本文整理汇总了Python中requests.compat.urlparse方法的典型用法代码示例。如果您正苦于以下问题:Python compat.urlparse方法的具体用法?Python compat.urlparse怎么用?Python compat.urlparse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类requests.compat
的用法示例。
在下文中一共展示了compat.urlparse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_connection
# 需要导入模块: from requests import compat [as 别名]
# 或者: from requests.compat import urlparse [as 别名]
def get_connection(self, url, proxies=None):
proxies = proxies or {}
proxy = proxies.get(urlparse(url.lower()).scheme)
if proxy:
raise ValueError('%s does not support specifying proxies'
% self.__class__.__name__)
with self.pools.lock:
pool = self.pools.get(url)
if pool:
return pool
pool = UnixHTTPConnectionPool(url, self.timeout)
self.pools[url] = pool
return pool
示例2: get_string_to_sign
# 需要导入模块: from requests import compat [as 别名]
# 或者: from requests.compat import urlparse [as 别名]
def get_string_to_sign(self, request, headers, created_timestamp, expires_timestamp):
sts = []
for header in headers:
if header == "(request-target)":
path_url = requests.models.RequestEncodingMixin.path_url.fget(request)
sts.append("{}: {} {}".format(header, request.method.lower(), path_url))
elif header == "(created)":
sts.append("{}: {}".format(header, created_timestamp))
elif header == "(expires)":
assert (expires_timestamp is not None), \
'You should provide the "expires_in" argument when using the (expires) header'
sts.append("{}: {}".format(header, int(expires_timestamp)))
else:
if header.lower() == "host":
url = urlparse(request.url)
value = request.headers.get("host", url.hostname)
if url.scheme == "http" and url.port not in [None, 80] or url.scheme == "https" \
and url.port not in [443, None]:
value = "{}:{}".format(value, url.port)
else:
value = request.headers[header]
sts.append("{k}: {v}".format(k=header.lower(), v=value))
return "\n".join(sts).encode()
示例3: test_principal_override
# 需要导入模块: from requests import compat [as 别名]
# 或者: from requests.compat import urlparse [as 别名]
def test_principal_override(self):
with patch.multiple("gssapi.Credentials", __new__=fake_creds), \
patch.multiple("gssapi.SecurityContext", __init__=fake_init,
step=fake_resp):
response = requests.Response()
response.url = "http://www.example.org/"
response.headers = {'www-authenticate': b64_negotiate_token}
host = urlparse(response.url).hostname
auth = requests_gssapi.HTTPKerberosAuth(principal="user@REALM")
auth.generate_request_header(response, host)
fake_creds.assert_called_with(gssapi.creds.Credentials,
usage="initiate",
name=gssapi_name("user@REALM"))
fake_init.assert_called_with(
name=gssapi_name("HTTP@www.example.org"),
usage="initiate", flags=gssflags,
creds=b"fake creds", mech=None)
示例4: test_explicit_creds
# 需要导入模块: from requests import compat [as 别名]
# 或者: from requests.compat import urlparse [as 别名]
def test_explicit_creds(self):
with patch.multiple("gssapi.Credentials", __new__=fake_creds), \
patch.multiple("gssapi.SecurityContext", __init__=fake_init,
step=fake_resp):
response = requests.Response()
response.url = "http://www.example.org/"
response.headers = {'www-authenticate': b64_negotiate_token}
host = urlparse(response.url).hostname
creds = gssapi.Credentials()
auth = requests_gssapi.HTTPSPNEGOAuth(creds=creds)
auth.generate_request_header(response, host)
fake_init.assert_called_with(
name=gssapi_name("HTTP@www.example.org"),
usage="initiate", flags=gssflags,
creds=b"fake creds", mech=None)
fake_resp.assert_called_with(b"token")
示例5: test_explicit_mech
# 需要导入模块: from requests import compat [as 别名]
# 或者: from requests.compat import urlparse [as 别名]
def test_explicit_mech(self):
with patch.multiple("gssapi.Credentials", __new__=fake_creds), \
patch.multiple("gssapi.SecurityContext", __init__=fake_init,
step=fake_resp):
response = requests.Response()
response.url = "http://www.example.org/"
response.headers = {'www-authenticate': b64_negotiate_token}
host = urlparse(response.url).hostname
fake_mech = b'fake mech'
auth = requests_gssapi.HTTPSPNEGOAuth(mech=fake_mech)
auth.generate_request_header(response, host)
fake_init.assert_called_with(
name=gssapi_name("HTTP@www.example.org"),
usage="initiate", flags=gssflags,
creds=None, mech=b'fake mech')
fake_resp.assert_called_with(b"token")
示例6: authenticate_user
# 需要导入模块: from requests import compat [as 别名]
# 或者: from requests.compat import urlparse [as 别名]
def authenticate_user(self, response, **kwargs):
"""Handles user authentication with GSSAPI"""
host = urlparse(response.url).hostname
try:
auth_header = self.generate_request_header(response, host)
except SPNEGOExchangeError:
# GSS Failure, return existing response
return response
log.debug("authenticate_user(): Authorization header: {0}".format(
auth_header))
response.request.headers['Authorization'] = auth_header
# Consume the content so we can reuse the connection for the next
# request.
response.content
response.raw.release_conn()
_r = response.connection.send(response.request, **kwargs)
_r.history.append(response)
log.debug("authenticate_user(): returning {0}".format(_r))
return _r
示例7: authenticate_server
# 需要导入模块: from requests import compat [as 别名]
# 或者: from requests.compat import urlparse [as 别名]
def authenticate_server(self, response):
"""
Uses GSSAPI to authenticate the server.
Returns True on success, False on failure.
"""
log.debug("authenticate_server(): Authenticate header: {0}".format(
_negotiate_value(response)))
host = urlparse(response.url).hostname
try:
# If the handshake isn't complete here, nothing we can do
self.context[host].step(_negotiate_value(response))
except gssapi.exceptions.GSSError as error:
log.exception("authenticate_server(): context stepping failed:")
log.exception(error.gen_message())
return False
log.debug("authenticate_server(): returning {0}".format(response))
return True
示例8: _api
# 需要导入模块: from requests import compat [as 别名]
# 或者: from requests.compat import urlparse [as 别名]
def _api(self, uri):
self._uri = urlparse(uri)
示例9: __init__
# 需要导入模块: from requests import compat [as 别名]
# 或者: from requests.compat import urlparse [as 别名]
def __init__(self, count, url, cls, session, params=None, etag=None,
headers=None):
GitHubCore.__init__(self, {}, session)
#: Original number of items requested
self.original = count
#: Number of items left in the iterator
self.count = count
#: URL the class used to make it's first GET
self.url = url
#: Last URL that was requested
self.last_url = None
self._api = self.url
#: Class for constructing an item to return
self.cls = cls
#: Parameters of the query string
self.params = params or {}
self._remove_none(self.params)
# We do not set this from the parameter sent. We want this to
# represent the ETag header returned by GitHub no matter what.
# If this is not None, then it won't be set from the response and
# that's not what we want.
#: The ETag Header value returned by GitHub
self.etag = None
#: Headers generated for the GET request
self.headers = headers or {}
#: The last response seen
self.last_response = None
#: Last status code received
self.last_status = 0
if etag:
self.headers.update({'If-None-Match': etag})
self.path = urlparse(self.url).path
示例10: get_connection
# 需要导入模块: from requests import compat [as 别名]
# 或者: from requests.compat import urlparse [as 别名]
def get_connection(self, url, proxies=None):
# proxies, silently ignored
path = unquote(urlparse(url).netloc)
return HTTPUnixConnectionPool(path)
示例11: connect
# 需要导入模块: from requests import compat [as 别名]
# 或者: from requests.compat import urlparse [as 别名]
def connect(self):
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
sock.settimeout(self.timeout)
socket_path = unquote(urlparse(self.unix_socket_url).netloc)
sock.connect(socket_path)
self.sock = sock
示例12: get_connection
# 需要导入模块: from requests import compat [as 别名]
# 或者: from requests.compat import urlparse [as 别名]
def get_connection(self, socket_path, proxies=None):
proxies = proxies or {}
proxy = proxies.get(urlparse(socket_path.lower()).scheme)
if proxy:
raise ValueError('%s does not support specifying proxies'
% self.__class__.__name__)
return UnixHTTPConnectionPool(socket_path, self.timeout)
示例13: cloudflare_is_bypassed
# 需要导入模块: from requests import compat [as 别名]
# 或者: from requests.compat import urlparse [as 别名]
def cloudflare_is_bypassed(self, url, resp=None):
cookie_domain = ".{}".format(urlparse(url).netloc)
return (
self.cookies.get("cf_clearance", None, domain=cookie_domain) or
(resp and resp.cookies.get("cf_clearance", None, domain=cookie_domain))
)
示例14: _get_domain
# 需要导入模块: from requests import compat [as 别名]
# 或者: from requests.compat import urlparse [as 别名]
def _get_domain(url):
parsed_url = urlparse(url)
scheme = parsed_url.scheme if parsed_url.scheme != '' else 'https'
return "%s://%s" % (scheme, parsed_url.netloc)
示例15: get
# 需要导入模块: from requests import compat [as 别名]
# 或者: from requests.compat import urlparse [as 别名]
def get(self, url, headers={}, allow_redirects=True):
parsed_url = urlparse(url)
response = self.head(_get_domain(url))
if response is None:
return None
(url, status_code) = response
if status_code != 200:
return None
resolved_url = urlparse(url)
url = urlunparse(
(
resolved_url.scheme,
resolved_url.netloc,
parsed_url.path,
parsed_url.params,
parsed_url.query,
parsed_url.fragment,
)
)
tools.log('GET: %s' % url, 'info')
request = lambda x: _get(self._cfscrape, url, headers, self._timeout, allow_redirects, x)
request.url = url
return self._request_core(request)