How to use the rfc3986.URIReference function in rfc3986

To help you get started, we’ve selected a few rfc3986 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github openstack / nova / nova / api / validator.py View on Github external
def validate_url_path(val):
    """True if val is matched by the path component grammar in rfc3986."""

    if not validate_str()(val):
        return False

    uri = rfc3986.URIReference(None, None, val, None, None)

    return uri.path_is_valid() and val.startswith('/')
github rsrdesarrollo / sarna / sarna / model / finding.py View on Github external
def update_affected_resources(self, resources: Collection[AnyStr]):
        resource_uris = []
        for resource in resources:
            resource = resource.strip()
            if not resource:
                continue  # Skip empty lines
            resource_uri = URIReference.from_string(resource)
            if resource_uri.is_valid(require_scheme=True):
                _resource_ok = resource_uri.scheme.lower() in {'http', 'https'} and resource_uri.authority is not None
                _resource_ok = _resource_ok or (resource_uri.scheme == 'urn' and resource_uri.path is not None)
                if _resource_ok:
                    resource_uris.append(resource_uri)
                    continue

            raise ValueError('Invalid formatted URI: "{}"'.format(resource.strip()))

        affected_resources_to_add = set()

        for resource in resource_uris:
            if resource.authority is not None:
                # URL
                active_name = "{}://{}".format(resource.scheme, resource.authority)
                resource_route = resource.path
github python-hyper / hyper / hyper / common / util.py View on Github external
def to_host_port_tuple(host_port_str, default_port=80):
    """
    Converts the given string containing a host and possibly a port
    to a tuple.
    """
    uri = URIReference(
        scheme=None,
        authority=host_port_str,
        path=None,
        query=None,
        fragment=None
    )

    host = uri.host.strip('[]')
    if not uri.port:
        port = default_port
    else:
        port = int(uri.port)

    return (host, port)
github opensvc / opensvc / opensvc / foreign / hyper / common / util.py View on Github external
def to_host_port_tuple(host_port_str, default_port=80):
    """
    Converts the given string containing a host and possibly a port
    to a tuple.
    """
    uri = URIReference(
        scheme=None,
        authority=host_port_str,
        path=None,
        query=None,
        fragment=None
    )

    host = uri.host.strip('[]')
    if not uri.port:
        port = default_port
    else:
        port = int(uri.port)

    return (host, port)