本文整理汇总了Python中thumbor.url.Url类的典型用法代码示例。如果您正苦于以下问题:Python Url类的具体用法?Python Url怎么用?Python Url使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Url类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_parsing_complete_url
def test_parsing_complete_url(self):
url = '/debug/meta/trim/300x200:400x500/adaptive-full-fit-in/-300x-400/' \
'left/top/smart/filters:brightness(100)/some/image.jpg'
expected = {
'trim': 'trim',
'full': True,
'halign': 'left',
'fit_in': True,
'vertical_flip': True,
'image': 'some/image.jpg',
'crop': {'top': 200, 'right': 400, 'bottom': 500, 'left': 300},
'height': 400,
'width': 300,
'meta': True,
'horizontal_flip': True,
'filters': 'brightness(100)',
'valign': 'top',
'debug': True,
'adaptive': True,
'smart': True,
}
result = Url.parse_decrypted(url)
expect(result).not_to_be_null()
expect(result).to_be_like(expected)
# do it again to use compiled regex
result = Url.parse_decrypted(url)
expect(result).not_to_be_null()
expect(result).to_be_like(expected)
示例2: test_parse_urls_without_image
def test_parse_urls_without_image():
options = Url.parse_options("unsafe/meta/10x11:12x13/-300x-200/left/top/smart/")
assert options
options = Url.parse_options("/unsafe/meta/10x11:12x13/-300x-200/left/top/smart/")
assert options
assert options['meta'] == True
assert options['crop']['left'] == 10
assert options['crop']['top'] == 11
assert options['crop']['right'] == 12
assert options['crop']['bottom'] == 13
assert options['width'] == 300
assert options['height'] == 200
assert options['horizontal_flip'] == True
assert options['vertical_flip'] == True
assert options['halign'] == 'left'
assert options['valign'] == 'top'
assert options['smart'] == True
示例3: test_parse_urls_with_image
def test_parse_urls_with_image():
image_url = 's.glbimg.com/es/ge/f/original/2011/03/29/orlandosilva_60.jpg'
options = Url.parse('/unsafe/meta/10x11:12x13/-300x-200/left/top/smart/%s' % image_url)
assert options['image']
assert options['image'] == image_url
options = Url.parse('unsafe/meta/10x11:12x13/-300x-200/left/top/smart/%s' % image_url)
assert options['image']
assert options['image'] == image_url
示例4: encrypt
def encrypt(self,
width,
height,
smart,
fit_in,
flip_horizontal,
flip_vertical,
halign,
valign,
crop_left,
crop_top,
crop_right,
crop_bottom,
image):
url = "%s/%s" % (Url.generate_options(width,
height,
smart,
False,
fit_in,
flip_horizontal,
flip_vertical,
halign,
valign,
crop_left,
crop_top,
crop_right,
crop_bottom),
hashlib.md5(image).hexdigest())
pad = lambda s: s + (16 - len(s) % 16) * "{"
cipher = AES.new(self.salt)
encrypted = base64.urlsafe_b64encode(cipher.encrypt(pad(url)))
return encrypted
示例5: test_can_generate_url
def test_can_generate_url(self):
url = Url.generate_options(
debug=True,
width=300,
height=200,
smart=True,
meta=True,
trim=True,
adaptive=True,
full=True,
fit_in=True,
horizontal_flip=True,
vertical_flip=True,
halign='left',
valign='top',
crop_left=100,
crop_top=100,
crop_right=400,
crop_bottom=400,
filters='brightness(100)'
)
expect(url).to_equal(
'debug/meta/trim/100x100:400x400/adaptive-full-fit-in/-300x-200/left/top/smart/filters:brightness(100)'
)
示例6: get_handlers
def get_handlers(self):
handlers = [
(r'/healthcheck', HealthcheckHandler),
]
if self.context.config.UPLOAD_ENABLED:
# Handler to upload images (POST).
handlers.append(
(r'/image', ImageUploadHandler, {'context': self.context})
)
# Handler to retrieve or modify existing images (GET, PUT, DELETE)
handlers.append(
(r'/image/(.*)', ImageResourceHandler, {'context': self.context})
)
if self.context.config.USE_BLACKLIST:
handlers.append(
(r'/blacklist', BlacklistHandler, {'context': self.context})
)
# Imaging handler (GET)
handlers.append(
(Url.regex(), ImagingHandler, {'context': self.context})
)
return handlers
示例7: test_usage_new_format
def test_usage_new_format():
key = "my-security-key"
image = "s.glbimg.com/et/bb/f/original/2011/03/24/VN0JiwzmOw0b0lg.jpg"
thumbor_signer = Signer(key)
thumbor_url = Url.generate_options(
width=300,
height=200,
smart=True,
adaptive=False,
fit_in=False,
horizontal_flip=False,
vertical_flip=False,
halign='center',
valign='middle',
crop_left=0,
crop_top=0,
crop_right=0,
crop_bottom=0,
filters=[]
)
thumbor_url = ('%s/%s' % (thumbor_url, image)).lstrip('/')
thumbor_url = '/%s/%s' % (thumbor_signer.signature(thumbor_url), thumbor_url)
crypto = CryptoURL(key=key)
url = crypto.generate(
width=300,
height=200,
smart=True,
image_url=image
)
assert url == thumbor_url
示例8: test_returns_route_regex_with_filters
def test_returns_route_regex_with_filters():
class TestFilter(object):
regex = r'some-filter-fake-regex'
url = Url.regex(filters=[TestFilter])
assert url == '/?unsafe/(?:(?P<meta>meta)/)?(?:(?P<crop_left>\d+)x(?P<crop_top>\d+):(?P<crop_right>\d+)x(?P<crop_bottom>\d+)/)?(?:(?P<fit_in>fit-in)/)?(?:(?P<horizontal_flip>-)?(?P<width>\d+)?x(?P<vertical_flip>-)?(?P<height>\d+)?/)?(?:(?P<halign>left|right|center)/)?(?:(?P<valign>top|bottom|middle)/)?(?:(?P<smart>smart)/)?some-filter-fake-regex(?P<image>.+)'
示例9: post
def post(self, **kw):
paths = self.get_arguments('paths[]')
if len(paths) > MultiHandler.paths_limit:
self.set_status(400)
super(MultiHandler, self).write(
'Too many paths: %d max' % MultiHandler.paths_limit
)
super(MultiHandler, self).finish()
return
for path in paths:
request = HTTPServerRequest(
method='GET',
uri=path,
host=self.request.host,
connection=self.request.connection
)
handler = MultiHandler(
self.application,
request,
context=self.context
)
# Copy over the storage as-is, which allows those requests to
# share storage if needed (useful for request-storage)
handler.context.modules.storage = self.context.modules.storage
m = re.match(Url.regex(), path)
yield handler.check_image(m.groupdict())
# Close the request ASAP, the work is to be done async
self.set_status(200)
super(MultiHandler, self).finish()
示例10: __init__
def __init__(self, context):
self.context = context
handlers = [
(r'/healthcheck', HealthcheckHandler),
]
if context.config.UPLOAD_ENABLED:
# TODO Old handler to upload images
handlers.append(
(r'/upload', UploadHandler, {'context': self.context})
)
# Handler to upload images (POST).
handlers.append(
(r'/image', ImagesHandler, {'context': self.context})
)
# Handler to retrieve or modify existing images (GET, PUT, DELETE)
handlers.append(
(r'/image/(.*)', ImageHandler, {'context': self.context})
)
# Imaging handler (GET)
handlers.append(
(Url.regex(), ImagingHandler, {'context': self.context})
)
super(ThumborServiceApp, self).__init__(handlers)
示例11: path_to_parameters
def path_to_parameters(cls, path):
'''
:param path: url path
:return: A dictionary of parameters to be used with
ImagingHandler instances
'''
if not cls._url_regex:
cls._url_regex = re.compile(Url.regex())
if cls._url_regex.groups:
match = cls._url_regex.match(path)
# See https://github.com/tornadoweb/tornado/blob/01c78ebfcc993ff4f1d8336c2c45844fe9dab60e/tornado/web.py#L1951
# Pass matched groups to the handler. Since
# match.groups() includes both named and
# unnamed groups, we want to use either groups
# or groupdict but not both.
if cls._url_regex.groupindex:
parameters = dict(
(str(k), tornado.web._unquote_or_none(v))
for (k, v) in match.groupdict().items())
else:
parameters = [
tornado.web._unquote_or_none(s)
for s in match.groups()
]
else:
parameters = dict()
return parameters
示例12: get_handlers
def get_handlers(self):
handlers = [
(r'/healthcheck', HealthcheckHandler),
]
if self.context.config.UPLOAD_ENABLED:
# TODO: Old handler to upload images. Will be deprecated soon.
handlers.append(
(r'/upload', LegacyImageUploadHandler, {'context': self.context})
)
# Handler to upload images (POST).
handlers.append(
(r'/image', ImageUploadHandler, {'context': self.context})
)
# Handler to retrieve or modify existing images (GET, PUT, DELETE)
handlers.append(
(r'/image/(.*)', ImageResourceHandler, {'context': self.context})
)
if self.context.config.USE_BLACKLIST:
handlers.append(
(r'/blacklist', BlacklistHandler, {'context': self.context})
)
# Imaging handler (GET)
handlers.append(
(Url.regex(not self.context.config.SECURITY_DISABLE_KEY), ImagingHandler, {'context': self.context})
)
return handlers
示例13: test_url_generate_with_alignments
def test_url_generate_with_alignments():
url = Url.generate_options(
halign='left',
valign='top'
)
assert url == "0x0/left/top", url
示例14: test_url_generate_min
def test_url_generate_min():
url = Url.generate_options(
width=300,
height=200
)
assert url == "300x200"
示例15: check_image
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"))
kw["config"] = self.context.config
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.encode_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()