當前位置: 首頁>>代碼示例>>Python>>正文


Python urllib.splitvalue方法代碼示例

本文整理匯總了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')) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:11,代碼來源:test_urllib.py

示例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 
開發者ID:ZSAIm,項目名稱:iqiyi-parser,代碼行數:38,代碼來源:DLProcessor.py

示例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 
開發者ID:ZSAIm,項目名稱:iqiyi-parser,代碼行數:10,代碼來源:DLProcessor.py

示例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 
開發者ID:spikeekips,項目名稱:serf-python,代碼行數:47,代碼來源:connection.py


注:本文中的urllib.splitvalue方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。