本文整理汇总了Python中six.moves.urllib.parse.parse_qs函数的典型用法代码示例。如果您正苦于以下问题:Python parse_qs函数的具体用法?Python parse_qs怎么用?Python parse_qs使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parse_qs函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_add_extras
def test_add_extras(self):
context = {}
settings.ANALYTICS = {
'GOOGLE': {
'GTM_SITE_ID': 'gtm-site-id',
'GA_SITE_ID': 'ga-site-id',
},
'DAP': {
'AGENCY': 'agency',
'SUBAGENCY': 'sub-agency',
}
}
utils.add_extras(context)
self.assertTrue('APP_PREFIX' in context)
self.assertTrue('env' in context)
self.assertEquals('gtm-site-id',
context['ANALYTICS']['GOOGLE']['GTM_SITE_ID'])
self.assertEquals('ga-site-id',
context['ANALYTICS']['GOOGLE']['GA_SITE_ID'])
self.assertEquals('agency', context['ANALYTICS']['DAP']['AGENCY'])
self.assertEquals('sub-agency',
context['ANALYTICS']['DAP']['SUBAGENCY'])
self.assertEquals(
parse_qs('agency=agency&subagency=sub-agency'),
parse_qs(context['ANALYTICS']['DAP']['DAP_URL_PARAMS']),
)
示例2: test_list_buckets_non_empty
def test_list_buckets_non_empty(self):
from six.moves.urllib.parse import parse_qs
from six.moves.urllib.parse import urlencode
from six.moves.urllib.parse import urlparse
PROJECT = 'PROJECT'
CREDENTIALS = _Credentials()
client = self._makeOne(project=PROJECT, credentials=CREDENTIALS)
BUCKET_NAME = 'bucket-name'
query_params = urlencode({'project': PROJECT, 'projection': 'noAcl'})
BASE_URI = '/'.join([
client.connection.API_BASE_URL,
'storage',
client.connection.API_VERSION,
])
URI = '/'.join([BASE_URI, 'b?%s' % (query_params,)])
http = client.connection._http = _Http(
{'status': '200', 'content-type': 'application/json'},
'{{"items": [{{"name": "{0}"}}]}}'.format(BUCKET_NAME)
.encode('utf-8'),
)
buckets = list(client.list_buckets())
self.assertEqual(len(buckets), 1)
self.assertEqual(buckets[0].name, BUCKET_NAME)
self.assertEqual(http._called_with['method'], 'GET')
self.assertTrue(http._called_with['uri'].startswith(BASE_URI))
self.assertEqual(parse_qs(urlparse(http._called_with['uri']).query),
parse_qs(urlparse(URI).query))
示例3: _list_buckets_non_empty_helper
def _list_buckets_non_empty_helper(self, project, use_default=False):
from six.moves.urllib.parse import parse_qs
from six.moves.urllib.parse import urlencode
from six.moves.urllib.parse import urlparse
from gcloud._testing import _monkey_defaults as _base_monkey_defaults
from gcloud.storage._testing import _monkey_defaults
from gcloud.storage.connection import Connection
BUCKET_NAME = "bucket-name"
conn = Connection()
query_params = urlencode({"project": project, "projection": "noAcl"})
BASE_URI = "/".join([conn.API_BASE_URL, "storage", conn.API_VERSION])
URI = "/".join([BASE_URI, "b?%s" % (query_params,)])
http = conn._http = Http(
{"status": "200", "content-type": "application/json"},
'{{"items": [{{"name": "{0}"}}]}}'.format(BUCKET_NAME).encode("utf-8"),
)
if use_default:
with _base_monkey_defaults(project=project):
with _monkey_defaults(connection=conn):
buckets = list(self._callFUT())
else:
buckets = list(self._callFUT(project=project, connection=conn))
self.assertEqual(len(buckets), 1)
self.assertEqual(buckets[0].name, BUCKET_NAME)
self.assertEqual(http._called_with["method"], "GET")
self.assertTrue(http._called_with["uri"].startswith(BASE_URI))
self.assertEqual(parse_qs(urlparse(http._called_with["uri"]).query), parse_qs(urlparse(URI).query))
示例4: test_authorize_view
def test_authorize_view(self):
with self.app.test_client() as c:
rv = c.get('/oauth2authorize')
location = rv.headers['Location']
q = urlparse.parse_qs(location.split('?', 1)[1])
state = json.loads(q['state'][0])
self.assertTrue(GOOGLE_AUTH_URI in location)
self.assertFalse(self.oauth2.client_secret in location)
self.assertTrue(self.oauth2.client_id in q['client_id'])
self.assertEqual(
flask.session['google_oauth2_csrf_token'], state['csrf_token'])
self.assertEqual(state['return_url'], '/')
with self.app.test_client() as c:
rv = c.get('/oauth2authorize?return_url=/test')
location = rv.headers['Location']
q = urlparse.parse_qs(location.split('?', 1)[1])
state = json.loads(q['state'][0])
self.assertEqual(state['return_url'], '/test')
with self.app.test_client() as c:
rv = c.get('/oauth2authorize?extra_param=test')
location = rv.headers['Location']
self.assertTrue('extra_param=test' in location)
示例5: assertRedirectsNoFollow
def assertRedirectsNoFollow(self, response, expected_url, use_params=True,
status_code=302):
"""Checks response redirect without loading the destination page.
Django's assertRedirects method loads the destination page, which
requires that the page be renderable in the current test context
(possibly requiring additional, unrelated setup).
"""
# Assert that the response has the correct redirect code.
self.assertEqual(
response.status_code, status_code,
"Response didn't redirect as expected: Response code was {0} "
"(expected {1})".format(response.status_code, status_code))
# Assert that the response redirects to the correct base URL.
# Use force_text to force evaluation of anything created by
# reverse_lazy.
response_url = force_text(response['location'])
expected_url = force_text(expected_url)
parsed1 = urlparse(response_url)
parsed2 = urlparse(expected_url)
self.assertEquals(
parsed1.path, parsed2.path,
"Response did not redirect to the expected URL: Redirect "
"location was {0} (expected {1})".format(parsed1.path, parsed2.path))
# Optionally assert that the response redirect URL has the correct
# GET parameters.
if use_params:
self.assertDictEqual(
parse_qs(parsed1.query), parse_qs(parsed2.query),
"Response did not have the GET parameters expected: GET "
"parameters were {0} (expected "
"{1})".format(parsed1.query or {}, parsed2.query or {}))
示例6: _unicode_parse_qs
def _unicode_parse_qs(qs, **kwargs):
"""
A wrapper around ``urlparse.parse_qs`` that converts unicode strings to
UTF-8 to prevent ``urlparse.unquote`` from performing it's default decoding
to latin-1 see http://hg.python.org/cpython/file/2.7/Lib/urlparse.py
:param qs: Percent-encoded query string to be parsed.
:type qs: ``str``
:param kwargs: Other keyword args passed onto ``parse_qs``.
"""
if PY3 or isinstance(qs, bytes):
# Nothing to do
return parse_qs(qs, **kwargs)
qs = qs.encode('utf-8', 'ignore')
query = parse_qs(qs, **kwargs)
unicode_query = {}
for key in query:
uni_key = key.decode('utf-8', 'ignore')
if uni_key == '':
# because we ignore decode errors and only support utf-8 right now,
# we could end up with a blank string which we ignore
continue
unicode_query[uni_key] = [p.decode('utf-8', 'ignore') for p in query[key]]
return unicode_query
示例7: test_collection_ok_by_state
def test_collection_ok_by_state(
self, f_users, f_coprs,
f_mock_chroots_many,
f_build_many_chroots,
f_db,
f_users_api):
self.db.session.commit()
for status in StatusEnum.vals.values():
expected_chroots = set([
name
for name, chroot_status in
self.status_by_chroot.items()
if chroot_status == status
])
href = "/api_2/build_tasks?state={}&limit=50".format(StatusEnum(status))
r0 = self.tc.get(href)
assert r0.status_code == 200
obj = json.loads(r0.data.decode("utf-8"))
assert len(obj["build_tasks"]) == len(expected_chroots)
assert set(bt["build_task"]["chroot_name"]
for bt in obj["build_tasks"]) == expected_chroots
assert parse_qs(urlparse(obj["_links"]["self"]["href"]).query) \
== parse_qs(urlparse(href).query)
示例8: test_signature_values
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
params = parse_qs(query)
self.assertEqual(params['signature'][0], CALL_SIGNATURES[0])
query = responses.calls[1].request.body
params = parse_qs(query)
self.assertEqual(params['signature'][0], CALL_SIGNATURES[1])
示例9: test_authorize_view
def test_authorize_view(self):
with self.app.test_client() as client:
response = client.get('/oauth2authorize')
location = response.headers['Location']
q = urlparse.parse_qs(location.split('?', 1)[1])
state = json.loads(q['state'][0])
self.assertIn(GOOGLE_AUTH_URI, location)
self.assertNotIn(self.oauth2.client_secret, location)
self.assertIn(self.oauth2.client_id, q['client_id'])
self.assertEqual(
flask.session['google_oauth2_csrf_token'], state['csrf_token'])
self.assertEqual(state['return_url'], '/')
with self.app.test_client() as client:
response = client.get('/oauth2authorize?return_url=/test')
location = response.headers['Location']
q = urlparse.parse_qs(location.split('?', 1)[1])
state = json.loads(q['state'][0])
self.assertEqual(state['return_url'], '/test')
with self.app.test_client() as client:
response = client.get('/oauth2authorize?extra_param=test')
location = response.headers['Location']
self.assertIn('extra_param=test', location)
示例10: _match_url
def _match_url(self, request):
if self._url is ANY:
return True
# regular expression matching
if hasattr(self._url, 'search'):
return self._url.search(request.url) is not None
if self._url_parts.scheme and request.scheme != self._url_parts.scheme:
return False
if self._url_parts.netloc and request.netloc != self._url_parts.netloc:
return False
if (request.path or '/') != (self._url_parts.path or '/'):
return False
# construct our own qs structure as we remove items from it below
request_qs = urlparse.parse_qs(request.query)
matcher_qs = urlparse.parse_qs(self._url_parts.query)
for k, vals in six.iteritems(matcher_qs):
for v in vals:
try:
request_qs.get(k, []).remove(v)
except ValueError:
return False
if self._complete_qs:
for v in six.itervalues(request_qs):
if v:
return False
return True
示例11: new_websocket_client
def new_websocket_client(self):
"""Called after a new WebSocket connection has been established."""
# Reopen the eventlet hub to make sure we don't share an epoll
# fd with parent and/or siblings, which would be bad
from eventlet import hubs
hubs.use_hub()
# The zun expected behavior is to have token
# passed to the method GET of the request
parse = urlparse.urlparse(self.path)
if parse.scheme not in ('http', 'https'):
# From a bug in urlparse in Python < 2.7.4 we cannot support
# special schemes (cf: https://bugs.python.org/issue9374)
if sys.version_info < (2, 7, 4):
raise exception.ZunException(
_("We do not support scheme '%s' under Python < 2.7.4, "
"please use http or https") % parse.scheme)
query = parse.query
token = urlparse.parse_qs(query).get("token", [""]).pop()
uuid = urlparse.parse_qs(query).get("uuid", [""]).pop()
exec_id = urlparse.parse_qs(query).get("exec_id", [""]).pop()
ctx = context.get_admin_context(all_projects=True)
if uuidutils.is_uuid_like(uuid):
container = objects.Container.get_by_uuid(ctx, uuid)
else:
container = objects.Container.get_by_name(ctx, uuid)
if exec_id:
self._new_exec_client(container, token, uuid, exec_id)
else:
self._new_websocket_client(container, token, uuid)
示例12: get_msg
def get_msg(hinfo, binding, response=False):
if binding == BINDING_SOAP:
msg = hinfo["data"]
elif binding == BINDING_HTTP_POST:
_inp = hinfo["data"][3]
i = _inp.find(TAG1)
i += len(TAG1) + 1
j = _inp.find('"', i)
msg = _inp[i:j]
elif binding == BINDING_HTTP_ARTIFACT:
# either by POST or by redirect
if hinfo["data"]:
_inp = hinfo["data"][3]
i = _inp.find(TAG1)
i += len(TAG1) + 1
j = _inp.find('"', i)
msg = _inp[i:j]
else:
parts = urlparse(hinfo["url"])
msg = parse_qs(parts.query)["SAMLart"][0]
else: # BINDING_HTTP_REDIRECT
parts = urlparse(hinfo["headers"][0][1])
msg = parse_qs(parts.query)["SAMLRequest"][0]
return msg
示例13: discharge
def discharge(url, request):
qs = parse_qs(request.body)
if qs.get('token64') is None:
return response(
status_code=401,
content={
'Code': httpbakery.ERR_INTERACTION_REQUIRED,
'Message': 'interaction required',
'Info': {
'InteractionMethods': {
'agent': {'login-url': '/login'},
},
},
},
headers={'Content-Type': 'application/json'})
else:
qs = parse_qs(request.body)
content = {q: qs[q][0] for q in qs}
m = httpbakery.discharge(checkers.AuthContext(), content,
discharge_key, None, alwaysOK3rd)
return {
'status_code': 200,
'content': {
'Macaroon': m.to_dict()
}
}
示例14: _list_buckets_non_empty_helper
def _list_buckets_non_empty_helper(self, project, use_default=False):
from six.moves.urllib.parse import parse_qs
from six.moves.urllib.parse import urlencode
from six.moves.urllib.parse import urlparse
from gcloud._testing import _monkey_defaults as _base_monkey_defaults
from gcloud.storage._testing import _monkey_defaults
from gcloud.storage.connection import Connection
BUCKET_NAME = 'bucket-name'
conn = Connection()
query_params = urlencode({'project': project, 'projection': 'noAcl'})
BASE_URI = '/'.join([
conn.API_BASE_URL,
'storage',
conn.API_VERSION,
])
URI = '/'.join([BASE_URI, 'b?%s' % (query_params,)])
http = conn._http = Http(
{'status': '200', 'content-type': 'application/json'},
'{{"items": [{{"name": "{0}"}}]}}'.format(BUCKET_NAME)
.encode('utf-8'),
)
if use_default:
with _base_monkey_defaults(project=project):
with _monkey_defaults(connection=conn):
buckets = list(self._callFUT())
else:
buckets = list(self._callFUT(project=project, connection=conn))
self.assertEqual(len(buckets), 1)
self.assertEqual(buckets[0].name, BUCKET_NAME)
self.assertEqual(http._called_with['method'], 'GET')
self.assertTrue(http._called_with['uri'].startswith(BASE_URI))
self.assertEqual(parse_qs(urlparse(http._called_with['uri']).query),
parse_qs(urlparse(URI).query))
示例15: test_build_ga_params_for_campaign_tracking_params
def test_build_ga_params_for_campaign_tracking_params(self):
'''
Test that the correct GA campaign
tracking params are tracked correctly
'''
request = self.make_fake_request(
'/somewhere/?utm_campaign=campaign name&utm_term=campaign keyword')
ga_dict_with_campaign_params = build_ga_params(
request, 'ua-test-id', '/compaign/path/')
self.assertEqual(
parse_qs(ga_dict_with_campaign_params.get(
'utm_url')).get('cn'), ['campaign name'])
self.assertEqual(
parse_qs(ga_dict_with_campaign_params.get(
'utm_url')).get('ck'), ['campaign keyword'])
# params that aren't in the request should be excluded from the utm_url
self.assertEqual(
parse_qs(
ga_dict_with_campaign_params.get(
'utm_url')).get('cs'), None)
self.assertEqual(
parse_qs(
ga_dict_with_campaign_params.get(
'utm_url')).get('cm'), None)