Python six.moves.urllib.parse.urlencode() Examples
The following are 30
code examples of six.moves.urllib.parse.urlencode().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
six.moves.urllib.parse
, or try the search function
.
Example #1
Source File: base.py From designate with Apache License 2.0 | 6 votes |
def _get_collection_href(cls, request, extra_params=None): params = request.GET if extra_params is not None: params.update(extra_params) if cfg.CONF['service:api'].enable_host_header: try: base_uri = request.host_url except Exception: base_uri = cls.BASE_URI else: base_uri = cls.BASE_URI href = "%s%s?%s" % ( base_uri, cls._get_path(request), parse.urlencode(params)) return href.rstrip('?')
Example #2
Source File: test_example_app.py From Flask-pyoidc with Apache License 2.0 | 6 votes |
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'] }
Example #3
Source File: base.py From eclcli with Apache License 2.0 | 6 votes |
def find(self, base_url=None, **kwargs): """Find a single item with attributes matching ``**kwargs``. :param base_url: if provided, the generated URL will be appended to it """ kwargs = self._filter_kwargs(kwargs) rl = self._list( '%(base_url)s%(query)s' % { 'base_url': self.build_url(base_url=base_url, **kwargs), 'query': '?%s' % parse.urlencode(kwargs) if kwargs else '', }, self.collection_key) num = len(rl) if num == 0: msg = _("No %(name)s matching %(args)s.") % { 'name': self.resource_class.__name__, 'args': kwargs } raise exceptions.NotFound(404, msg) elif num > 1: raise exceptions.NoUniqueMatch else: return rl[0]
Example #4
Source File: models.py From coursys with GNU General Public License v3.0 | 6 votes |
def totpauth_url(totp_dev): # https://github.com/google/google-authenticator/wiki/Key-Uri-Format label = totp_dev.user.username.encode('utf8') # We need two separate issuers, otherwise deploying in prod will override our authenticator token from # dev if settings.DEPLOY_MODE == 'production': issuer = b'CourSys' else: issuer = b'CourSys-DEV' query = [ ('secret', base64.b32encode(totp_dev.bin_key)), ('digits', totp_dev.digits), ('issuer', issuer) ] return b'otpauth://totp/%s?%s' % (label, urlencode(query).encode('ascii')) # based on http://stackoverflow.com/a/4631504/1236542
Example #5
Source File: codec.py From pwnypack with MIT License | 6 votes |
def enurlform(q): """ Convert a dictionary to a URL encoded query string. Args: q(dict): The query to encode. Returns: str: The urlencoded representation of ``q``. Example: >>> from pwny import * >>> enurlform({'foo': 'bar', 'baz': ['quux', 'corge']}) 'foo=bar&baz=quux&baz=corge' """ return urlencode(q, doseq=True)
Example #6
Source File: usages.py From eclcli with Apache License 2.0 | 6 votes |
def get_histories(self, usage, search_opts=None): if search_opts is None: search_opts = {} qparams = {} for opt, val in six.iteritems(search_opts): if val: qparams[opt] = val # Transform the dict to a sequence of two-element tuples in fixed # order, then the encoded string will be consistent in Python 2&3. if qparams: items = list(qparams.items()) new_qparams = sorted(items, key=lambda x: x[0]) query_string = "?%s" % parse.urlencode(new_qparams) else: query_string = "" return self._get_histories("/usages/%s/histories%s" % (usage, query_string), "histories")
Example #7
Source File: usages.py From eclcli with Apache License 2.0 | 6 votes |
def list(self, search_opts=None): if search_opts is None: search_opts = {} qparams = {} for opt, val in six.iteritems(search_opts): if val: qparams[opt] = val # Transform the dict to a sequence of two-element tuples in fixed # order, then the encoded string will be consistent in Python 2&3. if qparams: items = list(qparams.items()) new_qparams = sorted(items, key=lambda x: x[0]) query_string = "?%s" % parse.urlencode(new_qparams) else: query_string = "" return self._list("/usages%s" % query_string, "usages")
Example #8
Source File: tableau.py From luigi-td with Apache License 2.0 | 6 votes |
def get_result_url(self): reqs = {} for name in ['server', 'username', 'password', 'datasource']: if getattr(self, name) is None: raise TypeError('missing option "{0}" for {1}'.format(name, self)) reqs[name] = url_quote(getattr(self, name)) params = { 'ssl': self.ssl, 'ssl_verify': self.ssl_verify, 'server_version': self.server_version, 'site': self.site, 'project': self.project, 'mode': self.mode, } reqs['params'] = urlencode([(key, params[key]) for key in params if params[key] is not None]) return "tableau://{username}:{password}@{server}/{datasource}?{params}".format(**reqs)
Example #9
Source File: licenses.py From eclcli with Apache License 2.0 | 6 votes |
def list(self, search_opts=None): if search_opts is None: search_opts = {} qparams = {} for opt, val in six.iteritems(search_opts): if val: qparams[opt] = val # Transform the dict to a sequence of two-element tuples in fixed # order, then the encoded string will be consistent in Python 2&3. if qparams: new_qparams = sorted(qparams.items(), key=lambda x: x[0]) query_string = "?%s" % urlencode(new_qparams) else: query_string = "" return self._list("/licenses%s" % query_string, "licenses") # def get(self, license): # return self._get("/licenses/%s" % getid(license), "license")
Example #10
Source File: base.py From eclcli with Apache License 2.0 | 6 votes |
def find(self, base_url=None, **kwargs): """Find a single item with attributes matching ``**kwargs``. :param base_url: if provided, the generated URL will be appended to it """ kwargs = self._filter_kwargs(kwargs) rl = self._list( '%(base_url)s%(query)s' % { 'base_url': self.build_url(base_url=base_url, **kwargs), 'query': '?%s' % parse.urlencode(kwargs) if kwargs else '', }, self.collection_key) num = len(rl) if num == 0: msg = _("No %(name)s matching %(args)s.") % { 'name': self.resource_class.__name__, 'args': kwargs } raise exceptions.NotFound(404, msg) elif num > 1: raise exceptions.NoUniqueMatch else: return rl[0]
Example #11
Source File: software_configs.py From eclcli with Apache License 2.0 | 6 votes |
def list(self, **kwargs): """Get a list of software configs. :rtype: list of :class:`SoftwareConfig` """ qparams = {} for opt, val in six.iteritems(kwargs): if val: qparams[opt] = val # Transform the dict to a sequence of two-element tuples in fixed # order, then the encoded string will be consistent in Python 2&3. if qparams: new_qparams = sorted(qparams.items(), key=lambda x: x[0]) query_string = "?%s" % parse.urlencode(new_qparams) else: query_string = "" url = '/software_configs%s' % query_string return self._list(url, "software_configs")
Example #12
Source File: google.py From icrawler with MIT License | 6 votes |
def feed(self, keyword, offset, max_num, language=None, filters=None): base_url = 'https://www.google.com/search?' self.filter = self.get_filter() filter_str = self.filter.apply(filters, sep=',') for i in range(offset, offset + max_num, 100): params = dict( q=keyword, ijn=int(i / 100), start=i, tbs=filter_str, tbm='isch') if language: params['lr'] = 'lang_' + language url = base_url + urlencode(params) self.out_queue.put(url) self.logger.debug('put url to url_queue: {}'.format(url))
Example #13
Source File: base.py From eclcli with Apache License 2.0 | 6 votes |
def find(self, base_url=None, **kwargs): """Find a single item with attributes matching ``**kwargs``. :param base_url: if provided, the generated URL will be appended to it """ kwargs = self._filter_kwargs(kwargs) rl = self._list( '%(base_url)s%(query)s' % { 'base_url': self.build_url(base_url=base_url, **kwargs), 'query': '?%s' % parse.urlencode(kwargs) if kwargs else '', }, self.collection_key) num = len(rl) if num == 0: msg = _("No %(name)s matching %(args)s.") % { 'name': self.resource_class.__name__, 'args': kwargs } raise exceptions.NotFound(404, msg) elif num > 1: raise exceptions.NoUniqueMatch else: return rl[0]
Example #14
Source File: images_client.py From tempest-lib with Apache License 2.0 | 6 votes |
def list_images(self, detail=False, **params): """Return a list of all images filtered by any parameter. Available params: see http://developer.openstack.org/ api-ref-compute-v2.1.html#listImages """ url = 'images' _schema = schema.list_images if detail: url += '/detail' _schema = schema.list_images_details if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(_schema, resp, body) return rest_client.ResponseBody(resp, body)
Example #15
Source File: api.py From django-payfast with MIT License | 6 votes |
def _sign_fields(signable_fields): # type: (SignableFields) -> str """ Common signing code. """ for (k, v) in signable_fields: assert isinstance(k, str), repr(k) assert isinstance(v, str), repr(v) if sys.version_info < (3,): # Python 2 doesn't do IRI encoding. text = urlencode([ (k.encode('utf-8'), v.encode('utf-8')) for (k, v) in signable_fields ]) else: text = urlencode(signable_fields, encoding='utf-8', errors='strict') return md5(text.encode('ascii')).hexdigest() #: The checkout signature should ignore these leading and trailing whitespace characters. #: #: This list is an educated guess based on the PHP trim() function. #:
Example #16
Source File: connector.py From designate with Apache License 2.0 | 6 votes |
def _construct_url(self, relative_path, query_params=None, extattrs=None): if query_params is None: query_params = {} if extattrs is None: extattrs = {} if not relative_path or relative_path[0] == '/': raise ValueError('Path in request must be relative.') query = '' if query_params or extattrs: query = '?' if extattrs: attrs_queries = [] for key, value in extattrs.items(): LOG.debug("key: %s, value: %s", key, value) attrs_queries.append('*' + key + '=' + value['value']) query += '&'.join(attrs_queries) if query_params: if len(query) > 1: query += '&' query += parse.urlencode(query_params) baseurl = parse.urljoin(self.wapi_url, parse.quote(relative_path)) return baseurl + query
Example #17
Source File: consumer.py From xblock-lti-consumer with GNU Affero General Public License v3.0 | 6 votes |
def prepare_preflight_url( self, callback_url, hint="hint", lti_hint="lti_hint" ): """ Generates OIDC url with parameters """ oidc_url = self.oidc_url + "?" parameters = { "iss": self.iss, "client_id": self.client_id, "lti_deployment_id": self.deployment_id, "target_link_uri": callback_url, "login_hint": hint, "lti_message_hint": lti_hint } return { "oidc_url": oidc_url + urlencode(parameters), }
Example #18
Source File: SCIMIdResolver.py From privacyidea with GNU Affero General Public License v3.0 | 6 votes |
def _search_users(resource_server, access_token, params=None): """ :param params: Additional http parameters added to the URL :type params: dictionary """ params = params or {} headers = {'Authorization': "Bearer {0}".format(access_token), 'content-type': 'application/json'} url = '{0}/Users?{1}'.format(resource_server, urlencode(params)) resp = requests.get(url, headers=headers) if resp.status_code != 200: info = "Could not get user list: {0!s}".format(resp.status_code) log.error(info) raise Exception(info) j_content = yaml.safe_load(resp.content) return j_content
Example #19
Source File: test_api_token.py From privacyidea with GNU Affero General Public License v3.0 | 6 votes |
def test_10_set_token_realms(self): self._create_temp_token("REALM001") with self.app.test_request_context('/token/realm/REALM001', method="POST", data={"realms": "realm1, realm2"}, headers={'Authorization': self.at}): res = self.app.full_dispatch_request() self.assertTrue(res.status_code == 200, res) result = res.json.get("result") value = result.get("value") self.assertTrue(value is True, result) with self.app.test_request_context('/token/', method="GET", query_string=urlencode({"serial": "REALM001"}), headers={'Authorization': self.at}): res = self.app.full_dispatch_request() self.assertTrue(res.status_code == 200, res) result = res.json.get("result") value = result.get("value") token = value.get("tokens")[0] self.assertTrue(token.get("realms") == ["realm1"], token)
Example #20
Source File: utils.py From oss-ftp with MIT License | 6 votes |
def _generate_uri(hotp, type_name, account_name, issuer, extra_parameters): parameters = [ ("digits", hotp._length), ("secret", base64.b32encode(hotp._key)), ("algorithm", hotp._algorithm.name.upper()), ] if issuer is not None: parameters.append(("issuer", issuer)) parameters.extend(extra_parameters) uriparts = { "type": type_name, "label": ("%s:%s" % (quote(issuer), quote(account_name)) if issuer else quote(account_name)), "parameters": urlencode(parameters), } return "otpauth://{type}/{label}?{parameters}".format(**uriparts)
Example #21
Source File: utils.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
def _generate_uri(hotp, type_name, account_name, issuer, extra_parameters): parameters = [ ("digits", hotp._length), ("secret", base64.b32encode(hotp._key)), ("algorithm", hotp._algorithm.name.upper()), ] if issuer is not None: parameters.append(("issuer", issuer)) parameters.extend(extra_parameters) uriparts = { "type": type_name, "label": ("%s:%s" % (quote(issuer), quote(account_name)) if issuer else quote(account_name)), "parameters": urlencode(parameters), } return "otpauth://{type}/{label}?{parameters}".format(**uriparts)
Example #22
Source File: utils.py From teleport with Apache License 2.0 | 6 votes |
def _generate_uri(hotp, type_name, account_name, issuer, extra_parameters): parameters = [ ("digits", hotp._length), ("secret", base64.b32encode(hotp._key)), ("algorithm", hotp._algorithm.name.upper()), ] if issuer is not None: parameters.append(("issuer", issuer)) parameters.extend(extra_parameters) uriparts = { "type": type_name, "label": ("%s:%s" % (quote(issuer), quote(account_name)) if issuer else quote(account_name)), "parameters": urlencode(parameters), } return "otpauth://{type}/{label}?{parameters}".format(**uriparts)
Example #23
Source File: utils.py From teleport with Apache License 2.0 | 6 votes |
def _generate_uri(hotp, type_name, account_name, issuer, extra_parameters): parameters = [ ("digits", hotp._length), ("secret", base64.b32encode(hotp._key)), ("algorithm", hotp._algorithm.name.upper()), ] if issuer is not None: parameters.append(("issuer", issuer)) parameters.extend(extra_parameters) uriparts = { "type": type_name, "label": ("%s:%s" % (quote(issuer), quote(account_name)) if issuer else quote(account_name)), "parameters": urlencode(parameters), } return "otpauth://{type}/{label}?{parameters}".format(**uriparts)
Example #24
Source File: utils.py From teleport with Apache License 2.0 | 6 votes |
def _generate_uri(hotp, type_name, account_name, issuer, extra_parameters): parameters = [ ("digits", hotp._length), ("secret", base64.b32encode(hotp._key)), ("algorithm", hotp._algorithm.name.upper()), ] if issuer is not None: parameters.append(("issuer", issuer)) parameters.extend(extra_parameters) uriparts = { "type": type_name, "label": ("%s:%s" % (quote(issuer), quote(account_name)) if issuer else quote(account_name)), "parameters": urlencode(parameters), } return "otpauth://{type}/{label}?{parameters}".format(**uriparts)
Example #25
Source File: niji_tags.py From niji with MIT License | 6 votes |
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
Example #26
Source File: servers_client.py From tempest-lib with Apache License 2.0 | 6 votes |
def list_servers(self, detail=False, **params): """List servers. Available params: see http://developer.openstack.org/ api-ref-compute-v2.1.html#listServers and http://developer.openstack.org/ api-ref-compute-v2.1.html#listDetailServers """ url = 'servers' _schema = schema.list_servers if detail: url += '/detail' _schema = schema.list_servers_detail if params: url += '?%s' % urllib.urlencode(params) resp, body = self.get(url) body = json.loads(body) self.validate_response(_schema, resp, body) return rest_client.ResponseBody(resp, body)
Example #27
Source File: core.py From osbs-client with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _build_k8s_url(self, url, _prepend_namespace=True, **query): if _prepend_namespace: url = "namespaces/%s/%s" % (self.namespace, url) if query: url += ("?" + urlencode(query)) return urljoin(self.k8s_api_url, url)
Example #28
Source File: resource_types.py From eclcli with Apache License 2.0 | 5 votes |
def list(self, **kwargs): """Get a list of resource types. :rtype: list of :class:`ResourceType` """ url = '/%s' % self.KEY params = {} if 'filters' in kwargs: filters = kwargs.pop('filters') params.update(filters) url += '?%s' % parse.urlencode(params, True) return self._list(url, self.KEY)
Example #29
Source File: resource_types.py From eclcli with Apache License 2.0 | 5 votes |
def generate_template(self, resource_type, template_type='cfn'): url_str = '/%s/%s/template' % ( self.KEY, parse.quote(encodeutils.safe_encode(resource_type), '')) if template_type: url_str += '?%s' % parse.urlencode( {'template_type': template_type}, True) resp = self.client.get(url_str) body = utils.get_response_body(resp) return body
Example #30
Source File: base.py From designate with Apache License 2.0 | 5 votes |
def _get_collection_href(self, request, parents=None, extra_params=None): params = request.GET if extra_params is not None: params.update(extra_params) base_href = self._get_base_href(parents) href = "%s?%s" % (base_href, parse.urlencode(params)) return href.rstrip('?')