Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if ':' in auth:
user, password = auth.split(':', 1)
else:
user = auth
# Parsing domain & port
netloc = netloc.split(':', 1)
if len(netloc) == 2:
port = netloc[1]
lru.append('t:' + port)
# Need to process TLD?
if tld_aware:
domain_parts, non_zero_i, _ = process_url(
url=parsed_url,
fail_silently=True,
fix_protocol=False,
search_public=True,
search_private=True
)
tld = '.'.join(domain_parts[non_zero_i:])
lru.append('h:' + tld)
for element in reversed(domain_parts[0:non_zero_i]):
lru.append('h:' + element)
else:
for element in reversed(netloc[0].split('.')):
lru.append('h:' + element)
# Path
hostname = parsed_url.hostname or ''
lru = []
if scheme:
lru.append('s:' + scheme)
# Handling port
if parsed_url.port is not None:
lru.append('t:' + str(parsed_url.port))
# Need to process TLD?
should_process_normally = not tld_aware
if tld_aware:
domain_parts, non_zero_i, _ = process_url(
url=parsed_url,
fail_silently=True,
fix_protocol=False,
search_public=True,
search_private=True
)
if domain_parts is None:
should_process_normally = True
else:
tld = '.'.join(domain_parts[non_zero_i:])
lru.append('h:' + tld)
for element in reversed(domain_parts[0:non_zero_i]):
lru.append('h:' + element)
if allow_spaces_in_path:
pattern = RELAXED_URL_WITH_PROTOCOL_RE
else:
pattern = URL_WITH_PROTOCOL_RE
else:
if allow_spaces_in_path:
pattern = RELAXED_URL
else:
pattern = URL_RE
if not pattern.match(string):
return False
if tld_aware:
domain_parts, non_zero_i, parsed_url = process_url(
url=string,
fail_silently=True,
fix_protocol=not require_protocol,
search_public=True,
search_private=True
)
if domain_parts is None:
if not parsed_url:
return False
return bool(SPECIAL_HOSTS_RE.match(parsed_url.hostname))
return True