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


Python parse.parse_qs方法代码示例

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


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

示例1: deurlform

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import parse_qs [as 别名]
def deurlform(d):
    """
    Convert a URL encoded query string to a dictionary.

    Args:
        d(str): The URL encoded query string.

    Returns:
        dict: A dictionary containing each key and all its values as a list.

    Example:
        >>> from pwny import *
        >>> deurlform('foo=bar&baz=quux&baz=corge')
        {'foo': ['bar'], 'baz': ['quux', 'corge']}
    """
    return parse_qs(d) 
开发者ID:edibledinos,项目名称:pwnypack,代码行数:18,代码来源:codec.py

示例2: _connect_elasticsearch

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import parse_qs [as 别名]
def _connect_elasticsearch(parsed, dbtype):
    # in python 2.6 url like "http://host/?query", query will not been splitted
    if parsed.path.startswith('/?'):
        index = parse_qs(parsed.path[2:])
    else:
        index = parse_qs(parsed.query)
    if 'index' in index and index['index']:
        index = index['index'][0]
    else:
        index = 'pyspider'

    if dbtype == 'projectdb':
        from .elasticsearch.projectdb import ProjectDB
        return ProjectDB([parsed.netloc], index=index)
    elif dbtype == 'resultdb':
        from .elasticsearch.resultdb import ResultDB
        return ResultDB([parsed.netloc], index=index)
    elif dbtype == 'taskdb':
        from .elasticsearch.taskdb import TaskDB
        return TaskDB([parsed.netloc], index=index) 
开发者ID:binux,项目名称:pyspider,代码行数:22,代码来源:__init__.py

示例3: test_default

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import parse_qs [as 别名]
def test_default(self):
        target = TestTableauServerResultTarget(test_config.get_tmp_path('result.job'))
        target.datasource = 'test-datasource'
        url = urlparse(target.get_result_url())
        params = parse_qs(url.query)
        eq_(url.scheme, 'tableau')
        eq_(url.hostname, 'tableau.example.com')
        eq_(url.path, '/' + target.datasource)
        eq_(url_unquote(url.username), TestTableauServerResultTarget.username)
        eq_(url_unquote(url.password), TestTableauServerResultTarget.password)
        eq_(params.get('ssl'), ['true'])
        eq_(params.get('ssl_verify'), ['true'])
        eq_(params.get('server_version'), None)
        eq_(params.get('site'), None)
        eq_(params.get('project'), None)
        eq_(params.get('mode'), ['replace']) 
开发者ID:treasure-data,项目名称:luigi-td,代码行数:18,代码来源:test_tableau.py

示例4: test_refresh

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import parse_qs [as 别名]
def test_refresh():
    """
    Test token expiration and refresh.
    """
    test_client = make_test_client()

    with patch('time.time', Mock(return_value=time.time())) as time_1:
        # authenticate and get an ID token cookie
        auth_redirect = test_client.get('/')
        callback_redirect = test_client.get(callback_url_for(auth_redirect))
        actual_page = test_client.get(callback_redirect.headers['Location'])
        page_text = ''.join(codecs.iterdecode(actual_page.response, 'utf-8'))
        assert page_text == 'too many secrets', "Authentication failed"

    # app should now try to use the refresh token
    with patch('time.time', Mock(return_value=time.time() + 10)) as time_2:
        test_client.get('/')
        body = parse_qs(last_request['body'])
        assert body.get('refresh_token') == ['mock_refresh_token'],\
            "App should have tried to refresh credentials" 
开发者ID:puiterwijk,项目名称:flask-oidc,代码行数:22,代码来源:test_flask_oidc.py

示例5: test_get_relative_url_with_unicode

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import parse_qs [as 别名]
def test_get_relative_url_with_unicode(self):
        """Tests if it properly converts multibyte characters."""
        from six.moves.urllib import parse as urlparse

        self.view.request = self.request_factory.get(
            '/', data={'a': 1, 'b': 2}
        )
        expected_path = ('/elasticsearch/.kibana/search'
                         '/New-Saved-Search%E3%81%82')
        expected_qs = {'a': ['1'], 'b': ['2']}

        url = self.view.get_relative_url(
            u'/elasticsearch/.kibana/search/New-Saved-Searchあ'
        )
        # order of query params may change
        parsed_url = urlparse.urlparse(url)
        actual_path = parsed_url.path
        actual_qs = urlparse.parse_qs(parsed_url.query)

        self.assertEqual(actual_path, expected_path)
        self.assertEqual(actual_qs, expected_qs) 
开发者ID:openstack,项目名称:monasca-ui,代码行数:23,代码来源:tests.py

