本文整理汇总了Python中urllib.parse.quote_plus方法的典型用法代码示例。如果您正苦于以下问题:Python parse.quote_plus方法的具体用法?Python parse.quote_plus怎么用?Python parse.quote_plus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类urllib.parse
的用法示例。
在下文中一共展示了parse.quote_plus方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: redirect
# 需要导入模块: from urllib import parse [as 别名]
# 或者: from urllib.parse import quote_plus [as 别名]
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
)
示例2: build_custom_verification_url
# 需要导入模块: from urllib import parse [as 别名]
# 或者: from urllib.parse import quote_plus [as 别名]
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
示例3: generate_sas_token
# 需要导入模块: from urllib import parse [as 别名]
# 或者: from urllib.parse import quote_plus [as 别名]
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)
示例4: list_request_by_did
# 需要导入模块: from urllib import parse [as 别名]
# 或者: from urllib.parse import quote_plus [as 别名]
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)
示例5: add_scope
# 需要导入模块: from urllib import parse [as 别名]
# 或者: from urllib.parse import quote_plus [as 别名]
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)
示例6: list_file_replicas
# 需要导入模块: from urllib import parse [as 别名]
# 或者: from urllib.parse import quote_plus [as 别名]
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)
示例7: list_dataset_replicas
# 需要导入模块: from urllib import parse [as 别名]
# 或者: from urllib.parse import quote_plus [as 别名]
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)
示例8: list_dataset_replicas_vp
# 需要导入模块: from urllib import parse [as 别名]
# 或者: from urllib.parse import quote_plus [as 别名]
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)
示例9: delete_global_account_limit
# 需要导入模块: from urllib import parse [as 别名]
# 或者: from urllib.parse import quote_plus [as 别名]
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)
示例10: get_global_account_usage
# 需要导入模块: from urllib import parse [as 别名]
# 或者: from urllib.parse import quote_plus [as 别名]
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)
示例11: detach_dids
# 需要导入模块: from urllib import parse [as 别名]
# 或者: from urllib.parse import quote_plus [as 别名]
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)
示例12: list_files
# 需要导入模块: from urllib import parse [as 别名]
# 或者: from urllib.parse import quote_plus [as 别名]
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)
示例13: get_did
# 需要导入模块: from urllib import parse [as 别名]
# 或者: from urllib.parse import quote_plus [as 别名]
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)
示例14: set_metadata
# 需要导入模块: from urllib import parse [as 别名]
# 或者: from urllib.parse import quote_plus [as 别名]
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)
示例15: set_status
# 需要导入模块: from urllib import parse [as 别名]
# 或者: from urllib.parse import quote_plus [as 别名]
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)