• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python urllib2.parse_http_list函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中urllib2.parse_http_list函数的典型用法代码示例。如果您正苦于以下问题:Python parse_http_list函数的具体用法?Python parse_http_list怎么用?Python parse_http_list使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了parse_http_list函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: http_response

    def http_response(self, req, resp):
        # code for after-fetch, to know whether to save to hard-drive (if stiking to http headers' will)

        if resp.code == 304:
            return resp

        if ('cache-control' in resp.headers or 'pragma' in resp.headers) and self.force_min is None:
            cache_control = parse_http_list(resp.headers.get('cache-control', ()))
            cache_control += parse_http_list(resp.headers.get('pragma', ()))

            cc_list = [x for x in cache_control if '=' not in x]

            if 'no-cache' in cc_list or 'no-store' in cc_list or ('private' in cc_list and not self.private):
                # kindly follow web servers indications
                return resp

        if resp.headers.get('Morss') == 'from_cache':
            # it comes from cache, so no need to save it again
            return resp

        # save to disk
        data = resp.read()
        self._save(req.get_full_url(), resp.code, resp.msg, resp.headers, data, time.time())

        fp = BytesIO(data)
        old_resp = resp
        resp = addinfourl(fp, old_resp.headers, old_resp.url, old_resp.code)
        resp.msg = old_resp.msg

        return resp
开发者ID:brainyfarm,项目名称:morss,代码行数:30,代码来源:crawler.py


示例2: test_parse_http_list

 def test_parse_http_list(self):
     tests = [('a,b,c', ['a', 'b', 'c']),
              ('path"o,l"og"i"cal, example', ['path"o,l"og"i"cal', 'example']),
              ('a, b, "c", "d", "e,f", g, h', ['a', 'b', '"c"', '"d"', '"e,f"', 'g', 'h']),
              ('a="b\\"c", d="e\\,f", g="h\\\\i"', ['a="b"c"', 'd="e,f"', 'g="h\\i"'])]
     for string, list in tests:
         self.assertEquals(urllib2.parse_http_list(string), list)
开发者ID:005,项目名称:gevent,代码行数:7,代码来源:test_urllib2.py


示例3: check_auth

 def check_auth(self, header, method='GET'):
     "Check a response to our auth challenge"
     from urllib2 import parse_http_list
     H, KD = self.get_algorithm_impls()
     resp = parse_keqv_list(parse_http_list(header))
     algo = resp.get('algorithm', 'MD5').upper()
     if algo != self.algorithm:
         return False, "unknown algo %s"%algo
     user = resp['username']
     realm = resp['realm']
     nonce = resp['nonce']
     # XXX Check the nonce is something we've issued
     HA1 = self._user_hashes.get((user,realm))
     if not HA1:
         return False, "unknown user/realm %s/%s"%(user, realm)
     qop = resp.get('qop')
     if qop != 'auth':
         return False, "unknown qop %r"%(qop)
     cnonce, ncvalue = resp.get('cnonce'), resp.get('nc')
     if not cnonce or not ncvalue:
         return False, "failed to provide cnonce"
     # Check the URI is correct!
     A2 = '%s:%s'%(method, resp['uri'])
     noncebit = "%s:%s:%s:%s:%s" % (nonce,ncvalue,cnonce,qop,H(A2))
     respdig = KD(HA1, noncebit)
     if respdig != resp['response']:
         return False, "response incorrect"
     print "all ok"
     return True, "OK"
开发者ID:habnabit,项目名称:divmod-sine,代码行数:29,代码来源:digestauth.py


示例4: parse_oauth_header

def parse_oauth_header(header):
    type, rest = header.split(" ", 1)

    if type != "OAuth":
        raise ValueError("Authorization is not of OAuth type")

    return urllib2.parse_keqv_list(urllib2.parse_http_list(rest))
开发者ID:cgorbit,项目名称:rem,代码行数:7,代码来源:oauth.py


示例5: get

 def get(self):
     assert self.current_user
     origin = self.get_argument("origin", None)
     session = model.Session()
     actions_param = self.get_argument("actions", None)
     where = [model.UserConsent.user_id==self.current_user]
     if origin is not None:
         where.append(model.UserConsent.origin==origin)
     if actions_param is not None:
         actions = actions_param.split(",")
         where.append(model.UserConsent.operation.in_(actions))
     existing = session.query(model.UserConsent).filter(
                     and_(*where)).all()
     result = {}
     for e in existing:
         origin_result = result.setdefault(e.origin, {})
         origin_result[e.operation] = e.allowed
     # work out if we are trying to serve up the html ui or just the data.
     accepts = urllib2.parse_http_list(self.request.headers.get("Accept", ""))
     try:
         json_ndx = accepts.index("application/json")
     except ValueError:
         json_ndx = 10000
     try:
         html_ndx = accepts.index("text/html")
     except ValueError:
         html_ndx = 10000
     if html_ndx < json_ndx:
         self.render("consent.html", consent_items=result)
     else:
         self.write(result)
