本文整理汇总了Python中six.moves.urllib.parse.quote函数的典型用法代码示例。如果您正苦于以下问题:Python quote函数的具体用法?Python quote怎么用?Python quote使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了quote函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
示例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_
示例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)
示例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
示例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
示例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)
示例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)
示例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)
示例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')
示例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')
示例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)
]
)
示例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')
示例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
示例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)
示例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)