def _validate_namespaces(namespaces):
    """Validate wildcards and renaming in namespaces.

    Target namespaces should have the same number of wildcards as the source.
    No target namespaces overlap exactly with each other. Logs a warning
    when wildcard namespaces have a chance of overlapping.
    """
    for source, namespace in namespaces.items():
        target = namespace.dest_name
        _validate_namespace(source)
        _validate_namespace(target)
        if source.count("*") > 1 or target.count("*") > 1:
            raise errors.InvalidConfiguration(
                "The namespace mapping from '%s' to '%s' cannot contain more "
                "than one '*' character." % (source, target)
            )
        if source.count("*") != target.count("*"):
            raise errors.InvalidConfiguration(
                "The namespace mapping from '%s' to '%s' must contain the "
                "same number of '*' characters." % (source, target)
            )
        if "*" not in source:
            continue
        # Make sure that wildcards are not moved from database name to
        # collection name or vice versa, eg "db*.foo" => "db.foo_*"
        if (
            wildcard_in_db(source)
            and not wildcard_in_db(target)
            or (not wildcard_in_db(source) and wildcard_in_db(target))
        ):
            raise errors.InvalidConfiguration(
                "The namespace mapping from '%s' to '%s' is invalid. A '*' "
                "that appears in the source database name must also appear"
                "in the target database name. A '*' that appears in the "
                "source collection name must also appear in the target "
                "collection name" % (source, target)
            )

    for source1, source2 in combinations(namespaces.keys(), 2):
        if wildcards_overlap(source1, source2):
            LOG.warning(
                'Namespaces "%s" and "%s" may match the ' "same source namespace.",
                source1,
                source2,
            )
        target1 = namespaces[source1].dest_name
        target2 = namespaces[source2].dest_name
        if target1 == target2:
            raise errors.InvalidConfiguration(
                "Multiple namespaces cannot be combined into one target "
                "namespace. Trying to map '%s' to '%s' but '%s' already "
                "corresponds to '%s' in the target system."
                % (source2, target2, source1, target1)
            )
        if wildcards_overlap(target1, target2):
            LOG.warning(
                "Multiple namespaces cannot be combined into one target "
                "namespace. Mapping from '%s' to '%s' might overlap "
                "with mapping from '%s' to '%s'." % (source2, target2, source1, target1)
            )
def _validate_namespaces ( namespaces ) : for source , namespace in namespaces . items ( ) : target = namespace . dest_name _validate_namespace ( source ) _validate_namespace ( target ) if source . count ( "*" ) > 1 or target . count ( "*" ) > 1 : raise errors . InvalidConfiguration ( "The namespace mapping from '%s' to '%s' cannot contain more " "than one '*' character." % ( source , target ) ) if source . count ( "*" ) != target . count ( "*" ) : raise errors . InvalidConfiguration ( "The namespace mapping from '%s' to '%s' must contain the " "same number of '*' characters." % ( source , target ) ) if "*" not in source : continue if ( wildcard_in_db ( source ) and not wildcard_in_db ( target ) or ( not wildcard_in_db ( source ) and wildcard_in_db ( target ) ) ) : raise errors . InvalidConfiguration ( "The namespace mapping from '%s' to '%s' is invalid. A '*' " "that appears in the source database name must also appear" "in the target database name. A '*' that appears in the " "source collection name must also appear in the target " "collection name" % ( source , target ) ) for source1 , source2 in combinations ( namespaces . keys ( ) , 2 ) : if wildcards_overlap ( source1 , source2 ) : LOG . warning ( 'Namespaces "%s" and "%s" may match the ' "same source namespace." , source1 , source2 , ) target1 = namespaces [ source1 ] . dest_name target2 = namespaces [ source2 ] . dest_name if target1 == target2 : raise errors . InvalidConfiguration ( "Multiple namespaces cannot be combined into one target " "namespace. Trying to map '%s' to '%s' but '%s' already " "corresponds to '%s' in the target system." % ( source2 , target2 , source1 , target1 ) ) if wildcards_overlap ( target1 , target2 ) : LOG . warning ( "Multiple namespaces cannot be combined into one target " "namespace. Mapping from '%s' to '%s' might overlap " "with mapping from '%s' to '%s'." % ( source2 , target2 , source1 , target1 ) )
Validate wildcards and renaming in namespaces.

    Target namespaces should have the same number of wildcards as the source.
    No target namespaces overlap exactly with each other. Logs a warning
    when wildcard namespaces have a chance of overlapping.