开发者ID:mozilla,项目名称:experimental-split-server,代码行数:31,代码来源:consent.py


示例6: parse_options_header

def parse_options_header(value):
    result = []
    for item in urllib2.parse_http_list(value):
        if item[:1] == item[-1:] == '"':
            item = unquote_header_value(item[1:-1])
        result.append(item)
    return result
开发者ID:SuperDaffy,项目名称:glance,代码行数:7,代码来源:urlmap.py


示例7: parse_authorization_header

def parse_authorization_header(header):
    """ Parse requests authorization header into list.
    Raise ValueError if some problem occurs. """
    # digest is marked as part of header and causes problem
    # parsing, so remove its

    if not header.startswith("Digest "):
        raise ValueError("Header do not start with Digest")
    header = header[len("Digest ") :]

    # Convert the auth params to a dict
    items = urllib2.parse_http_list(header)
    params = urllib2.parse_keqv_list(items)

    required = ["username", "realm", "nonce", "uri", "response"]

    for field in required:
        if not params.has_key(field):
            raise ValueError("Required field %s not found" % field)

    # check for qop companions (sect. 3.2.2)
    if params.has_key("qop") and not params.has_key("cnonce") and params.has_key("cn"):
        raise ValueError("qop sent without cnonce and cn")

    return params
开发者ID:nAk123,项目名称:fluffyhome,代码行数:25,代码来源:digest.py


示例8: parse_authorization_header

def parse_authorization_header(value):
    """Parse the Authenticate header

    Returns nothing on failure, opts hash on success with type='basic' or 'digest'
    and other params.

    <http://nullege.com/codes/search/werkzeug.http.parse_authorization_header>
    <http://stackoverflow.com/questions/1349367/parse-an-http-request-authorization-header-with-python>
    <http://bugs.python.org/file34041/0001-Add-an-authorization-header-to-the-initial-request.patch>
    """
    try:
        (auth_type, auth_info) = value.split(' ', 1)
        auth_type = auth_type.lower()
    except ValueError as e:
        return
    if (auth_type == 'basic'):
        try:
            (username, password) = base64.b64decode(auth_info).split(':', 1)
        except Exception as e:
            return
        return {'type':'basic', 'username': username, 'password': password}
    elif (auth_type == 'digest'):
        auth_map = urllib2.parse_keqv_list(urllib2.parse_http_list(auth_info))
        print auth_map
        for key in 'username', 'realm', 'nonce', 'uri', 'response':
            if not key in auth_map:
                return
            if 'qop' in auth_map:
                if not auth_map.get('nc') or not auth_map.get('cnonce'):
                    return
        auth_map['type']='digest'
        return auth_map
    else:
        # unknown auth type
        return
开发者ID:edsu,项目名称:iiif,代码行数:35,代码来源:iiif_testserver.py


示例9: compose

 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,)
开发者ID:CGastrell,项目名称:argenmap-cachebuilder,代码行数:25,代码来源:httpheaders.py


示例10: _parseHeader

 def _parseHeader(self, authheader, request):
     n = 7 # n = len("Digest ")
     try:
         authheader = authheader[n:].strip()
         items = urllib2.parse_http_list(authheader)
         request.env['__DIGEST_PARAMS__'] = urllib2.parse_keqv_list(items)
     except Exception, e:
         request.env['__DIGEST_PARAMS__'] = {}
开发者ID:slaff,项目名称:attachix,代码行数:8,代码来源:authentication.py


示例11: test_parse_http_list

 def test_parse_http_list(self):
     tests = [
         ("a,b,c", ["a", "b", "c"]),
         ('path"o,l"og"i"cal, example', ['path"o,l"og"i"cal', "example"]),
         ('a, b, "c", "d", "e,f", g, h', ["a", "b", '"c"', '"d"', '"e,f"', "g", "h"]),
         ('a="b\\"c", d="e\\,f", g="h\\\\i"', ['a="b"c"', 'd="e,f"', 'g="h\\i"']),
     ]
     for string, list in tests:
         self.assertEqual(urllib2.parse_http_list(string), list)
开发者ID:int3,项目名称:jython,代码行数:9,代码来源:test_urllib2.py


