本文整理汇总了Python中urllib2.parse_keqv_list方法的典型用法代码示例。如果您正苦于以下问题:Python urllib2.parse_keqv_list方法的具体用法?Python urllib2.parse_keqv_list怎么用?Python urllib2.parse_keqv_list使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类urllib2
的用法示例。
在下文中一共展示了urllib2.parse_keqv_list方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: compose
# 需要导入模块: import urllib2 [as 别名]
# 或者: from urllib2 import parse_keqv_list [as 别名]
def compose(self, digest=None, basic=None, username=None, password=None,
challenge=None, path=None, method=None):
assert username and password
if basic or not challenge:
assert not digest
userpass = "%s:%s" % (username.strip(), password.strip())
return "Basic %s" % userpass.encode('base64').strip()
assert challenge and not basic
path = path or "/"
(_, realm) = challenge.split('realm="')
(realm, _) = realm.split('"', 1)
auth = urllib2.AbstractDigestAuthHandler()
auth.add_password(realm, path, username, password)
(token, challenge) = challenge.split(' ', 1)
chal = urllib2.parse_keqv_list(urllib2.parse_http_list(challenge))
class FakeRequest(object):
def get_full_url(self):
return path
def has_data(self):
return False
def get_method(self):
return method or "GET"
get_selector = get_full_url
retval = "Digest %s" % auth.get_authorization(FakeRequest(), chal)
return (retval,)
示例2: registry_get
# 需要导入模块: import urllib2 [as 别名]
# 或者: from urllib2 import parse_keqv_list [as 别名]
def registry_get(self, api):
url = "https://%s/v2/%s" % (self.registry, api)
response = get(url, auth=(self.user, self.password),
headers={"Accept": 'application/vnd.docker.distribution.manifest.v2+json'},
verify=self.verify)
if response.status_code == 401:
challenge = response.headers['Www-Authenticate']
if challenge.startswith("Bearer "):
challenge = challenge[7:]
opts = urllib2.parse_keqv_list(urllib2.parse_http_list(challenge))
authresp = get("{realm}?service={service}&scope={scope}".format(**opts), auth=(self.user, self.password),
verify=self.verify)
if authresp.ok:
token = authresp.json()['token']
response = get(url, headers={'Authorization': 'Bearer %s' % token},
verify=self.verify)
else:
raise TaskError("problem authenticating with docker registry: [%s] %s" % (authresp.status_code,
authresp.content))
return response
示例3: parse_www_authenticate_header
# 需要导入模块: import urllib2 [as 别名]
# 或者: from urllib2 import parse_keqv_list [as 别名]
def parse_www_authenticate_header(header):
"""
Convert a WWW-Authentication header into a dict that can be used
in a JSON response.
"""
items = parse_http_list(header)
return parse_keqv_list(items)
示例4: _parse
# 需要导入模块: import urllib2 [as 别名]
# 或者: from urllib2 import parse_keqv_list [as 别名]
def _parse(self, authorization):
try:
scheme, rest = authorization.split(None, 1)
except ValueError:
# Probably "negotiate", which we don't support
scheme = authorization
rest = ""
args = urllib2.parse_keqv_list(urllib2.parse_http_list(rest))
challengeType = {
'basic': BasicChallenge,
'digest': DigestChallenge,
}.get(scheme.lower())
if challengeType is None:
return "", None
return scheme.lower(), challengeType(**args)
示例5: parse_keqv_list
# 需要导入模块: import urllib2 [as 别名]
# 或者: from urllib2 import parse_keqv_list [as 别名]
def parse_keqv_list(l):
"""A unicode-safe version of urllib2.parse_keqv_list"""
# With Python 2.6, parse_http_list handles unicode fine
return urllib2.parse_keqv_list(l)
示例6: parse_authorization_header
# 需要导入模块: import urllib2 [as 别名]
# 或者: from urllib2 import parse_keqv_list [as 别名]
def parse_authorization_header(authorization_header):
"""Parse an OAuth authorization header into a list of 2-tuples"""
auth_scheme = 'OAuth '.lower()
if authorization_header[:len(auth_scheme)].lower().startswith(auth_scheme):
items = parse_http_list(authorization_header[len(auth_scheme):])
try:
return list(parse_keqv_list(items).items())
except (IndexError, ValueError):
pass
raise ValueError('Malformed authorization header')