本文整理汇总了Python中urllib.splitvalue方法的典型用法代码示例。如果您正苦于以下问题:Python urllib.splitvalue方法的具体用法?Python urllib.splitvalue怎么用?Python urllib.splitvalue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类urllib
的用法示例。
在下文中一共展示了urllib.splitvalue方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_splitvalue
# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import splitvalue [as 别名]
def test_splitvalue(self):
# Normal cases are exercised by other tests; test pathological cases
# with no key/value pairs. (testcase ensuring coverage)
splitvalue = urllib.splitvalue
self.assertEqual(splitvalue('foo=bar'), ('foo', 'bar'))
self.assertEqual(splitvalue('foo='), ('foo', ''))
self.assertEqual(splitvalue('=bar'), ('', 'bar'))
self.assertEqual(splitvalue('foobar'), ('foobar', None))
self.assertEqual(splitvalue('foo=bar=baz'), ('foo', 'bar=baz'))
示例2: makeReqHeaders
# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import splitvalue [as 别名]
def makeReqHeaders(self):
range_format = self.url.range_format
Range = (self.progress.begin + self.progress.go_inc, self.progress.end)
req_path = self.target.path
req_headers = dict(self.url.headers.items())
if range_format[0] == '&':
path, query = splitquery(self.target.path)
query_dict = extract_query(query)
range_format = range_format % Range
for i in range_format[1:].split('&'):
param_key, param_value = splitvalue(i)
query_dict[param_key] = param_value
new_query = urlencode(query_dict)
req_path = '%s?%s' % (path, new_query)
else:
range_field = range_format % Range
key_value = [i.strip() for i in range_field.split(':')]
key = key_value[0]
value = key_value[1]
add_headers = {
key: value,
'Accept-Ranges': 'bytes'
}
req_headers.update(add_headers)
return req_path, req_headers
示例3: extract_query
# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import splitvalue [as 别名]
def extract_query(query_str):
querys = {}
if query_str:
for i in query_str.split('&'):
key_value = splitvalue(i)
querys[key_value[0]] = key_value[1]
return querys
示例4: _parse_host
# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import splitvalue [as 别名]
def _parse_host (h, ) :
if not h.startswith('serf://') :
h = 'serf://%s' % h
_parsed = list(urlparse.urlparse(h, ), )
if _parsed[0] not in ('serf', ) :
raise _exceptions.InvalidHostURL('invalid host url, `%s`.' % h, )
# the `urlparse` module in `travis-cis` does not understand the
# non-standard scheme like `serf'.
_parsed[0] = 'http'
if not _parsed[2].startswith('/') :
_parsed[2] = '/' + _parsed[2]
_parsed = urlparse.urlparse(urlparse.urlunparse(_parsed, ), )
_host = map(
lambda x : None if x in ('', -1, ) else x,
urllib.splitnport(_parsed.netloc, defport=7373, ),
)
if not _host[0] and not _host[1] :
raise _exceptions.InvalidHostURL('invalid host url, `%s`.' % h, )
if not _host[0] :
_host[0] = constant.DEFAULT_HOST
if not _host[1] :
_host[1] = constant.DEFAULT_PORT
_queries = dict()
if _parsed.query :
_queries = dict(map(
urllib.splitvalue,
filter(string.strip, _parsed.query.split('&'), ),
), )
if set(_queries.keys()) != AVAILABLE_HOST_URI_QUERY_KEYS :
raise _exceptions.InvalidHostURL(
'unknown key found, %s' % list(
set(_queries.keys() - AVAILABLE_HOST_URI_QUERY_KEYS), ),
)
_host.append(_queries, )
return _host