示例12: parse_auth_header

 def parse_auth_header(self, authorization):
     values = {}
     for value in urllib2.parse_http_list(authorization):
         n, v = value.split("=", 1)
         if v[0] == '"' and v[-1] == '"':
             values[n] = v[1:-1]
         else:
             values[n] = v
     return values
开发者ID:wiraqutra,项目名称:photrackjp,代码行数:9,代码来源:auth.py


示例13: parse_list_header

def parse_list_header(value):
    """
    Parse lists as described by RFC 2068 Section 2.
    """
    result = []
    for item in urllib2.parse_http_list(value):
        if item[:1] == item[-1:] == '"':
            item = unquote_header_value(item[1:-1])
        result.append(item)
    return result
开发者ID:liuliuxiaoge,项目名称:XDRS,代码行数:10,代码来源:urlmap.py


示例14: parse_authorization_header

def parse_authorization_header(authorization_header):
    """Parse an OAuth authorization header into a list of 2-tuples"""
    auth_scheme = 'OAuth '
    if authorization_header.startswith(auth_scheme):
        authorization_header = authorization_header.replace(auth_scheme, '', 1)
    items = urllib2.parse_http_list(authorization_header)
    try:
        return urllib2.parse_keqv_list(items).items()
    except ValueError:
        raise ValueError('Malformed authorization header')
开发者ID:ghickman,项目名称:oauthlib,代码行数:10,代码来源:utils.py


示例15: _parse

 def _parse(self, authorization):
     scheme, rest = authorization.split(None, 1)
     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)
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:10,代码来源:httpauth.py


示例16: retry_http_digest_auth

    def retry_http_digest_auth(self, req, auth):
        token, challenge = auth.split(' ', 1)
        chal = urllib2.parse_keqv_list(urllib2.parse_http_list(challenge))
        auth = self.get_authorization(req, chal)
        if auth:

            auth_val = 'X-Digest %s' % auth
            if req.headers.get(self.auth_header, None) == auth_val:
                return None
            req.add_unredirected_header(self.auth_header, auth_val)
            resp = self.parent.open(req, timeout=req.timeout)
            return resp
开发者ID:ivanfmartinez,项目名称:energy-monitor,代码行数:12,代码来源:abb_vsn300.py


示例17: retry_http_digest_auth

    def retry_http_digest_auth(self, req, resp, host, auth):
        _token, challenge = auth.split(" ", 1)
        chal = urllib2.parse_keqv_list(urllib2.parse_http_list(challenge))
        auth = self.get_authorization(req, chal)
        if auth:
            auth_val = "Digest %s" % auth
            if req.headers.get(self.auth_header, None) == auth_val:
                return None
            req.add_unredirected_header(self.auth_header, auth_val)
            return "request", req

        return None
开发者ID:niterain,项目名称:digsby,代码行数:12,代码来源:handlers.py


示例18: retry_http_digest_auth

 def retry_http_digest_auth(self, req, auth):
     token, challenge = auth.split(' ', 1)
     chal = parse_keqv_list(parse_http_list(challenge))
     auth = self.get_authorization(req, chal)
     if auth:
         auth_val = 'Digest %s' % auth
         if req.headers.get(self.auth_header, None) == auth_val:
             return None
         newreq = copy.copy(req)
         newreq.add_unredirected_header(self.auth_header, auth_val)
         newreq.visit = False
         return self.parent.open(newreq)
开发者ID:codesprinters,项目名称:twillmanager,代码行数:12,代码来源:_auth.py


示例19: authorized

    def authorized(self):
        tcs = self.server.test_case_server

        auth_header = self.headers.get(tcs.auth_header_recv, None)
        if auth_header is None:
            return False
        scheme, auth = auth_header.split(None, 1)
        if scheme.lower() == tcs.auth_scheme:
            auth_dict = urllib2.parse_keqv_list(urllib2.parse_http_list(auth))

            return tcs.digest_authorized(auth_dict, self.command)

        return False
开发者ID:Distrotech,项目名称:bzr,代码行数:13,代码来源:http_utils.py


示例20: parse_dict_header

def parse_dict_header(value):
    """Parse key=value pairs from value list
    """
    result = {}
    for item in parse_http_list(value):
        if "=" not in item:
            result[item] = None
            continue
        name, value = item.split('=', 1)
        if value[:1] == value[-1:] == '"':
            value = urllib.unquote(value[1:-1]) # strip " and unquote
        result[name] = value
    return result
开发者ID:nwlunatic,项目名称:human_curl,代码行数:13,代码来源:utils.py



注:本文中的urllib2.parse_http_list函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python urllib2.parse_keqv_list函数代码示例发布时间:2022-05-27
下一篇:
Python urllib2.build_opener函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap