Ejemplo n.º 1
0
def assert_valid_ns(db_ns):
    """Raise UnknownNamespace error if the given namespace is unknown.

    Parameters
    ----------
    db_ns : str
        The namespace.
    """
    identifiers_ns = identifiers_mappings.get(db_ns, db_ns.lower())
    if identifiers_ns in identifiers_registry or db_ns in non_registry \
            or db_ns in non_grounding:
        return
    raise UnknownNamespace(db_ns)
Ejemplo n.º 2
0
def assert_valid_id(db_ns, db_id):
    """Raise InvalidIdentifier error if the ID is invalid in the given
    namespace.

    Parameters
    ----------
    db_ns : str
        The namespace.
    db_id : str
        The ID.
    """
    identifiers_ns = identifiers_mappings.get(db_ns, db_ns.lower())
    if identifiers_ns in identifiers_registry:
        if re.match(identifiers_registry[identifiers_ns]['pattern'], db_id):
            return
        else:
            raise InvalidIdentifier(f'{db_ns}:{db_id}')
    elif db_ns in non_registry or db_ns in non_grounding:
        return
    else:
        raise InvalidIdentifier(f'{db_ns}:{db_id}')
Ejemplo n.º 3
0
def assert_valid_id(db_ns, db_id):
    """Raise InvalidIdentifier error if the ID is invalid in the given
    namespace.

    Parameters
    ----------
    db_ns : str
        The namespace.
    db_id : str
        The ID.
    """
    if db_id is None:
        raise MissingIdentifier(db_ns, None)
    identifiers_ns = identifiers_mappings.get(db_ns, db_ns.lower())
    if identifiers_ns in identifiers_registry:
        pattern = identifiers_registry[identifiers_ns]['pattern_compiled']
        if pattern.match(db_id):
            return
        else:
            raise InvalidIdentifier(db_ns, db_id, pattern)
    elif db_ns in non_registry or db_ns in non_grounding:
        return
    else:
        raise UnknownIdentifier(db_ns, db_id)