本文整理汇总了Python中six.moves.urllib.parse.quote函数的典型用法代码示例。如果您正苦于以下问题:Python quote函数的具体用法?Python quote怎么用?Python quote使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了quote函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: base_handle_copy_request
def base_handle_copy_request(self, src_container, src_obj, dest_container, dest_object):
"""
Unified path for:
PUT verb with X-Copy-From and
COPY verb with Destination
"""
# Get an iterator over the source object
source_path = "/%s/%s/%s/%s" % (self.api_version, self.account, src_container, src_obj)
source_req = self.request.copy_get()
source_req.headers.pop("X-Backend-Storage-Policy-Index", None)
source_req.headers.pop("X-Run-Storlet", None)
source_req.path_info = source_path
source_req.headers["X-Newest"] = "true"
src_resp = source_req.get_response(self.app)
sreq = self._build_storlet_request(self.request, src_resp.headers, src_resp.app_iter)
self.gather_extra_sources()
sresp = self.gateway.invocation_flow(sreq, self.extra_sources)
resp = self.handle_put_copy_response(sresp.user_metadata, sresp.data_iter)
acct, path = src_resp.environ["PATH_INFO"].split("/", 3)[2:4]
resp.headers["X-Storlet-Generated-From-Account"] = quote(acct)
resp.headers["X-Storlet-Generated-From"] = quote(path)
if "last-modified" in src_resp.headers:
resp.headers["X-Storlet-Generated-From-Last-Modified"] = src_resp.headers["last-modified"]
return resp
开发者ID:openstack,项目名称:storlets,代码行数:26,代码来源:proxy.py
示例2: id
def id(self):
"""Return the id of this sequence."""
if self.sub_children:
id_ = ",".join(quote(child.id) for child in self.template.children())
else:
id_ = quote(self.template.id)
return id_
开发者ID:pydap,项目名称:pydap,代码行数:7,代码来源:dap.py
示例3: test_image_already_generated_by_thumbor_2_times
def test_image_already_generated_by_thumbor_2_times(self):
with open(
normalize_unicode_path(u'./tests/fixtures/images/alabama1_ap620é.jpg'), 'r'
) as f:
self.context.modules.storage.put(
quote("http://test.com/smart/alabama1_ap620é"),
f.read()
)
crypto = CryptoURL('ACME-SEC')
image_url = self.get_url(
crypto.generate(
image_url=quote(self.get_url(
crypto.generate(
image_url=quote("http://test.com/smart/alabama1_ap620é")
)
))
)
)
url = crypto.generate(
image_url=quote(image_url)
)
response = self.fetch(url)
expect(response.code).to_equal(200)
开发者ID:scorphus,项目名称:thumbor,代码行数:25,代码来源:test_base_handler.py
示例4: base_handle_copy_request
def base_handle_copy_request(self, src_container, src_obj,
dest_container, dest_object):
"""
Unified path for:
PUT verb with X-Copy-From and
COPY verb with Destination
"""
# Get an iterator over the source object
source_path = '/%s/%s/%s/%s' % (self.api_version, self.account,
src_container, src_obj)
source_req = self.request.copy_get()
source_req.headers.pop('X-Backend-Storage-Policy-Index', None)
source_req.headers.pop('X-Run-Storlet', None)
source_req.path_info = source_path
source_req.headers['X-Newest'] = 'true'
source_resp = source_req.get_response(self.app)
# Do proxy copy flow
(out_md, app_iter) = self.gateway.gatewayProxyCopyFlow(self.request,
source_resp)
resp = self.handle_put_copy_response(out_md, app_iter)
acct, path = source_resp.environ['PATH_INFO'].split('/', 3)[2:4]
resp.headers['X-Storlet-Generated-From-Account'] = quote(acct)
resp.headers['X-Storlet-Generated-From'] = quote(path)
if 'last-modified' in source_resp.headers:
resp.headers['X-Storlet-Generated-From-Last-Modified'] = \
source_resp.headers['last-modified']
return resp
开发者ID:Nicolepcx,项目名称:storlets,代码行数:30,代码来源:storlet_handler.py
示例5: _listing_pages_iter
def _listing_pages_iter(self, account_name, lcontainer, lprefix, env):
marker = ''
while True:
lreq = make_pre_authed_request(
env, method='GET', swift_source='VW',
path='/v1/%s/%s' % (account_name, lcontainer))
lreq.environ['QUERY_STRING'] = \
'format=json&prefix=%s&marker=%s' % (quote(lprefix),
quote(marker))
lresp = lreq.get_response(self.app)
if not is_success(lresp.status_int):
if lresp.status_int == HTTP_NOT_FOUND:
raise ListingIterNotFound()
elif is_client_error(lresp.status_int):
raise HTTPPreconditionFailed()
else:
raise ListingIterError()
if not lresp.body:
break
sublisting = json.loads(lresp.body)
if not sublisting:
break
marker = sublisting[-1]['name'].encode('utf-8')
yield sublisting
开发者ID:bkolli,项目名称:swift,代码行数:26,代码来源:versioned_writes.py
示例6: sites_linking_in
def sites_linking_in(self, urls, count=MAX_SITES_LINKING_IN_COUNT, start=0):
if count > self.MAX_SITES_LINKING_IN_COUNT:
raise RuntimeError("Maximum SitesLinkingIn result count is %s." % self.MAX_SITES_LINKING_IN_COUNT)
params = { "Action": "SitesLinkingIn" }
if not isinstance(urls, (list, tuple)):
params.update({
"Url": urlparse.quote(urls),
"ResponseGroup": "SitesLinkingIn",
"Count": count,
"Start": start,
})
else:
if len(urls) > self.MAX_BATCH_REQUESTS:
raise RuntimeError("Maximum number of batch URLs is %s." % self.MAX_BATCH_REQUESTS)
params.update({
"SitesLinkingIn.Shared.ResponseGroup": "SitesLinkingIn",
"SitesLinkingIn.Shared.Count": count,
"SitesLinkingIn.Shared.Start": start,
})
for i, url in enumerate(urls):
params.update({"SitesLinkingIn.%d.Url" % (i + 1): urlparse.quote(url)})
return self.request(params)
开发者ID:krey,项目名称:python-awis,代码行数:26,代码来源:__init__.py
示例7: handle_COPY
def handle_COPY(self, req, start_response, account, container, obj):
if not req.headers.get('Destination'):
return HTTPPreconditionFailed(request=req,
body='Destination header required'
)(req.environ, start_response)
dest_account = account
if 'Destination-Account' in req.headers:
dest_account = unquote(req.headers.get('Destination-Account'))
dest_account = check_account_format(req, dest_account)
req.headers['X-Copy-From-Account'] = quote(account)
account = dest_account
del req.headers['Destination-Account']
dest_container, dest_object = _check_destination_header(req)
source = '/%s/%s' % (container, obj)
container = dest_container
obj = dest_object
# re-write the existing request as a PUT instead of creating a new one
req.method = 'PUT'
# As this the path info is updated with destination container,
# the proxy server app will use the right object controller
# implementation corresponding to the container's policy type.
ver, _junk = req.split_path(1, 2, rest_with_last=True)
req.path_info = '/%s/%s/%s/%s' % (
ver, dest_account, dest_container, dest_object)
req.headers['Content-Length'] = 0
req.headers['X-Copy-From'] = quote(source)
del req.headers['Destination']
return self.handle_PUT(req, start_response)
开发者ID:jgmerritt,项目名称:swift,代码行数:28,代码来源:copy.py
示例8: create_container
def create_container(self, req, container_path):
"""
Checks if the container exists and if not try to create it.
:params container_path: an unquoted path to a container to be created
:returns: True if created container, False if container exists
:raises CreateContainerError: when unable to create container
"""
head_cont_req = make_subrequest(
req.environ, method='HEAD', path=quote(container_path),
headers={'X-Auth-Token': req.headers.get('X-Auth-Token')},
swift_source='EA')
resp = head_cont_req.get_response(self.app)
if resp.is_success:
return False
if resp.status_int == HTTP_NOT_FOUND:
create_cont_req = make_subrequest(
req.environ, method='PUT', path=quote(container_path),
headers={'X-Auth-Token': req.headers.get('X-Auth-Token')},
swift_source='EA')
resp = create_cont_req.get_response(self.app)
if resp.is_success:
return True
raise CreateContainerError(
"Create Container Failed: " + container_path,
resp.status_int, resp.status)
开发者ID:jgmerritt,项目名称:swift,代码行数:25,代码来源:bulk.py
示例9: test_check_symlink_header_invalid_format
def test_check_symlink_header_invalid_format(self):
def do_test(headers, status, err_msg):
req = Request.blank('/v1/a/c/o', method='PUT',
headers=headers)
with self.assertRaises(swob.HTTPException) as cm:
symlink._check_symlink_header(req)
self.assertEqual(cm.exception.status, status)
self.assertEqual(cm.exception.body, err_msg)
do_test({'X-Symlink-Target': '/c1/o1'},
'412 Precondition Failed',
'X-Symlink-Target header must be of the '
'form <container name>/<object name>')
do_test({'X-Symlink-Target': 'c1o1'},
'412 Precondition Failed',
'X-Symlink-Target header must be of the '
'form <container name>/<object name>')
do_test({'X-Symlink-Target': 'c1/o1',
'X-Symlink-Target-Account': '/another'},
'412 Precondition Failed',
'Account name cannot contain slashes')
do_test({'X-Symlink-Target': 'c1/o1',
'X-Symlink-Target-Account': 'an/other'},
'412 Precondition Failed',
'Account name cannot contain slashes')
# url encoded case
do_test({'X-Symlink-Target': '%2Fc1%2Fo1'},
'412 Precondition Failed',
'X-Symlink-Target header must be of the '
'form <container name>/<object name>')
do_test({'X-Symlink-Target': 'c1/o1',
'X-Symlink-Target-Account': '%2Fanother'},
'412 Precondition Failed',
'Account name cannot contain slashes')
do_test({'X-Symlink-Target': 'c1/o1',
'X-Symlink-Target-Account': 'an%2Fother'},
'412 Precondition Failed',
'Account name cannot contain slashes')
# with multi-bytes
do_test(
{'X-Symlink-Target':
u'/\u30b0\u30e9\u30d6\u30eb/\u30a2\u30ba\u30ec\u30f3'},
'412 Precondition Failed',
'X-Symlink-Target header must be of the '
'form <container name>/<object name>')
target = u'/\u30b0\u30e9\u30d6\u30eb/\u30a2\u30ba\u30ec\u30f3'
encoded_target = quote(target.encode('utf-8'), '')
do_test(
{'X-Symlink-Target': encoded_target},
'412 Precondition Failed',
'X-Symlink-Target header must be of the '
'form <container name>/<object name>')
account = u'\u30b0\u30e9\u30d6\u30eb/\u30a2\u30ba\u30ec\u30f3'
encoded_account = quote(account.encode('utf-8'), '')
do_test(
{'X-Symlink-Target': 'c/o',
'X-Symlink-Target-Account': encoded_account},
'412 Precondition Failed',
'Account name cannot contain slashes')
开发者ID:chenzhongtao,项目名称:swift,代码行数:60,代码来源:test_symlink.py
示例10: list
def list(self, stack_id, resource_name=None, **kwargs):
"""Get a list of events.
:param stack_id: ID of stack the events belong to
:param resource_name: Optional name of resources to filter events by
:rtype: list of :class:`Event`
"""
params = {}
if 'filters' in kwargs:
filters = kwargs.pop('filters')
params.update(filters)
for key, value in kwargs.items():
if value:
params[key] = value
if resource_name is None:
url = '/stacks/%s/events' % stack_id
else:
stack_id = self._resolve_stack_id(stack_id)
url = '/stacks/%s/resources/%s/events' % (
parse.quote(stack_id),
parse.quote(encodeutils.safe_encode(resource_name)))
if params:
# convert to a sorted dict for python3 predictible order
params = collections.OrderedDict(sorted(params.items()))
url += '?%s' % parse.urlencode(params, True)
return self._list(url, 'events')
开发者ID:openstack,项目名称:python-heatclient,代码行数:29,代码来源:events.py
示例11: join_params
def join_params(params, encode=True):
return "&".join(
[
"%s=%s" % (urlparse.quote(key, safe="") if encode else key, urlparse.quote(val, safe="") if encode else val)
for key, val in six.iteritems(params)
]
)
开发者ID:ColdrickSotK,项目名称:storyboard,代码行数:7,代码来源:utils.py
示例12: list
def list(self, stack_id, resource_name=None, **kwargs):
"""Get a list of events.
:param stack_id: ID of stack the events belong to
:param resource_name: Optional name of resources to filter events by
:rtype: list of :class:`Event`
"""
params = {}
if 'filters' in kwargs:
filters = kwargs.pop('filters')
params.update(filters)
for key, value in six.iteritems(kwargs):
if value:
params[key] = value
if resource_name is None:
url = '/stacks/%s/events' % stack_id
else:
stack_id = self._resolve_stack_id(stack_id)
url = '/stacks/%s/resources/%s/events' % (
parse.quote(stack_id, ''),
parse.quote(strutils.safe_encode(resource_name), ''))
if params:
url += '?%s' % parse.urlencode(params, True)
return self._list(url, 'events')
开发者ID:AsherBond,项目名称:python-heatclient,代码行数:26,代码来源:events.py
示例13: getEditTileURL
def getEditTileURL(tile, request):
"""Get the edit URL for the given tile.
If the tile is transient, the URL will contain a `_tiledata`
parameter with the tile data encoded in JSON. This avoids possible
collisions between raw data coming from the edit form and tile
data retrieved by the transient tile data manager.
"""
id = tile.id
name = tile.__name__
context = tile.__parent__
if name is None or context is None:
raise TypeError("Insufficient context to determine URL")
url = str(getMultiAdapter((context, request), IAbsoluteURL))
tileFragment = "@@edit-tile/" + urlparse.quote(name.encode('utf-8'), _safe)
if id:
tileFragment += '/' + urlparse.quote(id.encode('utf-8'), _safe)
url = '%s/%s' % (url, tileFragment,)
if not IPersistentTile.providedBy(tile):
data = ITileDataManager(tile).get()
if data:
tileType = queryUtility(ITileType, name=name)
if tileType is not None and tileType.schema is not None:
if '?' in url:
url += '&' + '_tiledata=' + json.dumps(data)
else:
url += '?' + '_tiledata=' + json.dumps(data)
return url
开发者ID:plone,项目名称:plone.app.tiles,代码行数:33,代码来源:utils.py
示例14: notify
def notify(self, check):
url = self.channel.value_down
if check.status == "up":
url = self.channel.value_up
if not url:
# If the URL is empty then we do nothing
return "no-op"
# Replace variables with actual values.
# There should be no bad translations if users use $ symbol in
# check's name or tags, because $ gets urlencoded to %24
if "$CODE" in url:
url = url.replace("$CODE", str(check.code))
if "$STATUS" in url:
url = url.replace("$STATUS", check.status)
if "$NAME" in url:
url = url.replace("$NAME", quote(check.name))
if "$TAG" in url:
for i, tag in enumerate(check.tags_list()):
placeholder = "$TAG%d" % (i + 1)
url = url.replace(placeholder, quote(tag))
return self.get(url)
开发者ID:Persistent13,项目名称:healthchecks,代码行数:28,代码来源:transports.py
示例15: _db_create_special
def _db_create_special(
client,
source_db,
dest_db,
kwargs):
# Determine server location
kwargs['location'] = get_server_location(
server_name=dest_db.server_name,
resource_group_name=dest_db.resource_group_name)
# Set create mode properties
subscription_id = get_subscription_id()
kwargs['source_database_id'] = (
'/subscriptions/{}/resourceGroups/{}/providers/Microsoft.Sql/servers/{}/databases/{}'
.format(quote(subscription_id),
quote(source_db.resource_group_name),
quote(source_db.server_name),
quote(source_db.database_name)))
# Create
return client.create_or_update(
server_name=dest_db.server_name,
resource_group_name=dest_db.resource_group_name,
database_name=dest_db.database_name,
parameters=kwargs)
开发者ID:akshaysngupta,项目名称:azure-cli,代码行数:26,代码来源:custom.py
示例16: make_query
def make_query(*args, **kwargs):
'''Construct a URL query string, with marshalling markup.
If there are positional arguments, they must be dictionaries.
They are combined with the dictionary of keyword arguments to form
a dictionary of query names and values.
Query names (the keys) must be strings. Values may be strings,
integers, floats, or DateTimes, and they may also be lists or
namespaces containing these types. Names and string values
should not be URL-quoted. All arguments are marshalled with
complex_marshal().
'''
d = {}
for arg in args:
d.update(arg)
d.update(kwargs)
qlist = complex_marshal(list(d.items()))
for i in range(len(qlist)):
k, m, v = qlist[i]
if PY2 and isinstance(v, text_type):
v = v.encode(_default_encoding())
qlist[i] = '%s%s=%s' % (quote(k), m, quote(str(v)))
return '&'.join(qlist)
开发者ID:dhavlik,项目名称:Zope,代码行数:27,代码来源:Zope.py
示例17: object_request
def object_request(self, req, api_version, account, container, obj,
allow_versioned_writes):
container_name = unquote(container)
object_name = unquote(obj)
orig_container = get_unversioned_container(container_name)
if orig_container != container_name:
orig_object, version = \
swift3_split_object_name_version(object_name)
req.environ['oio.query'] = {'version': version}
req.environ['PATH_INFO'] = '/%s/%s/%s/%s' % (api_version,
account,
quote(orig_container),
quote(orig_object))
elif req.method == 'DELETE':
ver_mode = req.headers.get('X-Backend-Versioning-Mode-Override',
'history')
if ver_mode == 'stack':
# Do not create a delete marker, delete the latest version
obj_inf = get_object_info(req.environ, self.app,
swift_source='VW')
req.environ['oio.query'] = {
'version': obj_inf.get('sysmeta', {}).get('version-id')
}
resp = req.get_response(self.app)
if req.method == 'HEAD':
close_if_possible(resp.app_iter)
return resp
开发者ID:jfsmig,项目名称:oio-swift,代码行数:27,代码来源:versioned_writes.py
示例18: quote_user_host
def quote_user_host(user, host):
quoted = ''
if host:
quoted = parse.quote("%[email protected]%s" % (user, host))
else:
quoted = parse.quote("%s" % user)
return quoted.replace('.', '%2e')
开发者ID:Simplit-openapps,项目名称:python-troveclient,代码行数:7,代码来源:common.py
示例19: _dump_common_links
def _dump_common_links(self, obj):
"""Dump common links for deposits and records."""
links = {}
m = obj.get('metadata', {})
doi = m.get('doi')
if doi:
links['badge'] = ui_link_for('badge', doi=quote(doi))
links['doi'] = idutils.to_url(doi, 'doi', 'https')
conceptdoi = m.get('conceptdoi')
if conceptdoi:
links['conceptbadge'] = ui_link_for('badge', doi=quote(conceptdoi))
links['conceptdoi'] = idutils.to_url(conceptdoi, 'doi', 'https')
files = m.get('_files', [])
for f in files:
if f.get('type') in thumbnail_exts:
try:
links['thumb250'] = self._thumbnail_url(f, 250)
# First previewable image is used for preview.
except RuntimeError:
pass
break
return links
开发者ID:slint,项目名称:zenodo,代码行数:26,代码来源:common.py
示例20: test_list_alarms_sort_by_asc_desc
def test_list_alarms_sort_by_asc_desc(self):
alarm_definition_ids, expected_metric = self._create_alarms_for_test_alarms(num=3)
resp, response_body = self.monasca_client.list_alarms('?metric_name=' + expected_metric['name'])
self._verify_list_alarms_elements(resp, response_body,
expect_num_elements=3)
resp, response_body = self.monasca_client.list_alarms('?metric_name=' + expected_metric['name'] +
'&sort_by=' +
urlparse.quote('created_timestamp asc'))
self._verify_list_alarms_elements(resp, response_body,
expect_num_elements=3)
elements = response_body['elements']
last_timestamp = elements[0]['created_timestamp']
for element in elements:
assert element['created_timestamp'] >= last_timestamp,\
"Created_timestamps are not in ascending order {} came before {}".format(last_timestamp,
element['created_timestamp'])
last_timestamp = element['created_timestamp']
resp, response_body = self.monasca_client.list_alarms('?metric_name=' + expected_metric['name'] +
'&sort_by=' +
urlparse.quote('created_timestamp desc'))
self._verify_list_alarms_elements(resp, response_body,
expect_num_elements=3)
elements = response_body['elements']
last_timestamp = elements[0]['created_timestamp']
for element in elements:
assert element['created_timestamp'] <= last_timestamp,\
"Created_timestamps are not in descending order {} came before {}".format(last_timestamp,
element['created_timestamp'])
last_timestamp = element['created_timestamp']
开发者ID:Missxiaoguo,项目名称:monasca-api,代码行数:33,代码来源:test_alarms.py
注:本文中的six.moves.urllib.parse.quote函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论