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

Python urllib2.parse_keqv_list函数代码示例

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

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



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

示例1: 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


示例2: 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


示例3: 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


示例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: youtube_video

def youtube_video(url):
    try:
        conn = urllib2.urlopen(url)
        encoding = conn.headers.getparam("charset")
        content = conn.read().decode(encoding)
        s = re.findall(r'"url_encoded_fmt_stream_map": ?"([^"]+)"', content)
        if s:
            import HTMLParser

            s = s[0].split(",")
            s = [a.replace("\\u0026", "&") for a in s]
            s = [urllib2.parse_keqv_list(a.split("&")) for a in s]
            n = re.findall(r"<title>(.+) - YouTube</title>", content)
            s, n = (s or [], HTMLParser.HTMLParser().unescape(n[0]))
            for z in s:
                if z["itag"] == "18":
                    if "mp4" in z["type"]:
                        ext = ".mp4"
                    elif "flv" in z["type"]:
                        ext = ".flv"
                    try:
                        link = urllib.unquote(z["url"] + "&signature=%s" % z["sig"])
                    except:
                        link = urllib.unquote(z["url"])
            return link
    except:
        return False
开发者ID:cplaiasu,项目名称:krysty-xbmc,代码行数:27,代码来源:default.py


示例6: getYoutubeMovie

def getYoutubeMovie(url):
	try:
		conn = urllib2.urlopen(url)
		encoding = conn.headers.getparam('charset')
		content = conn.read().decode(encoding)
		#get available streams
		s = re.findall(r'"url_encoded_fmt_stream_map": ?"([^"]+)"', content)
		print s
		if s and len(s):
			s = s[0].split(',')
			values = {}
			for stream in s:
				stream = stream.replace('\\u0026', '&')
				stream = urllib2.parse_keqv_list(stream.split('&'))
				values[stream.get('itag') or "0"] = stream
			itags = values.keys()
			sorted(itags, reverse=True)
			print itags
			link = None
			for itag in itags:
				z = values[itag]
				if itag == '84' or itag == '82' or itag == '38' or itag == '37' or itag == '22' or itag == '18':
					try: 
						link = urllib.unquote(z['url'] + '&signature=%s' % z['sig'])
					except: 
						link = urllib.unquote(z['url'])
			return link
	except Exception as e:
		print e
		return None
开发者ID:strainu,项目名称:plugin.video.cinepub,代码行数:30,代码来源:youtube.py


示例7: _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


示例8: 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


示例9: _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


示例10: 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


示例11: 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


示例12: 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


示例13: 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


示例14: yt_get_all_url_maps_name

def yt_get_all_url_maps_name(url):
    conn = urllib2.urlopen(url)
    encoding = conn.headers.getparam('charset')
    content = conn.read().decode(encoding)
    s = re.findall(r'"url_encoded_fmt_stream_map": "([^"]+)"', content)
    if s:
        s = s[0].split(',')
        s = [a.replace('\\u0026', '&') for a in s]
        s = [urllib2.parse_keqv_list(a.split('&')) for a in s]

    n = re.findall(r'<title>(.+) - YouTube</title>', content)
    return  (s or [], 
            HTMLParser.HTMLParser().unescape(n[0]))
开发者ID:cplaiasu,项目名称:plugin.video.serialonline,代码行数:13,代码来源:default.py


示例15: createAuthObject

    def createAuthObject(authHeader):
        """
        Returns the authentication mechanism, or None if not implemented.
        """
        authType, challenge = authHeader.split(' ', 1)
        _authType_lower = authType.lower()

        challenge = urllib2.parse_keqv_list(urllib2.parse_http_list(challenge))
        assert _authType_lower in ('digest', 'ssl'), \
               repr(_authType_lower)

        # "basic" authentication is not supported
        return DigestAuthentication(challenge) if _authType_lower == 'digest' \
                                               else None
开发者ID:shvar,项目名称:redfs,代码行数:14,代码来源:client.py


示例16: _parse

 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)
开发者ID:anemitz,项目名称:calendarserver,代码行数:15,代码来源:httpauth.py


