本文整理汇总了Python中urllib3.util.url.parse_url函数的典型用法代码示例。如果您正苦于以下问题:Python parse_url函数的具体用法?Python parse_url怎么用?Python parse_url使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parse_url函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_parse_url_unicode_python_2
def test_parse_url_unicode_python_2(self):
url = parse_url(u"https://www.google.com/")
assert url == Url(u'https', host=u'www.google.com', path=u'/')
assert isinstance(url.scheme, six.text_type)
assert isinstance(url.host, six.text_type)
assert isinstance(url.path, six.text_type)
示例2: __init__
def __init__(self, proxy_url, username=None, password=None,
num_pools=10, headers=None, **connection_pool_kw):
parsed = parse_url(proxy_url)
if parsed.scheme == 'socks5':
socks_version = socks.PROXY_TYPE_SOCKS5
elif parsed.scheme == 'socks4':
socks_version = socks.PROXY_TYPE_SOCKS4
else:
raise ValueError(
"Unable to determine SOCKS version from %s" % proxy_url
)
self.proxy_url = proxy_url
socks_options = {
'socks_version': socks_version,
'proxy_host': parsed.host,
'proxy_port': parsed.port,
'username': username,
'password': password,
}
connection_pool_kw['_socks_options'] = socks_options
super(SOCKSProxyManager, self).__init__(
num_pools, headers, **connection_pool_kw
)
self.pool_classes_by_scheme = SOCKSProxyManager.pool_classes_by_scheme
示例3: test_parse_url
def test_parse_url(self):
url_host_map = {
"http://google.com/mail": Url("http", host="google.com", path="/mail"),
"http://google.com/mail/": Url("http", host="google.com", path="/mail/"),
"google.com/mail": Url(host="google.com", path="/mail"),
"http://google.com/": Url("http", host="google.com", path="/"),
"http://google.com": Url("http", host="google.com"),
"http://google.com?foo": Url("http", host="google.com", path="", query="foo"),
# Path/query/fragment
"": Url(),
"/": Url(path="/"),
"?": Url(path="", query=""),
"#": Url(path="", fragment=""),
"#?/!google.com/?foo#bar": Url(path="", fragment="?/!google.com/?foo#bar"),
"/foo": Url(path="/foo"),
"/foo?bar=baz": Url(path="/foo", query="bar=baz"),
"/foo?bar=baz#banana?apple/orange": Url(path="/foo", query="bar=baz", fragment="banana?apple/orange"),
# Port
"http://google.com/": Url("http", host="google.com", path="/"),
"http://google.com:80/": Url("http", host="google.com", port=80, path="/"),
"http://google.com:/": Url("http", host="google.com", path="/"),
"http://google.com:80": Url("http", host="google.com", port=80),
"http://google.com:": Url("http", host="google.com"),
# Auth
"http://foo:[email protected]/": Url("http", auth="foo:bar", host="localhost", path="/"),
"http://[email protected]/": Url("http", auth="foo", host="localhost", path="/"),
"http://foo:[email protected]@localhost/": Url("http", auth="foo:[email protected]", host="localhost", path="/"),
"http://@": Url("http", host=None, auth=""),
}
for url, expected_url in url_host_map.items():
returned_url = parse_url(url)
self.assertEqual(returned_url, expected_url)
示例4: test_parse_url
def test_parse_url(self):
url_host_map = {
'http://google.com/mail': Url('http', host='google.com', path='/mail'),
'http://google.com/mail/': Url('http', host='google.com', path='/mail/'),
'google.com/mail': Url(host='google.com', path='/mail'),
'http://google.com/': Url('http', host='google.com', path='/'),
'http://google.com': Url('http', host='google.com'),
'http://google.com?foo': Url('http', host='google.com', path='', query='foo'),
# Path/query/fragment
'': Url(),
'/': Url(path='/'),
'?': Url(path='', query=''),
'#': Url(path='', fragment=''),
'#?/!google.com/?foo#bar': Url(path='', fragment='?/!google.com/?foo#bar'),
'/foo': Url(path='/foo'),
'/foo?bar=baz': Url(path='/foo', query='bar=baz'),
'/foo?bar=baz#banana?apple/orange': Url(path='/foo', query='bar=baz', fragment='banana?apple/orange'),
# Port
'http://google.com/': Url('http', host='google.com', path='/'),
'http://google.com:80/': Url('http', host='google.com', port=80, path='/'),
'http://google.com:/': Url('http', host='google.com', path='/'),
'http://google.com:80': Url('http', host='google.com', port=80),
'http://google.com:': Url('http', host='google.com'),
# Auth
'http://foo:[email protected]/': Url('http', auth='foo:bar', host='localhost', path='/'),
'http://[email protected]/': Url('http', auth='foo', host='localhost', path='/'),
'http://foo:[email protected]@localhost/': Url('http', auth='foo:[email protected]', host='localhost', path='/'),
'http://@': Url('http', host=None, auth='')
}
for url, expected_url in url_host_map.items():
returned_url = parse_url(url)
self.assertEqual(returned_url, expected_url)
示例5: test_parse_url_bytes_to_str_python_2
def test_parse_url_bytes_to_str_python_2(self):
url = parse_url(b"https://www.google.com/")
assert url == Url('https', host='www.google.com', path='/')
assert isinstance(url.scheme, str)
assert isinstance(url.host, str)
assert isinstance(url.path, str)
示例6: test_netloc
def test_netloc(self):
url_netloc_map = {
"http://google.com/mail": "google.com",
"http://google.com:80/mail": "google.com:80",
"google.com/foobar": "google.com",
"google.com:12345": "google.com:12345",
}
for url, expected_netloc in url_netloc_map.items():
self.assertEqual(parse_url(url).netloc, expected_netloc)
示例7: test_parse_url_normalization
def test_parse_url_normalization(self):
"""Assert parse_url normalizes the scheme/host, and only the scheme/host"""
test_urls = [
('HTTP://GOOGLE.COM/MAIL/', 'http://google.com/MAIL/'),
('HTTP://JeremyCline:[email protected]:8080/', 'http://JeremyCline:[email protected]:8080/'),
('HTTPS://Example.Com/?Key=Value', 'https://example.com/?Key=Value'),
('Https://Example.Com/#Fragment', 'https://example.com/#Fragment'),
]
for url, expected_normalized_url in test_urls:
actual_normalized_url = parse_url(url).url
self.assertEqual(actual_normalized_url, expected_normalized_url)
示例8: test_request_uri
def test_request_uri(self):
url_host_map = {
"http://google.com/mail": "/mail",
"http://google.com/mail/": "/mail/",
"http://google.com/": "/",
"http://google.com": "/",
"": "/",
"/": "/",
"?": "/?",
"#": "/",
"/foo?bar=baz": "/foo?bar=baz",
}
for url, expected_request_uri in url_host_map.items():
returned_url = parse_url(url)
self.assertEqual(returned_url.request_uri, expected_request_uri)
示例9: test_request_uri
def test_request_uri(self):
url_host_map = {
'http://google.com/mail': '/mail',
'http://google.com/mail/': '/mail/',
'http://google.com/': '/',
'http://google.com': '/',
'': '/',
'/': '/',
'?': '/?',
'#': '/',
'/foo?bar=baz': '/foo?bar=baz',
}
for url, expected_request_uri in url_host_map.items():
returned_url = parse_url(url)
self.assertEqual(returned_url.request_uri, expected_request_uri)
示例10: validate_run_info
def validate_run_info(info: dict) -> bool:
passed = False
# ## Validate Binary Executable ## #
binary = Path(shutil.which(info["binary"]))
if binary.exists():
passed = True
else:
logger.error("binary", binary, "is not accessible from this process")
# ## Check the URL For Validity ## #
# ## By Checking It's Parts ## #
link = url.parse_url(runInfo["target"])
for x in [link.hostname, link.path, link.url]:
if x is not None:
passed = True
else:
passed = False
break # don't let other "True" values corrupt the state
return passed
示例11: test_parse_url
def test_parse_url(self):
for url, expected_Url in chain(self.parse_url_host_map,
self.non_round_tripping_parse_url_host_map.items()):
returned_Url = parse_url(url)
self.assertEqual(returned_Url, expected_Url)
示例12: test_url_vulnerabilities
def test_url_vulnerabilities(self, url, expected_url):
if expected_url is False:
with pytest.raises(LocationParseError):
parse_url(url)
else:
assert parse_url(url) == expected_url
示例13: test_netloc
def test_netloc(self, url, expected_netloc):
assert parse_url(url).netloc == expected_netloc
示例14: test_request_uri
def test_request_uri(self, url, expected_request_uri):
returned_url = parse_url(url)
assert returned_url.request_uri == expected_request_uri
示例15: test_parse_url_negative_port
def test_parse_url_negative_port(self):
with pytest.raises(LocationParseError):
parse_url("https://www.google.com:-80/")