/usr/lib/python3/dist-packages/path_and_address/parsing.py is in python3-path-and-address 2.0.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | from .validation import valid_hostname, valid_port
def resolve(path_or_address=None, address=None, *ignored):
"""
Returns (path, address) based on consecutive optional arguments,
[path] [address].
"""
if path_or_address is None or address is not None:
return path_or_address, address
path = None
if split_address(path_or_address)[1] is not None:
address = path_or_address
else:
path = path_or_address
return path, address
def split_address(address):
"""
Returns (host, port) with an integer port from the specified address
string. (None, None) is returned if the address is invalid.
"""
invalid = None, None
if not address and address != 0:
return invalid
components = str(address).split(':')
if len(components) > 2:
return invalid
if components[0] and not valid_hostname(components[0]):
return invalid
if len(components) == 2 and not valid_port(components[1]):
return invalid
if len(components) == 1:
components.insert(0 if valid_port(components[0]) else 1, None)
host, port = components
port = int(port) if port else None
return host, port
|