当前位置: 首页>>代码示例>>Python>>正文


Python parse.parse_qsl方法代码示例

本文整理汇总了Python中six.moves.urllib.parse.parse_qsl方法的典型用法代码示例。如果您正苦于以下问题:Python parse.parse_qsl方法的具体用法?Python parse.parse_qsl怎么用?Python parse.parse_qsl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在six.moves.urllib.parse的用法示例。


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

示例1: test_error_view

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import parse_qsl [as 别名]
def test_error_view(self):
        client = app.test_client()

        auth_redirect = client.get('/')
        parsed_auth_request = dict(parse_qsl(urlparse(auth_redirect.location).query))

        # fake auth error response sent to redirect_uri
        error_auth_response = {
            'error': 'invalid_request',
            'error_description': 'test error',
            'state': parsed_auth_request['state']
        }
        error_page = client.get('/redirect_uri?{}'.format(urlencode(error_auth_response)), follow_redirects=True)

        assert json.loads(error_page.data.decode('utf-8')) == {
            'error': error_auth_response['error'],
            'message': error_auth_response['error_description']
        } 
开发者ID:zamzterz,项目名称:Flask-pyoidc,代码行数:20,代码来源:test_example_app.py

示例2: combine_url

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import parse_qsl [as 别名]
def combine_url(url, page, pagetitle, **kwargs):
    """ Add the specified arguments in the provided kwargs dictionary to
    the given URL.
    """
    url_obj = urlparse(url)
    url = url_obj.geturl().replace(url_obj.query, "").rstrip("?")
    query = {}
    for k, v in parse_qsl(url_obj.query):
        if k in query:
            if isinstance(query[k], list):
                query[k].append(v)
            else:
                query[k] = [query[k], v]
        else:
            query[k] = v
    query[pagetitle] = page
    query.update(kwargs)
    args = ""
    for key in query:
        if isinstance(query[key], list):
            for val in query[key]:
                args += "&%s=%s" % (key, val)
        else:
            args += "&%s=%s" % (key, query[key])
    return url + "?" + args[1:] 
开发者ID:Pagure,项目名称:pagure,代码行数:27,代码来源:filters.py

示例3: connect_device

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import parse_qsl [as 别名]
def connect_device(uri):
    """
    Initialize device with uri, and set as current device.

    :param uri: an URI where to connect to device, e.g. `android://adbhost:adbport/serialno?param=value&param2=value2`
    :return: device instance
    :Example:
        * ``android:///`` # local adb device using default params
        * ``android://adbhost:adbport/1234566?cap_method=javacap&touch_method=adb``  # remote device using custom params
        * ``windows:///`` # local Windows application
        * ``ios:///`` # iOS device
    """
    d = urlparse(uri)
    platform = d.scheme
    host = d.netloc
    uuid = d.path.lstrip("/")
    params = dict(parse_qsl(d.query))
    if host:
        params["host"] = host.split(":")
    dev = init_device(platform, uuid, **params)
    return dev 
开发者ID:AirtestProject,项目名称:Airtest,代码行数:23,代码来源:api.py

示例4: _add_query_parameters

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import parse_qsl [as 别名]
def _add_query_parameters(base_url, name_value_pairs):
    """Add one query parameter to a base URL.

    :type base_url: string
    :param base_url: Base URL (may already contain query parameters)

    :type name_value_pairs: list of (string, string) tuples.
    :param name_value_pairs: Names and values of the query parameters to add

    :rtype: string
    :returns: URL with additional query strings appended.
    """
    if len(name_value_pairs) == 0:
        return base_url

    scheme, netloc, path, query, frag = urlsplit(base_url)
    query = parse_qsl(query)
    query.extend(name_value_pairs)
    return urlunsplit((scheme, netloc, path, urlencode(query), frag)) 
开发者ID:googleapis,项目名称:python-storage,代码行数:21,代码来源:blob.py

示例5: parse_proxy_uri

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import parse_qsl [as 别名]
def parse_proxy_uri(uri):
    uri = urlparse(uri)
    proxy_options = dict(parse_qsl(uri.query))
    proxy_type = {
        'SOCKS4': socks.PROXY_TYPE_SOCKS4,
        'SOCKS5': socks.PROXY_TYPE_SOCKS5,
    }.get(uri.scheme.upper())

    if not proxy_type:
        raise ValueError('%r is not supported proxy protocol' % uri.scheme)
    if not uri.hostname:
        raise ValueError('hostname is required')

    return {
        'proxy_type': proxy_type,
        'addr': uri.hostname,
        'port': uri.port or 1080,
        'rdns': proxy_options.get('rdns', True),
        'username': uri.username,
        'password': uri.password,
    } 
