本文整理汇总了Python中thumbor.url.Url.reencode_url方法的典型用法代码示例。如果您正苦于以下问题:Python Url.reencode_url方法的具体用法?Python Url.reencode_url怎么用?Python Url.reencode_url使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类thumbor.url.Url
的用法示例。
在下文中一共展示了Url.reencode_url方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check_image
# 需要导入模块: from thumbor.url import Url [as 别名]
# 或者: from thumbor.url.Url import reencode_url [as 别名]
def check_image(self, kw):
if self.context.config.MAX_ID_LENGTH > 0:
# Check if an image with an uuid exists in storage
exists = yield gen.maybe_future(self.context.modules.storage.exists(kw['image'][:self.context.config.MAX_ID_LENGTH]))
if exists:
kw['image'] = kw['image'][:self.context.config.MAX_ID_LENGTH]
url = self.request.uri
if not self.validate(kw['image']):
self._error(400, 'No original image was specified in the given URL')
return
kw['request'] = self.request
kw['image'] = quote(kw['image'].encode('utf-8'))
self.context.request = RequestParameters(**kw)
has_none = not self.context.request.unsafe and not self.context.request.hash
has_both = self.context.request.unsafe and self.context.request.hash
if has_none or has_both:
self._error(400, 'URL does not have hash or unsafe, or has both: %s' % url)
return
if self.context.request.unsafe and not self.context.config.ALLOW_UNSAFE_URL:
self._error(400, 'URL has unsafe but unsafe is not allowed by the config: %s' % url)
return
if self.context.config.USE_BLACKLIST:
blacklist = yield self.get_blacklist_contents()
if self.context.request.image_url in blacklist:
self._error(400, 'Source image url has been blacklisted: %s' % self.context.request.image_url)
return
url_signature = self.context.request.hash
if url_signature:
signer = self.context.modules.url_signer(self.context.server.security_key)
url_to_validate = Url.reencode_url(url).replace('/%s/' % self.context.request.hash, '')
valid = signer.validate(url_signature, url_to_validate)
if not valid and self.context.config.STORES_CRYPTO_KEY_FOR_EACH_IMAGE:
# Retrieves security key for this image if it has been seen before
security_key = yield gen.maybe_future(self.context.modules.storage.get_crypto(self.context.request.image_url))
if security_key is not None:
signer = self.context.modules.url_signer(security_key)
valid = signer.validate(url_signature, url_to_validate)
if not valid:
self._error(400, 'Malformed URL: %s' % url)
return
self.execute_image_operations()