Python urllib.splitvalue() Examples
The following are 6
code examples of urllib.splitvalue().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
urllib
, or try the search function
.
Example #1
Source File: test_urllib.py From ironpython2 with Apache License 2.0 | 5 votes |
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'))
Example #2
Source File: test_urllib.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
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'))
Example #3
Source File: DLProcessor.py From iqiyi-parser with MIT License | 5 votes |
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
Example #4
Source File: DLProcessor.py From iqiyi-parser with MIT License | 5 votes |
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
Example #5
Source File: test_urllib.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
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'))
Example #6
Source File: connection.py From serf-python with Mozilla Public License 2.0 | 4 votes |
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