• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python url.Url类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中thumbor.url.Url的典型用法代码示例。如果您正苦于以下问题:Python Url类的具体用法?Python Url怎么用?Python Url使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Url类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:5um1th,项目名称:thumbor,代码行数:31,代码来源:test_url.py


示例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
开发者ID:rootart,项目名称:thumbor,代码行数:26,代码来源:test_urls.py


示例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
开发者ID:rootart,项目名称:thumbor,代码行数:13,代码来源:test_urls.py


示例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
开发者ID:douglas,项目名称:thumbor,代码行数:35,代码来源:crypto.py


示例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)'
        )
开发者ID:5um1th,项目名称:thumbor,代码行数:25,代码来源:test_url.py


示例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
开发者ID:5um1th,项目名称:thumbor,代码行数:27,代码来源:app.py


示例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
开发者ID:gerasim13,项目名称:libthumbor,代码行数:33,代码来源:test_libthumbor.py


示例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>.+)'
开发者ID:torkil,项目名称:thumbor,代码行数:7,代码来源:test_urls.py


示例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()
开发者ID:wikimedia,项目名称:thumbor-multi-handler,代码行数:35,代码来源:multi.py


示例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)
开发者ID:Hazer,项目名称:thumbor,代码行数:29,代码来源:app.py


示例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
开发者ID:Bladrak,项目名称:core,代码行数:30,代码来源:web.py


示例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
开发者ID:ettoredn,项目名称:thumbor,代码行数:32,代码来源:app.py


示例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
开发者ID:rootart,项目名称:thumbor,代码行数:7,代码来源:test_urls.py


示例14: test_url_generate_min

def test_url_generate_min():
    url = Url.generate_options(
        width=300,
        height=200
    )

    assert url == "300x200"
开发者ID:rootart,项目名称:thumbor,代码行数:7,代码来源:test_urls.py


示例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()
开发者ID:VladimirFilonov,项目名称:thumbor,代码行数:59,代码来源:imaging.py


示例16: test_url_generate_with_smart

def test_url_generate_with_smart():
    url = Url.generate_options(
        width=300,
        height=200,
        smart=True
    )

    assert url == "300x200/smart"
开发者ID:rootart,项目名称:thumbor,代码行数:8,代码来源:test_urls.py


示例17: test_url_generate_with_flipping

def test_url_generate_with_flipping():
    url = Url.generate_options(
        width=300,
        height=200,
        smart=True,
        horizontal_flip=True,
        vertical_flip=True
    )

    assert url == "-300x-200/smart"
开发者ID:rootart,项目名称:thumbor,代码行数:10,代码来源:test_urls.py


示例18: __init__

    def __init__(self, context):
        self.context = context

        handlers = [(r"/healthcheck", HealthcheckHandler)]

        if context.config.ENABLE_ORIGINAL_PHOTO_UPLOAD:
            handlers.append((r"/upload", UploadHandler, {"context": context}))

        handlers.append((Url.regex(), ImageProcessHandler, {"context": context}))

        super(ThumborServiceApp, self).__init__(handlers)
开发者ID:diogomonica,项目名称:thumbor,代码行数:11,代码来源:app.py


示例19: test_url_generate_with_manual_crop

def test_url_generate_with_manual_crop():
    url = Url.generate_options(
        width=300,
        height=200,
        crop_left=10,
        crop_top=11,
        crop_right=12,
        crop_bottom=13
    )

    assert url == "10x11:12x13/300x200"
开发者ID:rootart,项目名称:thumbor,代码行数:11,代码来源:test_urls.py


示例20: test_can_get_regex_without_unsafe

    def test_can_get_regex_without_unsafe(self):
        regex = Url.regex(False)

        expect(regex).to_equal(
            '/?(?:(?P<debug>debug)/)?(?:(?P<meta>meta)/)?'
            '(?:(?P<trim>trim(?::(?:top-left|bottom-right))?(?::\\d+)?)/)?'
            '(?:(?P<crop_left>\\d+)x(?P<crop_top>\\d+):(?P<crop_right>\\d+)x(?P<crop_bottom>\\d+)/)?'
            '(?:(?P<adaptive>adaptive-)?(?P<full>full-)?(?P<fit_in>fit-in)/)?(?:(?P<horizontal_flip>-)?'
            '(?P<width>(?:\\d+|orig))?x(?P<vertical_flip>-)?(?P<height>(?:\\d+|orig))?/)?'
            '(?:(?P<halign>left|right|center)/)?(?:(?P<valign>top|bottom|middle)/)?'
            '(?:(?P<smart>smart)/)?(?:filters:(?P<filters>.+?\\))/)?(?P<image>.+)'
        )
开发者ID:5um1th,项目名称:thumbor,代码行数:12,代码来源:test_url.py



注:本文中的thumbor.url.Url类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.which函数代码示例发布时间:2022-05-27
下一篇:
Python transformer.Transformer类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap