本文整理汇总了Python中six.moves.urllib.parse.urlquote函数的典型用法代码示例。如果您正苦于以下问题:Python urlquote函数的具体用法?Python urlquote怎么用?Python urlquote使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了urlquote函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_client_protocol_mapper
def create_client_protocol_mapper(self, realm_name, client, mapper):
obj_id = client['id']
cmd_name = ('create protocol-mapper "{mapper_name}" for clientid {clientid} '
'in realm "{realm}"'.format(
mapper_name=mapper['name'],
clientid=client['clientId'],
realm=realm_name))
url = URL_CLIENT_PROTOCOL_MAPPER_MODEL.format(
server=self.server,
realm=urlquote(realm_name),
id=urlquote(obj_id))
self._log_rest_request(cmd_name, url, mapper)
response = self.session.post(url, json=mapper)
self._log_rest_response(cmd_name, response)
try:
response_json = response.json()
except ValueError:
response_json = None
if response.status_code != requests.codes.created: # pylint: disable=no-member
raise RESTError(cmd_name, response)
self._log_return_value(response_json)
return response_json
示例2: process_job_folder
def process_job_folder(self, folder, folder_path):
folder_path += '/job/%s' % urlquote(folder['name'])
data = self.get_data(self.python_api_url(folder_path),
tree='jobs[name,color]')
result = []
for job in data.get('jobs', []):
if 'color' not in job.keys():
result += self.process_job_folder(job, folder_path)
else:
job['url'] = '%s/job/%s' % (folder_path, urlquote(job['name']))
result.append(job)
return result
示例3: get_local_file_url
def get_local_file_url(fname):
"""Return OS specific URL pointing to a local file
Parameters
----------
fname : string
Full filename
"""
if on_windows:
fname_rep = fname.replace("\\", "/")
furl = "file:///%s" % urlquote(fname_rep)
lgr.debug("Replaced '\\' in file's url: %s" % furl)
else:
furl = "file://%s" % urlquote(fname)
return furl
示例4: _fields_to_pr
def _fields_to_pr(cls, fields):
"""Recompose back fields dict to ParseResult"""
netloc = fields['username'] or ''
if fields['password']:
netloc += ':' + fields['password']
if netloc:
netloc += '@'
netloc += fields['hostname']
if fields['port']:
if fields['hostname'].count(':') >= 2:
# ipv6 -- need to enclose in []
netloc = '[%s]:%s' % (netloc, fields['port'])
else:
netloc += ':%s' % fields['port']
pr_fields = {
f: fields[f]
for f in cls._FIELDS
if f not in ('hostname', 'password', 'username', 'port')
}
pr_fields['netloc'] = netloc
pr_fields['params'] = ''
# We need to quote the path
pr_fields['path'] = urlquote(pr_fields['path'])
# TODO: figure out what to do with query/fragment... one step at a time
return ParseResult(**pr_fields)
示例5: get_node_url
def get_node_url(self, nodename=""):
"""Return the url for nodes"""
url = urlparse.urljoin(
self.base_server_url(),
'computer/%s' %
urlquote(nodename))
return url
示例6: set_num_executors
def set_num_executors(self, value):
"""
Sets number of executors for node
Warning! Setting number of executors on master node will erase all
other settings
"""
set_value = value if isinstance(value, str) else str(value)
if self.name == 'master':
# master node doesn't have config.xml, so we're going to submit
# form here
data = 'json=%s' % urlquote(
json.dumps({
"numExecutors": set_value,
"nodeProperties": {
"stapler-class-bag": "true"
}
})
)
url = self.baseurl + '/configSubmit'
self.jenkins.requester.post_and_confirm_status(url, data=data)
else:
self.set_config_element('numExecutors', set_value)
self.poll()
示例7: category
def category(self, trans, **kwd):
"""
GET /api/tool_shed/category
Display a list of repositories in the selected category.
:param tool_shed_url: the url of the toolshed to get repositories from
:param category_id: the category to get repositories from
"""
tool_shed_url = urlunquote(kwd.get('tool_shed_url', ''))
category_id = kwd.get('category_id', '')
params = dict(installable=True)
tool_shed_url = common_util.get_tool_shed_url_from_tool_shed_registry(trans.app, tool_shed_url)
url = util.build_url(tool_shed_url, pathspec=['api', 'categories', category_id, 'repositories'], params=params)
repositories = []
return_json = json.loads(util.url_get(url))
for repository in return_json['repositories']:
api_url = web.url_for(controller='api/tool_shed',
action='repository',
tool_shed_url=urlquote(tool_shed_url),
repository_id=repository['id'],
qualified=True)
repository['url'] = api_url
repositories.append(repository)
return_json['repositories'] = repositories
return return_json
示例8: toggle_temporarily_offline
def toggle_temporarily_offline(self, message="requested from jenkinsapi"):
"""
Switches state of connected node (online/offline) and
set 'temporarilyOffline' property (True/False)
Calling the same method again will bring node status back.
:param message: optional string can be used to explain why you
are taking this node offline
"""
initial_state = self.is_temporarily_offline()
url = self.baseurl + \
"/toggleOffline?offlineMessage=" + urlquote(message)
try:
html_result = self.jenkins.requester.get_and_confirm_status(url)
except PostRequired:
html_result = self.jenkins.requester.post_and_confirm_status(
url,
data={})
self.poll()
log.debug(html_result)
state = self.is_temporarily_offline()
if initial_state == state:
raise AssertionError(
"The node state has not changed: temporarilyOffline = %s" %
state)
示例9: combine_single
def combine_single(url, add_on):
url_parsed = list(urlparse(url))
path = url_parsed[2]
if path and not path.endswith("/"):
path += "/"
path += urlquote(str(add_on), safe="/:")
url_parsed[2] = path
return urlunparse(url_parsed)
示例10: update_offline_reason
def update_offline_reason(self, reason):
"""
Update offline reason on a temporary offline clsuter
"""
if self.is_temporarily_offline():
url = self.baseurl + '/changeOfflineCause?offlineMessage=' + urlquote(reason)
self.jenkins.requester.post_and_confirm_status(url, data={})
示例11: _sanitize_untrusted_url
def _sanitize_untrusted_url(response, url):
if isinstance(url, bytes):
url = url.decode('utf8', 'replace')
if not url.startswith('/') or url.startswith('//'):
url = '/?bad_redirect=' + urlquote(url)
host = response.request.headers[b'Host'].decode('ascii')
# ^ this is safe because we don't accept requests with unknown hosts
return response.website.canonical_scheme + '://' + host + url
示例12: as_git_url
def as_git_url(self):
"""Dereference /// into original URLs which could be used by git for cloning
Returns
-------
str
URL string to reference the DataLadRI from its /// form
"""
if self.remote:
raise NotImplementedError("not supported ATM to reference additional remotes")
return "{}{}".format(consts.DATASETS_TOPURL, urlquote(self.path))
示例13: sign_certificate
def sign_certificate(self, public_key, duration=DEFAULT_CERT_DURATION,
service=None):
body = {
"publicKey": public_key,
"duration": duration,
}
url = "/certificate/sign"
if service is not None:
url += "?service=" + urlquote(service)
resp = self.apiclient.post(url, body, auth=self._auth)
return resp["cert"]
示例14: nolog_replace
def nolog_replace(string, nolog):
"""Replace occurences of strings given in `nolog` with XXXXXXXX"""
for value in nolog:
if not isinstance(value, six.string_types):
continue
quoted = urlquote(value)
shquoted = shell_quote(value)
for nolog_value in (shquoted, value, quoted):
string = string.replace(nolog_value, 'XXXXXXXX')
return string
示例15: get_file_url
def get_file_url(self, archive_file=None, archive_key=None, file=None):
"""Given archive (file or a key) and a file -- compose URL for access
"""
assert file is not None
if archive_file is not None:
if archive_key is not None:
raise ValueError("Provide archive_file or archive_key - not both")
archive_key = self._get_file_key(archive_file)
# todo (out, err) = annex('lookupkey a.tar.gz')
assert archive_key is not None
file_quoted = urlquote(file)
return "%s%s/%s" % (self.url_prefix, archive_key, file_quoted.lstrip("/"))