def in_namespace(uri, base_uri):
    """
    Check if given URI is in the "namespace" of the given base URI

    """
    if any((
        base_uri.endswith("#"),
        base_uri.endswith("/")
    )):
        # We chop off last character of base uri as that typically can include a
        # backslash (/) or a fragment (#) character.
        base_uri = base_uri[:-1]
    return uri.startswith(base_uri)