开发者ID:tonyseek,项目名称:rsocks,代码行数:23,代码来源:utils.py

示例6: test_post

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import parse_qsl [as 别名]
def test_post(self):
        """Tests POST requests to delete a record."""
        get_doc = self.to_doc(self.client.get(
            '/global/admin/delete_record/', secure=True))
        xsrf_token = get_doc.cssselect_one('input[name="xsrf_token"]').get(
            'value')
        post_resp = self.client.post('/haiti/admin/delete_record/', {
            'xsrf_token': xsrf_token,
            'id': self.person.record_id,
        }, secure=True)
        # Check that the user's redirected to the repo's main admin page.
        self.assertIsInstance(post_resp, django.http.HttpResponseRedirect)
        parse = urlparse.urlparse(post_resp.url)
        self.assertEqual('/haiti/delete', parse.path)
        query_params = dict(urlparse.parse_qsl(parse.query))
        self.assertEqual(query_params['id'], self.person.record_id)
        # Check that the signature param is present and not the empty string.
        self.assertTrue(len(query_params['signature']) > 1) 
开发者ID:google,项目名称:personfinder,代码行数:20,代码来源:test_admin_delete_record.py

示例7: proxy_with_warning_page_mock

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import parse_qsl [as 别名]
def proxy_with_warning_page_mock(url, *args, **kwargs):
    cookies = kwargs.get('cookies') or {}
    proxy_cookie = cookies.get('proxy_cookie')
    url_parts = list(urlparse(url))
    query = dict(parse_qsl(url_parts[4]))
    if proxy_cookie and query.get('proxyapproved') == 'true':
        del query['proxyapproved']
        url_parts[4] = urlencode(query)
        return standalone_requests_get_mock(urlunparse(url_parts), *args[1:], **kwargs)
    else:
        # Display the html warning page with the redirect link
        query['proxyapproved'] = 'true'
        url_parts[4] = urlencode(query)
        with open(os.path.join(FIXTURE_DIR, 'html_warning_page'), 'r') as f:
            body = f.read().replace('$REDIRECT_URL$', urlunparse(url_parts))
            cookies['proxy_cookie'] = 'foo'
            return MockedResponse(body, 200, cookies) 
开发者ID:DataDog,项目名称:integrations-core,代码行数:19,代码来源:test_spark.py

示例8: perform_authentication

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import parse_qsl [as 别名]
def perform_authentication(self, test_client, login_endpoint, client_id, provider_metadata):
        # index page should make auth request
        auth_redirect = test_client.get(login_endpoint)
        parsed_auth_request = dict(parse_qsl(urlparse(auth_redirect.location).query))

        now = int(time.time())
        # mock token response
        id_token = IdToken(iss=provider_metadata['issuer'],
                           aud=client_id,
                           sub=self.USER_ID,
                           exp=now + 10,
                           iat=now,
                           nonce=parsed_auth_request['nonce'])
        token_response = {'access_token': 'test_access_token', 'token_type': 'Bearer', 'id_token': id_token.to_jwt()}
        responses.add(responses.POST, provider_metadata['token_endpoint'], json=token_response)

        # mock userinfo response
        userinfo = {'sub': self.USER_ID, 'name': 'Test User'}
        responses.add(responses.GET, provider_metadata['userinfo_endpoint'], json=userinfo)

        # fake auth response sent to redirect URI
        fake_auth_response = 'code=fake_auth_code&state={}'.format(parsed_auth_request['state'])
        logged_in_page = test_client.get('/redirect_uri?{}'.format(fake_auth_response), follow_redirects=True)
        result = json.loads(logged_in_page.data.decode('utf-8'))

        assert result['access_token'] == 'test_access_token'
        assert result['id_token'] == id_token.to_dict()
        assert result['userinfo'] == {'sub': self.USER_ID, 'name': 'Test User'} 
开发者ID:zamzterz,项目名称:Flask-pyoidc,代码行数:30,代码来源:test_example_app.py

