Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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('/')
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
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)
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)