Python urllib.parse.quote_plus() Examples
The following are 30
code examples of urllib.parse.quote_plus().
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
urllib.parse
, or try the search function
.
Example #1
Source File: replicaclient.py From rucio with Apache License 2.0 | 6 votes |
def list_dataset_replicas(self, scope, name, deep=False): """ List dataset replicas for a did (scope:name). :param scope: The scope of the dataset. :param name: The name of the dataset. :param deep: Lookup at the file level. :returns: A list of dict dataset replicas. """ payload = {} if deep: payload = {'deep': True} url = build_url(self.host, path='/'.join([self.REPLICAS_BASEURL, quote_plus(scope), quote_plus(name), 'datasets']), params=payload) r = self._send_request(url, type='GET') if r.status_code == codes.ok: return self._load_json_data(r) exc_cls, exc_msg = self._get_exception(headers=r.headers, status_code=r.status_code, data=r.content) raise exc_cls(exc_msg)
Example #2
Source File: didclient.py From rucio with Apache License 2.0 | 6 votes |
def delete_did_meta(self, scope, name, key): """ Delete a key from the metadata column :param scope: the scope of did :param name: the name of the did :param key: the key to be deleted """ path = '/'.join([self.DIDS_BASEURL, quote_plus(scope), quote_plus(name), 'did_meta']) url = build_url(choice(self.list_hosts), path=path, params={'key': key}) r = self._send_request(url, type='DEL') if r.status_code == codes.ok: print(r.text) return True else: exc_cls, exc_msg = self._get_exception(headers=r.headers, status_code=r.status_code, data=r.content) raise exc_cls(exc_msg)
Example #3
Source File: test_azure_iothub_receive.py From azure-uamqp-python with MIT License | 6 votes |
def generate_sas_token(self): """ Create a shared access signiture token as a string literal. Returns: result (str): SAS token as string literal. """ encoded_uri = quote_plus(self.uri) ttl = int(self.expiry) sign_key = '%s\n%d' % (encoded_uri, ttl) signature = b64encode(HMAC(b64decode(self.key), sign_key.encode('utf-8'), sha256).digest()) result = { 'sr': self.uri, 'sig': signature, 'se': str(ttl) } if self.policy: result['skn'] = self.policy return 'SharedAccessSignature ' + urlencode(result)
Example #4
Source File: tests_views.py From koku with GNU Affero General Public License v3.0 | 6 votes |
def test_metric_map_values(self): """ Test contents of the metrics. Test that the COST_MODEL_METRIC_MAP constant is properly formatted and contains the required data. """ url = reverse("metrics") client = APIClient() params = {"source_type": Provider.PROVIDER_OCP} url = url + "?" + urlencode(params, quote_via=quote_plus) response = client.get(url, **self.headers).data["data"] self.assertEquals(len(COST_MODEL_METRIC_MAP), len(response)) for metric in COST_MODEL_METRIC_MAP: self.assertIsNotNone(metric.get("source_type")) self.assertIsNotNone(metric.get("metric")) self.assertIsNotNone(metric.get("label_metric")) self.assertIsNotNone(metric.get("label_measurement_unit")) self.assertIsNotNone(metric.get("default_cost_type"))
Example #5
Source File: metaclient.py From rucio with Apache License 2.0 | 6 votes |
def add_value(self, key, value): """ Sends the request to add a value to a key. :param key: the name for key. :param value: the value. :return: True if value was created successfully. :raises Duplicate: if valid already exists. """ path = '/'.join([self.META_BASEURL, quote_plus(key)]) + '/' data = dumps({'value': value}) url = build_url(choice(self.list_hosts), path=path) r = self._send_request(url, type='POST', data=data) if r.status_code == codes.created: return True else: exc_cls, exc_msg = self._get_exception(headers=r.headers, status_code=r.status_code, data=r.content) raise exc_cls(exc_msg)
Example #6
Source File: tests_views.py From koku with GNU Affero General Public License v3.0 | 6 votes |
def test_execute_query_ocp_aws_storage_last_thirty_days(self): """Test that OCP CPU endpoint works.""" url = reverse("reports-openshift-aws-storage") client = APIClient() params = {"filter[time_scope_value]": "-30", "filter[time_scope_units]": "day", "filter[resolution]": "daily"} url = url + "?" + urlencode(params, quote_via=quote_plus) response = client.get(url, **self.headers) expected_end_date = self.dh.today expected_start_date = self.dh.n_days_ago(expected_end_date, 29) expected_end_date = str(expected_end_date.date()) expected_start_date = str(expected_start_date.date()) self.assertEqual(response.status_code, status.HTTP_200_OK) data = response.json() dates = sorted([item.get("date") for item in data.get("data")]) self.assertEqual(dates[0], expected_start_date) self.assertEqual(dates[-1], expected_end_date) for item in data.get("data"): if item.get("values"): values = item.get("values")[0] self.assertTrue("usage" in values) self.assertTrue("cost" in values)
Example #7
Source File: tests_views.py From koku with GNU Affero General Public License v3.0 | 6 votes |
def test_execute_query_ocp_aws_storage_this_month(self): """Test that data is returned for the full month.""" url = reverse("reports-openshift-aws-storage") client = APIClient() params = { "filter[resolution]": "monthly", "filter[time_scope_value]": "-1", "filter[time_scope_units]": "month", } url = url + "?" + urlencode(params, quote_via=quote_plus) response = client.get(url, **self.headers) expected_date = self.dh.today.strftime("%Y-%m") self.assertEqual(response.status_code, status.HTTP_200_OK) data = response.json() dates = sorted([item.get("date") for item in data.get("data")]) self.assertEqual(dates[0], expected_date) self.assertNotEqual(data.get("data")[0].get("values", []), []) values = data.get("data")[0].get("values")[0] self.assertTrue("usage" in values) self.assertTrue("cost" in values)
Example #8
Source File: tests_views.py From koku with GNU Affero General Public License v3.0 | 6 votes |
def test_execute_query_ocp_aws_storage_this_month_daily(self): """Test that data is returned for the full month.""" url = reverse("reports-openshift-aws-storage") client = APIClient() params = {"filter[resolution]": "daily", "filter[time_scope_value]": "-1", "filter[time_scope_units]": "month"} url = url + "?" + urlencode(params, quote_via=quote_plus) response = client.get(url, **self.headers) expected_start_date = self.dh.this_month_start.strftime("%Y-%m-%d") expected_end_date = self.dh.today.strftime("%Y-%m-%d") self.assertEqual(response.status_code, status.HTTP_200_OK) data = response.json() dates = sorted([item.get("date") for item in data.get("data")]) self.assertEqual(dates[0], expected_start_date) self.assertEqual(dates[-1], expected_end_date) for item in data.get("data"): if item.get("values"): values = item.get("values")[0] self.assertTrue("usage" in values) self.assertTrue("cost" in values)
Example #9
Source File: test_register.py From django-rest-registration with MIT License | 6 votes |
def build_custom_verification_url(signer): base_url = signer.get_base_url() signed_data = signer.get_signed_data() if signer.USE_TIMESTAMP: timestamp = signed_data.pop(signer.TIMESTAMP_FIELD) else: timestamp = None signature = signed_data.pop(signer.SIGNATURE_FIELD) segments = [signed_data[k] for k in sorted(signed_data.keys())] segments.append(signature) if timestamp: segments.append(timestamp) quoted_segments = [urlquote(str(s)) for s in segments] url = base_url if not url.endswith('/'): url += '/' url += '/'.join(quoted_segments) url += '/' if signer.request: url = signer.request.build_absolute_uri(url) return url
Example #10
Source File: tests_views.py From koku with GNU Affero General Public License v3.0 | 6 votes |
def test_execute_query_ocp_aws_storage_last_month(self): """Test that data is returned for the last month.""" url = reverse("reports-openshift-aws-storage") client = APIClient() params = { "filter[resolution]": "monthly", "filter[time_scope_value]": "-2", "filter[time_scope_units]": "month", } url = url + "?" + urlencode(params, quote_via=quote_plus) response = client.get(url, **self.headers) expected_date = self.dh.last_month_start.strftime("%Y-%m") self.assertEqual(response.status_code, status.HTTP_200_OK) data = response.json() dates = sorted([item.get("date") for item in data.get("data")]) self.assertEqual(dates[0], expected_date) self.assertIsNotNone(data.get("data")[0].get("values")) self.assertNotEqual(data.get("data")[0].get("values"), []) values = data.get("data")[0].get("values")[0] self.assertTrue("usage" in values) self.assertTrue("cost" in values)
Example #11
Source File: response.py From sanic with MIT License | 6 votes |
def redirect( to, headers=None, status=302, content_type="text/html; charset=utf-8" ): """Abort execution and cause a 302 redirect (by default). :param to: path or fully qualified URL to redirect to :param headers: optional dict of headers to include in the new request :param status: status code (int) of the new request, defaults to 302 :param content_type: the content type (string) of the response :returns: the redirecting Response """ headers = headers or {} # URL Quote the URL before redirecting safe_to = quote_plus(to, safe=":/%#?&=@[]!$&'()*+,;") # According to RFC 7231, a relative URI is now permitted. headers["Location"] = safe_to return HTTPResponse( status=status, headers=headers, content_type=content_type )
Example #12
Source File: test_magnet.py From torf with GNU General Public License v3.0 | 6 votes |
def test_from_torrent_with_multiple_trackers(singlefile_content, multifile_content): for content in singlefile_content, multifile_content: t = torf.Torrent(content.path, trackers=['http://foo', 'http://bar']) t.generate() assert str(t.magnet()) == (f'magnet:?xt=urn:btih:{t.infohash}' f'&dn={quote_plus(t.name)}' f'&xl={t.size}' f'&tr=http%3A%2F%2Ffoo&tr=http%3A%2F%2Fbar') assert str(t.magnet(tracker=True, trackers=False)) == (f'magnet:?xt=urn:btih:{t.infohash}' f'&dn={quote_plus(t.name)}' f'&xl={t.size}' f'&tr=http%3A%2F%2Ffoo') assert str(t.magnet(tracker=False, trackers=False)) == (f'magnet:?xt=urn:btih:{t.infohash}' f'&dn={quote_plus(t.name)}' f'&xl={t.size}') assert str(t.magnet(tracker=True, trackers=True)) == (f'magnet:?xt=urn:btih:{t.infohash}' f'&dn={quote_plus(t.name)}' f'&xl={t.size}' f'&tr=http%3A%2F%2Ffoo') assert str(t.magnet(tracker=False, trackers=True)) == (f'magnet:?xt=urn:btih:{t.infohash}' f'&dn={quote_plus(t.name)}' f'&xl={t.size}' f'&tr=http%3A%2F%2Ffoo&tr=http%3A%2F%2Fbar')
Example #13
Source File: requestclient.py From rucio with Apache License 2.0 | 6 votes |
def list_request_by_did(self, name, rse, scope=None): """Return latest request details for a DID :param name: DID :type name: str :param rse: Destination RSE name :type rse: str :param scope: rucio scope, defaults to None :param scope: str, optional :raises exc_cls: from BaseClient._get_exception :return: request information :rtype: dict """ path = '/'.join(['requests', quote_plus(scope), quote_plus(name), rse]) url = build_url(choice(self.list_hosts), path=path) r = self._send_request(url, type='GET') if r.status_code == codes.ok: return next(self._load_json_data(r)) else: exc_cls, exc_msg = self._get_exception(headers=r.headers, status_code=r.status_code, data=r.content) raise exc_cls(exc_msg)
Example #14
Source File: scopeclient.py From rucio with Apache License 2.0 | 6 votes |
def add_scope(self, account, scope): """ Sends the request to add a new scope. :param account: the name of the account to add the scope to. :param scope: the name of the new scope. :return: True if scope was created successfully. :raises Duplicate: if scope already exists. :raises AccountNotFound: if account doesn't exist. """ path = '/'.join([self.SCOPE_BASEURL, account, 'scopes', quote_plus(scope)]) url = build_url(choice(self.list_hosts), path=path) r = self._send_request(url, type='POST') if r.status_code == codes.created: return True else: exc_cls, exc_msg = self._get_exception(headers=r.headers, status_code=r.status_code, data=r.content) raise exc_cls(exc_msg)
Example #15
Source File: fileclient.py From rucio with Apache License 2.0 | 6 votes |
def list_file_replicas(self, scope, lfn): """ List file replicas. :param scope: the scope. :param lfn: the lfn. :return: List of replicas. """ path = '/'.join([self.BASEURL, quote_plus(scope), quote_plus(lfn), 'rses']) url = build_url(choice(self.list_hosts), path=path) r = self._send_request(url, type='GET') if r.status_code == codes.ok: rses = loads(r.text) return rses else: print(r.status_code) exc_cls, exc_msg = self._get_exception(headers=r.headers, status_code=r.status_code, data=r.content) raise exc_cls(exc_msg)
Example #16
Source File: test_magnet.py From torf with GNU General Public License v3.0 | 6 votes |
def test_from_torrent_with_single_tracker(singlefile_content, multifile_content): for content in singlefile_content, multifile_content: t = torf.Torrent(content.path, trackers=['http://foo']) t.generate() assert str(t.magnet()) == (f'magnet:?xt=urn:btih:{t.infohash}' f'&dn={quote_plus(t.name)}' f'&xl={t.size}' f'&tr=http%3A%2F%2Ffoo') assert str(t.magnet(tracker=True, trackers=False)) == (f'magnet:?xt=urn:btih:{t.infohash}' f'&dn={quote_plus(t.name)}' f'&xl={t.size}' f'&tr=http%3A%2F%2Ffoo') assert str(t.magnet(tracker=False, trackers=False)) == (f'magnet:?xt=urn:btih:{t.infohash}' f'&dn={quote_plus(t.name)}' f'&xl={t.size}') assert str(t.magnet(tracker=True, trackers=True)) == (f'magnet:?xt=urn:btih:{t.infohash}' f'&dn={quote_plus(t.name)}' f'&xl={t.size}' f'&tr=http%3A%2F%2Ffoo') assert str(t.magnet(tracker=False, trackers=True)) == (f'magnet:?xt=urn:btih:{t.infohash}' f'&dn={quote_plus(t.name)}' f'&xl={t.size}' f'&tr=http%3A%2F%2Ffoo')
Example #17
Source File: replicaclient.py From rucio with Apache License 2.0 | 6 votes |
def list_dataset_replicas_vp(self, scope, name, deep=False): """ List dataset replicas for a DID (scope:name) using the Virtual Placement service. NOTICE: This is an RnD function and might change or go away at any time. :param scope: The scope of the dataset. :param name: The name of the dataset. :param deep: Lookup at the file level. :returns: If VP exists a list of dicts of sites """ payload = {} if deep: payload = {'deep': True} url = build_url(self.host, path='/'.join([self.REPLICAS_BASEURL, quote_plus(scope), quote_plus(name), 'datasets_vp']), params=payload) r = self._send_request(url, type='GET') if r.status_code == codes.ok: return self._load_json_data(r) exc_cls, exc_msg = self._get_exception(headers=r.headers, status_code=r.status_code, data=r.content) raise exc_cls(exc_msg)
Example #18
Source File: accountlimitclient.py From rucio with Apache License 2.0 | 6 votes |
def delete_global_account_limit(self, account, rse_expression): """ Sends the request to remove a global account limit. :param account: The name of the account. :param rse_expression: The rse expression. :return: True if quota was removed successfully. False otherwise. :raises AccountNotFound: if account doesn't exist. """ path = '/'.join([self.ACCOUNTLIMIT_BASEURL, 'global', account, quote_plus(rse_expression)]) url = build_url(choice(self.list_hosts), path=path) r = self._send_request(url, type='DEL') if r.status_code == codes.ok: return True else: exc_cls, exc_msg = self._get_exception(headers=r.headers, status_code=r.status_code, data=r.content) raise exc_cls(exc_msg)
Example #19
Source File: didclient.py From rucio with Apache License 2.0 | 6 votes |
def add_did_meta(self, scope, name, meta): """ Insert metadata to the json column of a did, updates key if already present :param scope: the scope of did :param name: the name of the did :param meta: the metadata to be inserted or updated(in json format) """ path = '/'.join([self.DIDS_BASEURL, quote_plus(scope), quote_plus(name), 'did_meta']) url = build_url(choice(self.list_hosts), path=path) data = dumps(meta) r = self._send_request(url, type='POST', data=data) if r.status_code == codes.created: return True else: exc_cls, exc_msg = self._get_exception(headers=r.headers, status_code=r.status_code, data=r.content) raise exc_cls(exc_msg)
Example #20
Source File: accountclient.py From rucio with Apache License 2.0 | 6 votes |
def get_global_account_usage(self, account, rse_expression=None): """ List the account usage for one or all RSE expressions of this account. :param account: The account name. :param rse_expression: The rse expression. """ if rse_expression: path = '/'.join([self.ACCOUNTS_BASEURL, account, 'usage', 'global', quote_plus(rse_expression)]) else: path = '/'.join([self.ACCOUNTS_BASEURL, account, 'usage', 'global']) url = build_url(choice(self.list_hosts), path=path) res = self._send_request(url, type='GET') if res.status_code == codes.ok: return self._load_json_data(res) else: exc_cls, exc_msg = self._get_exception(headers=res.headers, status_code=res.status_code, data=res.content) raise exc_cls(exc_msg)
Example #21
Source File: didclient.py From rucio with Apache License 2.0 | 6 votes |
def create_did_sample(self, input_scope, input_name, output_scope, output_name, nbfiles): """ Create a sample from an input collection. :param input_scope: The scope of the input DID. :param input_name: The name of the input DID. :param output_scope: The scope of the output dataset. :param output_name: The name of the output dataset. :param account: The account. :param nbfiles: The number of files to register in the output dataset. """ path = '/'.join([self.DIDS_BASEURL, quote_plus(input_scope), quote_plus(input_name), quote_plus(output_scope), quote_plus(output_name), str(nbfiles), 'sample']) url = build_url(choice(self.list_hosts), path=path) r = self._send_request(url, type='POST', data=dumps({})) if r.status_code == codes.created: return True else: exc_cls, exc_msg = self._get_exception(headers=r.headers, status_code=r.status_code, data=r.content) raise exc_cls(exc_msg)
Example #22
Source File: didclient.py From rucio with Apache License 2.0 | 6 votes |
def detach_dids(self, scope, name, dids): """ Detach data identifier :param scope: The scope name. :param name: The data identifier name. :param dids: The content. """ path = '/'.join([self.DIDS_BASEURL, quote_plus(scope), quote_plus(name), 'dids']) url = build_url(choice(self.list_hosts), path=path) data = {'dids': dids} r = self._send_request(url, type='DEL', data=render_json(**data)) if r.status_code == codes.ok: return True exc_cls, exc_msg = self._get_exception(headers=r.headers, status_code=r.status_code, data=r.content) raise exc_cls(exc_msg)
Example #23
Source File: didclient.py From rucio with Apache License 2.0 | 6 votes |
def list_parent_dids(self, scope, name): """ List parent dataset/containers of a did. :param scope: The scope. :param name: The name. """ path = '/'.join([self.DIDS_BASEURL, quote_plus(scope), quote_plus(name), 'parents']) url = build_url(choice(self.list_hosts), path=path) r = self._send_request(url, type='GET') if r.status_code == codes.ok: return self._load_json_data(r) else: exc_cls, exc_msg = self._get_exception(headers=r.headers, status_code=r.status_code, data=r.content) raise exc_cls(exc_msg)
Example #24
Source File: didclient.py From rucio with Apache License 2.0 | 6 votes |
def list_associated_rules_for_file(self, scope, name): """ List the associated rules a file is affected from.. :param scope: The scope name. :param name: The file name. """ path = '/'.join([self.DIDS_BASEURL, quote_plus(scope), quote_plus(name), 'associated_rules']) url = build_url(choice(self.list_hosts), path=path) r = self._send_request(url, type='GET') if r.status_code == codes.ok: return self._load_json_data(r) else: exc_cls, exc_msg = self._get_exception(headers=r.headers, status_code=r.status_code, data=r.content) raise exc_cls(exc_msg)
Example #25
Source File: didclient.py From rucio with Apache License 2.0 | 6 votes |
def list_files(self, scope, name, long=None): """ List data identifier file contents. :param scope: The scope name. :param name: The data identifier name. :param long: A boolean to choose if GUID is returned or not. """ payload = {} path = '/'.join([self.DIDS_BASEURL, quote_plus(scope), quote_plus(name), 'files']) if long: payload['long'] = True url = build_url(choice(self.list_hosts), path=path, params=payload) r = self._send_request(url, type='GET') if r.status_code == codes.ok: return self._load_json_data(r) else: exc_cls, exc_msg = self._get_exception(headers=r.headers, status_code=r.status_code, data=r.content) raise exc_cls(exc_msg)
Example #26
Source File: didclient.py From rucio with Apache License 2.0 | 6 votes |
def get_did(self, scope, name, dynamic=False): """ Retrieve a single data identifier. :param scope: The scope name. :param name: The data identifier name. :param dynamic: Calculate sizes dynamically when True """ path = '/'.join([self.DIDS_BASEURL, quote_plus(scope), quote_plus(name)]) if dynamic: path += '?dynamic=True' url = build_url(choice(self.list_hosts), path=path) r = self._send_request(url, type='GET') if r.status_code == codes.ok: return next(self._load_json_data(r)) else: exc_cls, exc_msg = self._get_exception(headers=r.headers, status_code=r.status_code, data=r.content) raise exc_cls(exc_msg)
Example #27
Source File: didclient.py From rucio with Apache License 2.0 | 6 votes |
def set_metadata(self, scope, name, key, value, recursive=False): """ Set data identifier metadata :param scope: The scope name. :param name: The data identifier name. :param key: the key. :param value: the value. :param recursive: Option to propagate the metadata change to content. """ path = '/'.join([self.DIDS_BASEURL, quote_plus(scope), quote_plus(name), 'meta', key]) url = build_url(choice(self.list_hosts), path=path) data = dumps({'value': value, 'recursive': recursive}) r = self._send_request(url, type='POST', data=data) if r.status_code == codes.created: return True else: exc_cls, exc_msg = self._get_exception(headers=r.headers, status_code=r.status_code, data=r.content) raise exc_cls(exc_msg)
Example #28
Source File: didclient.py From rucio with Apache License 2.0 | 6 votes |
def set_status(self, scope, name, **kwargs): """ Set data identifier status :param scope: The scope name. :param name: The data identifier name. :param kwargs: Keyword arguments of the form status_name=value. """ path = '/'.join([self.DIDS_BASEURL, quote_plus(scope), quote_plus(name), 'status']) url = build_url(choice(self.list_hosts), path=path) data = dumps(kwargs) r = self._send_request(url, type='PUT', data=data) if r.status_code in (codes.ok, codes.no_content, codes.created): return True exc_cls, exc_msg = self._get_exception(headers=r.headers, status_code=r.status_code, data=r.content) raise exc_cls(exc_msg)
Example #29
Source File: didclient.py From rucio with Apache License 2.0 | 6 votes |
def delete_metadata(self, scope, name, key): """ Delete data identifier metadata :param scope: The scope name. :param name: The data identifier. :param key: the key. """ path = '/'.join([self.DIDS_BASEURL, quote_plus(scope), quote_plus(name), 'meta', key]) url = build_url(choice(self.list_hosts), path=path) r = self._send_request(url, type='DEL') if r.status_code == codes.ok: return True else: exc_cls, exc_msg = self._get_exception(headers=r.headers, status_code=r.status_code, data=r.content) raise exc_cls(exc_msg)
Example #30
Source File: didclient.py From rucio with Apache License 2.0 | 6 votes |
def list_did_rules(self, scope, name): """ List the associated rules of a data identifier. :param scope: The scope name. :param name: The data identifier name. """ path = '/'.join([self.DIDS_BASEURL, quote_plus(scope), quote_plus(name), 'rules']) url = build_url(choice(self.list_hosts), path=path) r = self._send_request(url, type='GET') if r.status_code == codes.ok: return self._load_json_data(r) else: exc_cls, exc_msg = self._get_exception(headers=r.headers, status_code=r.status_code, data=r.content) raise exc_cls(exc_msg)