示例9: remove_url_params

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import parse_qsl [as 别名]
def remove_url_params(url, params):
    parsed = urlparse(url)
    qsl = parse_qsl(parsed.query)
    for item in iteritems(params):
        qsl.remove(item)
    replaced = parsed._replace(query=urlencode(qsl))
    return urlunparse(replaced) 
开发者ID:eBay,项目名称:wextracto,代码行数:9,代码来源:http.py

示例10: test_build_api_url_w_extra_query_params

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import parse_qsl [as 别名]
def test_build_api_url_w_extra_query_params(self):
        from six.moves.urllib.parse import parse_qsl
        from six.moves.urllib.parse import urlsplit

        conn = self._make_one(object())
        uri = conn.build_api_url("/foo", {"bar": "baz"})
        scheme, netloc, path, qs, _ = urlsplit(uri)
        self.assertEqual("%s://%s" % (scheme, netloc), conn.API_BASE_URL)
        self.assertEqual(path, "/".join(["", "storage", conn.API_VERSION, "foo"]))
        parms = dict(parse_qsl(qs))
        self.assertEqual(parms["bar"], "baz") 
开发者ID:googleapis,项目名称:python-storage,代码行数:13,代码来源:test__http.py

示例11: get_params

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import parse_qsl [as 别名]
def get_params(self):

        ''' Get the params
        '''
        try:
            path = self.path[1:]

            if '?' in path:
                path = path.split('?', 1)[1]

            params = dict(parse_qsl(path))
        except Exception:
            params = {}

        return params 
开发者ID:jellyfin,项目名称:jellyfin-kodi,代码行数:17,代码来源:webservice.py

示例12: resolve_uri

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import parse_qsl [as 别名]
def resolve_uri(uri):
    scheme, netloc, path, params, query, fragment = parse.urlparse(uri)
    if params:
        raise ValueError("Unexpected URI params", params)
    if fragment:
        raise ValueError("Unexpected URI fragment", fragment)

    dbkw = {}
    options = {}
    pgq = ''

    if query:
        pgq = []
        for name, value in parse.parse_qsl(query):
            if name in storage_options:
                options[name] = storage_options[name](value)
            elif name in db_options:
                dbkw[name] = db_options[name](value)
            else:
                pgq.append(name + '=' + value)
        pgq = '?' + '&'.join(pgq) if pgq else ''

    dsn = "postgresql://" + netloc + path + pgq

    def factory():
        import newt.db
        return newt.db.storage(dsn, **options)

    return factory, dbkw 
开发者ID:newtdb,项目名称:db,代码行数:31,代码来源:zodburi.py

示例13: test_build_api_url_w_extra_query_params

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import parse_qsl [as 别名]
def test_build_api_url_w_extra_query_params(self):
        from six.moves.urllib.parse import parse_qsl
        from six.moves.urllib.parse import urlsplit

        conn = self._make_one(object())
        uri = conn.build_api_url("/foo", {"bar": "baz"})
        scheme, netloc, path, qs, _ = urlsplit(uri)
        self.assertEqual("%s://%s" % (scheme, netloc), conn.API_BASE_URL)
        self.assertEqual(path, "/".join(["", "bigquery", conn.API_VERSION, "foo"]))
        parms = dict(parse_qsl(qs))
        self.assertEqual(parms["bar"], "baz") 
开发者ID:googleapis,项目名称:python-bigquery,代码行数:13,代码来源:test__http.py

示例14: get_limit_and_offset_from_ref

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import parse_qsl [as 别名]
def get_limit_and_offset_from_ref(ref):
    matches = dict(parse.parse_qsl(parse.urlparse(ref).query))
    ref_limit = matches['limit']
    ref_offset = matches['offset']

    return ref_limit, ref_offset 
开发者ID:cloud-security-research,项目名称:sgx-kms,代码行数:8,代码来源:utils.py

示例15: get_limit_and_offset_from_ref

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import parse_qsl [as 别名]
def get_limit_and_offset_from_ref(ref):
    matches = dict(urlparse.parse_qsl(urlparse.urlparse(ref).query))
    ref_limit = matches['limit']
    ref_offset = matches['offset']

    return ref_limit, ref_offset 
开发者ID:openstack,项目名称:python-barbicanclient,代码行数:8,代码来源:utils.py


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