示例17: __init__

    def __init__(self, auth_header, http_method, debug=False):
        self.http_method = http_method
        self.debug = debug
        scheme, params = auth_header.split(" ", 1)
        self.scheme = scheme.lower()
        if self.scheme != 'digest':
            raise ValueError('Authorization scheme is not "Digest"')

        self.auth_header = auth_header

        # make a dict of the params
        items = parse_http_list(params)
        paramsd = parse_keqv_list(items)

        self.realm = paramsd.get('realm')
        self.username = paramsd.get('username')
        self.nonce = paramsd.get('nonce')
        self.uri = paramsd.get('uri')
        self.method = paramsd.get('method')
        self.response = paramsd.get('response') # the response digest
        self.algorithm = paramsd.get('algorithm', 'MD5')
        self.cnonce = paramsd.get('cnonce')
        self.opaque = paramsd.get('opaque')
        self.qop = paramsd.get('qop') # qop
        self.nc = paramsd.get('nc') # nonce count

        # perform some correctness checks
        if self.algorithm not in valid_algorithms:
            raise ValueError(self.errmsg("Unsupported value for algorithm: '%s'" % self.algorithm))

        has_reqd = self.username and \
                   self.realm and \
                   self.nonce and \
                   self.uri and \
                   self.response
        if not has_reqd:
            raise ValueError(self.errmsg("Not all required parameters are present."))

        if self.qop:
            if self.qop not in valid_qops:
                raise ValueError(self.errmsg("Unsupported value for qop: '%s'" % self.qop))
            if not (self.cnonce and self.nc):
                raise ValueError(self.errmsg("If qop is sent then cnonce and nc MUST be present"))
        else:
            if self.cnonce or self.nc:
                raise ValueError(self.errmsg("If qop is not sent, neither cnonce nor nc can be present"))
开发者ID:070499,项目名称:Sick-Beard,代码行数:46,代码来源:auth_digest.py


示例18: _parseDigestAuthorization

def _parseDigestAuthorization (auth_params):
    # Convert the auth params to a dict
    items = urllib2.parse_http_list (auth_params)
    params = urllib2.parse_keqv_list (items)

    # Now validate the params

    # Check for required parameters
    required = ["username", "realm", "nonce", "uri", "response"]
    for k in required:
        if not params.has_key(k):
            return None

    # If qop is sent then cnonce and cn MUST be present
    if params.has_key("qop") and not params.has_key("cnonce") \
                                  and params.has_key("cn"):
        return None

    return params
开发者ID:Juanvvc,项目名称:scfs,代码行数:19,代码来源:httpauth.py


示例19: get_proxy_authorization_line

def get_proxy_authorization_line(auth_type, auth_details, method, url, proxy_username, proxy_password):
    if auth_type.lower() == 'basic':
        response = base64.encodestring('%s:%s' % (proxy_username, proxy_password)).strip()
    elif auth_type.lower() == 'digest':

        class Passwd:

            def __init__(self, user, passwd):
                self.user, self.passwd = user, passwd

            def add_password(self, user, passwd):
                pass

            def find_user_password(self, realm, url):
                return (self.user, self.passwd)

            def get_full_url(self):
                return ''

        class DummyRequest:

            def __init__(self, method, url):
                self.method, self.url = method, url

            def get_method(self):
                return self.method

            def get_selector(self):
                return self.url

            def get_full_url(self):
                return self.url

            def has_data(self):
                return False

        digest_auth_handler = urllib2.AbstractDigestAuthHandler(passwd=Passwd(proxy_username or '', proxy_password or ''))
        chal = urllib2.parse_keqv_list(urllib2.parse_http_list(auth_details))
        response = digest_auth_handler.get_authorization(DummyRequest(method, url), chal)
    else:
        raise ValueError('Invalid proxy-authenticate line %r' % auth_type)
    return 'Proxy-Authorization: %s %s' % (auth_type, response)
开发者ID:bizonix,项目名称:DropBoxLibrarySRC,代码行数:42,代码来源:http_authentication.py


示例20: _parse_auth_info

def _parse_auth_info(auth_info):
    method, info_str = auth_info.split(' ', 1)
    if method != "Digest":
        raise ProviderError("Unknown authentication method: %s" % method)
    items = parse_http_list(info_str)
    info = parse_keqv_list(items)

    try:
        qop = info["qop"]
        realm = info["realm"]
        nonce = info["nonce"]
    except KeyError as e:
        raise ProviderError(
            "Authentication request missing required key: %s" % e)
    algorithm = info.get("algorithm", "MD5")
    if algorithm != "MD5":
        raise ProviderError("Unsupported digest algorithm: %s" % algorithm)
    if "auth" not in qop.split(","):
        raise ProviderError("Unsupported quality-of-protection: %s" % qop)
    return realm, nonce, "auth", algorithm
开发者ID:mcclurmc,项目名称:juju,代码行数:20,代码来源:digestauth.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python urllib2.quote函数代码示例发布时间:2022-05-27
下一篇:
Python urllib2.parse_http_list函数代码示例发布时间: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