Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
result = utils.parse_url('testhostname')
assert result['schema'] == 'http'
assert result['host'] == 'testhostname'
assert result['port'] is None
assert result['user'] is None
assert result['password'] is None
assert result['fullpath'] is None
assert result['path'] is None
assert result['query'] is None
# The default_schema kicks in here
assert result['url'] == 'http://testhostname'
assert result['qsd'] == {}
assert result['qsd-'] == {}
result = utils.parse_url('example.com', default_schema='unknown')
assert result['schema'] == 'unknown'
assert result['host'] == 'example.com'
assert result['port'] is None
assert result['user'] is None
assert result['password'] is None
assert result['fullpath'] is None
assert result['path'] is None
assert result['query'] is None
# The default_schema kicks in here
assert result['url'] == 'unknown://example.com'
assert result['qsd'] == {}
assert result['qsd-'] == {}
# An empty string without a hostame is still valid if verify_host is set
result = utils.parse_url('', verify_host=False)
assert result['schema'] == 'http'
assert result['schema'] == 'http'
assert result['host'] == 'invalid'
assert result['port'] is None
assert result['user'] is None
assert result['password'] is None
assert result['fullpath'] == '/host'
assert result['path'] == '/'
assert result['query'] == 'host'
assert result['url'] == 'http://invalid/host'
assert result['qsd'] == {}
assert result['qsd-'] == {}
assert result['qsd+'] == {}
# just all out invalid
assert utils.parse_url('?') is None
assert utils.parse_url('/') is None
# A default port of zero is still considered valid, but
# is removed in the response.
result = utils.parse_url('http://nuxref.com:0')
assert result['schema'] == 'http'
assert result['host'] == 'nuxref.com'
assert result['port'] is None
assert result['user'] is None
assert result['password'] is None
assert result['fullpath'] is None
assert result['path'] is None
assert result['query'] is None
assert result['url'] == 'http://nuxref.com'
assert result['qsd'] == {}
assert result['qsd-'] == {}
assert result['qsd+'] == {}
result = utils.parse_url('http://nuxref.com:0')
assert result['schema'] == 'http'
assert result['host'] == 'nuxref.com'
assert result['port'] is None
assert result['user'] is None
assert result['password'] is None
assert result['fullpath'] is None
assert result['path'] is None
assert result['query'] is None
assert result['url'] == 'http://nuxref.com'
assert result['qsd'] == {}
assert result['qsd-'] == {}
assert result['qsd+'] == {}
# Test some illegal strings
result = utils.parse_url(object, verify_host=False)
assert result is None
result = utils.parse_url(None, verify_host=False)
assert result is None
# Just a schema; invalid host
result = utils.parse_url('test://')
assert result is None
# Do it again without host validation
result = utils.parse_url('test://', verify_host=False)
assert result['schema'] == 'test'
# It's worth noting that the hostname is an empty string and is NEVER set
# to None if it wasn't specified.
assert result['host'] == ''
assert result['port'] is None
assert result['user'] is None
)
assert result['schema'] == 'http'
assert result['host'] == 'nuxref.com'
assert result['port'] is None
assert result['user'] is None
assert result['password'] is None
assert result['fullpath'] is None
assert result['path'] is None
assert result['query'] is None
assert result['url'] == 'http://nuxref.com'
assert result['qsd'] == {}
assert result['qsd-'] == {}
assert result['qsd+'] == {}
# just host and path
result = utils.parse_url('invalid/host')
assert result['schema'] == 'http'
assert result['host'] == 'invalid'
assert result['port'] is None
assert result['user'] is None
assert result['password'] is None
assert result['fullpath'] == '/host'
assert result['path'] == '/'
assert result['query'] == 'host'
assert result['url'] == 'http://invalid/host'
assert result['qsd'] == {}
assert result['qsd-'] == {}
assert result['qsd+'] == {}
# just all out invalid
assert utils.parse_url('?') is None
assert utils.parse_url('/') is None
assert result['password'] is None
assert result['fullpath'] == '/host'
assert result['path'] == '/'
assert result['query'] == 'host'
assert result['url'] == 'http://invalid/host'
assert result['qsd'] == {}
assert result['qsd-'] == {}
assert result['qsd+'] == {}
# just all out invalid
assert utils.parse_url('?') is None
assert utils.parse_url('/') is None
# A default port of zero is still considered valid, but
# is removed in the response.
result = utils.parse_url('http://nuxref.com:0')
assert result['schema'] == 'http'
assert result['host'] == 'nuxref.com'
assert result['port'] is None
assert result['user'] is None
assert result['password'] is None
assert result['fullpath'] is None
assert result['path'] is None
assert result['query'] is None
assert result['url'] == 'http://nuxref.com'
assert result['qsd'] == {}
assert result['qsd-'] == {}
assert result['qsd+'] == {}
# Test some illegal strings
result = utils.parse_url(object, verify_host=False)
assert result is None
result = utils.parse_url('HTTPS://user@hostname/test.py')
assert result['schema'] == 'https'
assert result['host'] == 'hostname'
assert result['port'] is None
assert result['user'] == 'user'
assert result['password'] is None
assert result['fullpath'] == '/test.py'
assert result['path'] == '/'
assert result['query'] == 'test.py'
assert result['url'] == 'https://user@hostname/test.py'
assert result['qsd'] == {}
assert result['qsd-'] == {}
assert result['qsd+'] == {}
result = utils.parse_url(' HTTPS://///user@@@hostname///test.py ')
assert result['schema'] == 'https'
assert result['host'] == 'hostname'
assert result['port'] is None
assert result['user'] == 'user'
assert result['password'] is None
assert result['fullpath'] == '/test.py'
assert result['path'] == '/'
assert result['query'] == 'test.py'
assert result['url'] == 'https://user@hostname/test.py'
assert result['qsd'] == {}
assert result['qsd-'] == {}
assert result['qsd+'] == {}
result = utils.parse_url(
'HTTPS://user:password@otherHost/full///path/name/',
)
assert result['qsd'] == {}
assert result['qsd-'] == {}
assert result['qsd+'] == {}
# Test some illegal strings
result = utils.parse_url(object, verify_host=False)
assert result is None
result = utils.parse_url(None, verify_host=False)
assert result is None
# Just a schema; invalid host
result = utils.parse_url('test://')
assert result is None
# Do it again without host validation
result = utils.parse_url('test://', verify_host=False)
assert result['schema'] == 'test'
# It's worth noting that the hostname is an empty string and is NEVER set
# to None if it wasn't specified.
assert result['host'] == ''
assert result['port'] is None
assert result['user'] is None
assert result['password'] is None
assert result['fullpath'] is None
assert result['path'] is None
assert result['query'] is None
assert result['url'] == 'test://'
assert result['qsd'] == {}
assert result['qsd-'] == {}
assert result['qsd+'] == {}
result = utils.parse_url('testhostname')
assert result['fullpath'] == '/'
assert result['path'] == '/'
assert result['query'] is None
assert result['url'] == 'http://hostname/'
assert '+key' in result['qsd']
assert '-key' in result['qsd']
assert 'key' in result['qsd']
assert 'KeY' in result['qsd+']
assert result['qsd+']['KeY'] == 'ValueA'
assert 'kEy' in result['qsd-']
assert result['qsd-']['kEy'] == 'ValueB'
assert result['qsd']['key'] == 'Value C'
assert result['qsd']['+key'] == result['qsd+']['KeY']
assert result['qsd']['-key'] == result['qsd-']['kEy']
result = utils.parse_url('http://hostname////')
assert result['schema'] == 'http'
assert result['host'] == 'hostname'
assert result['port'] is None
assert result['user'] is None
assert result['password'] is None
assert result['fullpath'] == '/'
assert result['path'] == '/'
assert result['query'] is None
assert result['url'] == 'http://hostname/'
assert result['qsd'] == {}
assert result['qsd-'] == {}
assert result['qsd+'] == {}
result = utils.parse_url('http://hostname:40////')
assert result['schema'] == 'http'
assert result['host'] == 'hostname'
result = utils.parse_url('invalid/host')
assert result['schema'] == 'http'
assert result['host'] == 'invalid'
assert result['port'] is None
assert result['user'] is None
assert result['password'] is None
assert result['fullpath'] == '/host'
assert result['path'] == '/'
assert result['query'] == 'host'
assert result['url'] == 'http://invalid/host'
assert result['qsd'] == {}
assert result['qsd-'] == {}
assert result['qsd+'] == {}
# just all out invalid
assert utils.parse_url('?') is None
assert utils.parse_url('/') is None
# A default port of zero is still considered valid, but
# is removed in the response.
result = utils.parse_url('http://nuxref.com:0')
assert result['schema'] == 'http'
assert result['host'] == 'nuxref.com'
assert result['port'] is None
assert result['user'] is None
assert result['password'] is None
assert result['fullpath'] is None
assert result['path'] is None
assert result['query'] is None
assert result['url'] == 'http://nuxref.com'
assert result['qsd'] == {}
assert result['qsd-'] == {}
result = utils.parse_url('http://hostname////')
assert result['schema'] == 'http'
assert result['host'] == 'hostname'
assert result['port'] is None
assert result['user'] is None
assert result['password'] is None
assert result['fullpath'] == '/'
assert result['path'] == '/'
assert result['query'] is None
assert result['url'] == 'http://hostname/'
assert result['qsd'] == {}
assert result['qsd-'] == {}
assert result['qsd+'] == {}
result = utils.parse_url('http://hostname:40////')
assert result['schema'] == 'http'
assert result['host'] == 'hostname'
assert result['port'] == 40
assert result['user'] is None
assert result['password'] is None
assert result['fullpath'] == '/'
assert result['path'] == '/'
assert result['query'] is None
assert result['url'] == 'http://hostname:40/'
assert result['qsd'] == {}
assert result['qsd-'] == {}
assert result['qsd+'] == {}
result = utils.parse_url('HTTP://HoStNaMe:40/test.php')
assert result['schema'] == 'http'
assert result['host'] == 'HoStNaMe'