示例6: change_url

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import parse_qs [as 别名]
def change_url(request, kwargs=None, query=None):
    kwargs = kwargs or {}
    query = query or {}
    rm = request.resolver_match
    _kwargs = rm.kwargs.copy()
    _kwargs.update(kwargs)
    if _kwargs.get("page") == 1:
        _kwargs.pop('page', None)
    qs = parse_qs(urlparse(request.get_full_path()).query)
    qs.update(query)
    path = reverse(
        '%s:%s' % (rm.namespace, rm.url_name),
        args=rm.args,
        kwargs=_kwargs,
    )
    if (qs):
        return "%s?%s" % (path, urlencode(qs, True))
    else:
        return path 
开发者ID:ericls,项目名称:niji,代码行数:21,代码来源:niji_tags.py

示例7: _pagination

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import parse_qs [as 别名]
def _pagination(self, collection, path, **params):
        if params.get('page_reverse', False):
            linkrel = 'previous'
        else:
            linkrel = 'next'
        next = True
        while next:
            res = self.get(path, params=params)
            yield res
            next = False
            try:
                for link in res['%s_links' % collection]:
                    if link['rel'] == linkrel:
                        query_str = urlparse.urlparse(link['href']).query
                        params = urlparse.parse_qs(query_str)
                        next = True
                        break
            except KeyError:
                break 
开发者ID:nttcom,项目名称:eclcli,代码行数:21,代码来源:client.py

示例8: _process_url

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import parse_qs [as 别名]
def _process_url(page_from, page_to, url):

    # Get url page
    query = urlparse(url).query
    query = parse_qs(query)
    page = query.get('page')

    # Preserve if match
    if page:
        page_from = int(page_from)
        page_to = int(page_to)
        page = int(page[0])
        if page >= page_from and page <= page_to:
            return url

    return None 
开发者ID:opentrials,项目名称:collectors,代码行数:18,代码来源:spider.py

示例9: test_signature_values

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import parse_qs [as 别名]
def test_signature_values(self):
        """Test signature generation and update"""

        body = """
        {"response": {
            "user_info": {}, "new_key": "yes", "result": "Success"}
        }
        """

        responses.add(responses.POST, self.url, body=body, status=200,
                      content_type="application/json")
        # original secret key
        self.api.user_get_info()
        # secret key is (1000000000 * 16807) % 2147483647 = 792978578
        self.api.user_get_info()

        query = responses.calls[0].request.body.decode('utf-8')
        params = parse_qs(query)

        self.assertEqual(params['signature'][0], CALL_SIGNATURES[0])

        query = responses.calls[1].request.body.decode('utf-8')
        params = parse_qs(query)

        self.assertEqual(params['signature'][0], CALL_SIGNATURES[1]) 
开发者ID:MediaFire,项目名称:mediafire-python-open-sdk,代码行数:27,代码来源:test_signature.py

示例10: parse_query_string

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import parse_qs [as 别名]
def parse_query_string(url, parameters):
        if not parameters:
            return ''

        url_query = url.query
        if six.PY2:
            url_query = url_query.encode('utf-8')
        query_params = parse_qs(url_query, keep_blank_values=True)
        query_common = set.intersection(set(query_params.keys()), set(parameters))
        fragment_params = parse_qs(url.fragment, keep_blank_values=True)
        fragment_common = set.intersection(set(fragment_params.keys()), set(parameters))
        query = ''
        if len(query_common) > 0:
            query = query_params[list(query_common)[0]][0]
        elif len(fragment_common) > 0:
            query = fragment_params[list(fragment_common)[0]][0]
        elif '*' in parameters:
            query = ''

        if six.PY2:
            return query.decode('utf-8')
        return query 
开发者ID:Shopify,项目名称:pyreferrer,代码行数:24,代码来源:referrer.py

示例11: _show

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import parse_qs [as 别名]
def _show(self, req, id, detail=False):
        context = req.environ['manila.context']
        params = parse.parse_qs(req.environ.get('QUERY_STRING', ''))
        user_id = params.get('user_id', [None])[0]
        share_type = params.get('share_type', [None])[0]
        try:
            db.authorize_project_context(context, id)
            # _get_quotas use 'usages' to indicate whether retrieve additional
            # attributes, so pass detail to the argument.
            share_type_id = self._get_share_type_id(context, share_type)
            quotas = self._get_quotas(
                context, id, user_id, share_type_id, usages=detail)
            return self._view_builder.detail_list(
                req, quotas, id, share_type_id)
        except exception.NotAuthorized:
            raise webob.exc.HTTPForbidden() 
开发者ID:openstack,项目名称:manila,代码行数:18,代码来源:quota_sets.py

示例12: _delete

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import parse_qs [as 别名]
def _delete(self, req, id):
        context = req.environ['manila.context']
        params = parse.parse_qs(req.environ.get('QUERY_STRING', ''))
        user_id = params.get('user_id', [None])[0]
        share_type = params.get('share_type', [None])[0]
        self._validate_user_id_and_share_type_args(user_id, share_type)
        try:
            db.authorize_project_context(context, id)
            if user_id:
                QUOTAS.destroy_all_by_project_and_user(context, id, user_id)
            elif share_type:
                share_type_id = self._get_share_type_id(context, share_type)
                QUOTAS.destroy_all_by_project_and_share_type(
                    context, id, share_type_id)
            else:
                QUOTAS.destroy_all_by_project(context, id)
            return webob.Response(status_int=http_client.ACCEPTED)
        except exception.NotAuthorized:
            raise webob.exc.HTTPForbidden() 
开发者ID:openstack,项目名称:manila,代码行数:21,代码来源:quota_sets.py

示例13: test_logout_response_http_redirect

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import parse_qs [as 别名]
def test_logout_response_http_redirect(self, unravel, verified):
        # See: https://github.com/italia/spid-testenv2/issues/88
        with patch('testenv.server.IdpServer._sp_single_logout_service', return_value=_sp_single_logout_service(self.idp_server, 'https://spid.test:8000', BINDING_HTTP_REDIRECT)) as mocked:  # noqa: F841
            response = self.test_client.get(
                '/slo-test?SAMLRequest=b64encodedrequest&SigAlg={}&Signature=sign'.format(
                    quote(SIG_RSA_SHA256)), follow_redirects=False)
            self.assertEqual(response.status_code, 302)
            response_location = response.headers.get('Location')
            url = urlparse(response_location)
            query = parse_qs(url.query)
            self.assertIn(
                'Signature',
                query
            )
            saml_response = query.get('SAMLResponse')[0]
            response = decode_base64_and_inflate(saml_response)
            xml = ET.fromstring(response)
            signatures = xml.findall(
                './/{http://www.w3.org/2000/09/xmldsig#}Signature')
            self.assertEqual(0, len(signatures))
            self.assertEqual(len(self.idp_server.ticket), 0)
            self.assertEqual(len(self.idp_server.responses), 0) 
开发者ID:italia,项目名称:spid-testenv2,代码行数:24,代码来源:test_spid_testenv.py

示例14: test_list_pagination_with_empty_page

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import parse_qs [as 别名]
def test_list_pagination_with_empty_page(self):
        return_value = []
        instance = self.plugin.return_value
        instance.get_networks.return_value = return_value
        params = {'limit': ['2'],
                  'marker': str(_uuid())}
        res = self.api.get(_get_path('networks'),
                           params=params).json

        self.assertEqual([], res['networks'])

        previous_links = []
        if 'networks_links' in res:
            for r in res['networks_links']:
                self.assertNotEqual(r['rel'], 'next')
                if r['rel'] == 'previous':
                    previous_links.append(r)
        self.assertEqual(1, len(previous_links))

        url = urlparse.urlparse(previous_links[0]['href'])
        self.assertEqual(_get_path('networks'), url.path)
        expect_params = params.copy()
        del expect_params['marker']
        expect_params['page_reverse'] = ['True']
        self.assertEqual(expect_params, urlparse.parse_qs(url.query)) 
开发者ID:openstack,项目名称:tacker,代码行数:27,代码来源:test_api_v2.py

示例15: test_list_pagination_reverse_with_empty_page

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import parse_qs [as 别名]
def test_list_pagination_reverse_with_empty_page(self):
        return_value = []
        instance = self.plugin.return_value
        instance.get_networks.return_value = return_value
        params = {'limit': ['2'],
                  'marker': [str(_uuid())],
                  'page_reverse': ['True']}
        res = self.api.get(_get_path('networks'),
                           params=params).json
        self.assertEqual([], res['networks'])

        next_links = []
        if 'networks_links' in res:
            for r in res['networks_links']:
                self.assertNotEqual(r['rel'], 'previous')
                if r['rel'] == 'next':
                    next_links.append(r)
        self.assertEqual(1, len(next_links))

        url = urlparse.urlparse(next_links[0]['href'])
        self.assertEqual(_get_path('networks'), url.path)
        expect_params = params.copy()
        del expect_params['marker']
        del expect_params['page_reverse']
        self.assertEqual(expect_params, urlparse.parse_qs(url.query)) 
开发者ID:openstack,项目名称:tacker,代码行数:27,代码来源:test_api_v2.py


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