当前位置: 首页>>代码示例>>Python>>正文


Python libthumbor.CryptoURL类代码示例

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


在下文中一共展示了CryptoURL类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: 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

示例2: test_usage

def test_usage():
    key = "my-security-key"
    image = "s.glbimg.com/et/bb/f/original/2011/03/24/VN0JiwzmOw0b0lg.jpg"
    thumbor_crypto = Crypto(salt=key)

    thumbor_options = thumbor_crypto.encrypt(
        300,
        200,
        True,
        False,
        False,
        'center',
        'middle',
        0, 0, 0, 0,
        image=image
    )
    thumbor_url = "/%s/%s" % (thumbor_options, image)

    crypto = CryptoURL(key=key)

    url = crypto.generate(
        width=300,
        height=200,
        smart=True,
        image_url=image
    )

    assert url == thumbor_url
开发者ID:rootart,项目名称:libthumbor,代码行数:28,代码来源:test_libthumbor.py

示例3: main

def main(arguments=None):
    """Converts a given url with the specified arguments."""

    parsed_options, arguments = get_options(arguments)

    image_url = arguments[0]
    image_url = quote(image_url)

    try:
        config = Config.load(None)
    except:
        config = None

    if not parsed_options.key and not config:
        sys.stdout.write("Error: The -k or --key argument is mandatory. For more information type thumbor-url -h\n")
        return

    security_key, thumbor_params = get_thumbor_params(image_url, parsed_options, config)

    crypto = CryptoURL(key=security_key)
    url = crypto.generate(**thumbor_params)
    sys.stdout.write("URL:\n")
    sys.stdout.write("%s\n" % url)

    return url
开发者ID:expertise-com,项目名称:thumbor,代码行数:25,代码来源:url_composer.py

示例4: test_thumbor_can_decrypt_lib_thumbor_generated_url

def test_thumbor_can_decrypt_lib_thumbor_generated_url():
    key = "my-security-key"
    image = "s.glbimg.com/et/bb/f/original/2011/03/24/VN0JiwzmOw0b0lg.jpg"
    thumbor_crypto = Cryptor(key)

    crypto = CryptoURL(key=key)

    url = crypto.generate(
        width=300,
        height=200,
        smart=True,
        image_url=image,
        old=True
    )

    reg = "/([^/]+)/(.+)"
    options = re.match(reg, url).groups()[0]

    decrypted_url = thumbor_crypto.decrypt(options)

    assert decrypted_url
    assert decrypted_url['height'] == 200
    assert decrypted_url['width'] == 300
    assert decrypted_url['smart']
    assert decrypted_url['image_hash'] == hashlib.md5(image).hexdigest()
开发者ID:gerasim13,项目名称:libthumbor,代码行数:25,代码来源:test_libthumbor.py

示例5: thumb

    def thumb(self, image, **kwargs):
        url = image.url

        if not url:
            return None

        if settings.THUMBOR_BASE_URL:
            # If THUMBOR_BASE_URL is explicity set, use that
            base = settings.THUMBOR_BASE_URL
        else:
            # otherwise assume that thumbor is setup behind the same
            # CDN behind the `thumbor` namespace.
            scheme, netloc = urlparse.urlsplit(url)[:2]
            base = '{}://{}/thumbor'.format(scheme, netloc)
        crypto = CryptoURL(key=settings.THUMBOR_KEY)

        # just for code clarity
        thumbor_kwargs = kwargs
        if not 'fit_in' in thumbor_kwargs:
            thumbor_kwargs['fit_in'] = False

        thumbor_kwargs['image_url'] = url

        path = crypto.generate(**thumbor_kwargs)
        return u'{}{}'.format(base, path)
开发者ID:kk9599,项目名称:django-mediacat,代码行数:25,代码来源:thumbor.py

示例6: generate_thumbnail_url

def generate_thumbnail_url(path: str, size: str='0x0') -> str:
    if not (path.startswith('https://') or path.startswith('http://')):
        path = '/' + path

    if not is_thumbor_enabled():
        if path.startswith('http://'):
            return get_camo_url(path)
        return path

    if not user_uploads_or_external(path):
        return path

    source_type = get_source_type(path)
    safe_url = base64.urlsafe_b64encode(path.encode()).decode('utf-8')
    image_url = '%s/source_type/%s' % (safe_url, source_type)
    width, height = map(int, size.split('x'))
    crypto = CryptoURL(key=settings.THUMBOR_KEY)
    encrypted_url = crypto.generate(
        width=width,
        height=height,
        smart=True,
        filters=['no_upscale()', 'sharpen(0.5,0.2,true)'],
        image_url=image_url
    )

    if settings.THUMBOR_URL == 'http://127.0.0.1:9995':
        # If THUMBOR_URL is the default then thumbor is hosted on same machine
        # as the Zulip server and we should serve a relative URL.
        # We add a /thumbor in front of the relative url because we make
        # use of a proxy pass to redirect request internally in Nginx to 9995
        # port where thumbor is running.
        thumbnail_url = '/thumbor' + encrypted_url
    else:
        thumbnail_url = urllib.parse.urljoin(settings.THUMBOR_URL, encrypted_url)
    return thumbnail_url
开发者ID:brainwane,项目名称:zulip,代码行数:35,代码来源:thumbnail.py

示例7: 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

示例8: test_usage

def test_usage():
    key = "my-security-key"
    image = "s.glbimg.com/et/bb/f/original/2011/03/24/VN0JiwzmOw0b0lg.jpg"
    thumbor_crypto = Crypto(salt=key)

    thumbor_options = thumbor_crypto.encrypt(
        width=300,
        height=200,
        smart=True,
        fit_in=False,
        flip_horizontal=False,
        flip_vertical=False,
        halign='center',
        valign='middle',
        crop_left=0,
        crop_top=0,
        crop_right=0,
        crop_bottom=0,
        image=image
    )
    thumbor_url = "/%s/%s" % (thumbor_options, image)

    crypto = CryptoURL(key=key)

    url = crypto.generate(
        width=300,
        height=200,
        smart=True,
        image_url=image
    )

    assert url == thumbor_url
开发者ID:flaviamissi,项目名称:libthumbor,代码行数:32,代码来源:test_libthumbor.py

示例9: thumb

def thumb(img, **kwargs):
    '''
        returns a thumbor url for 'img' with **kwargs as thumbor options.

        Positional arguments:
        img -- can be a string representing the image path or any object with a url property.

        Keyword arguments:
        For the complete list of thumbor options
        https://github.com/globocom/thumbor/wiki/Usage
        and the actual implementation for the url generation
        https://github.com/heynemann/libthumbor/blob/master/libthumbor/url.py
    '''
    # url is DNS sharded url
    try:
        url = img.url
    except ValueError:
        # When trying to access the url of an image object when
        # the image does not exist, a ValueError is raised
        logger.exception("No file for object (%s) in thumbor", img.instance)
        return ''
    except AttributeError:
        # If it's an attribute error, assume it's a string already
        url = img

    if settings.THUMBOR_BASE_URL:
        # If THUMBOR_BASE_URL is explicity set, use that
        base = settings.THUMBOR_BASE_URL
    else:
        # otherwise assume that thumbor is setup behind the same
        # CDN behind the `thumbor` namespace.
        scheme, netloc = urlparse.urlsplit(url)[:2]
        base = '{}://{}/thumbor'.format(scheme, netloc)

    url = remove_url_scheme(url)

    # just for code clarity
    thumbor_kwargs = kwargs

    if 'fit_in' not in thumbor_kwargs:
        thumbor_kwargs['fit_in'] = True

    # normalizes url to make it work localy
    if settings.LOCAL:
        thumbor_kwargs['unsafe'] = True

        # strips 'media/' from the start of the url
        if url.startswith('media/'):
            url = url[len('media/'):]

        url = '{}/{}'.format(settings.AWS_S3_CUSTOM_DOMAIN, url)

    thumbor_kwargs['image_url'] = url

    crypto = CryptoURL(key=settings.THUMBOR_KEY)
    path = crypto.generate(**thumbor_kwargs).lstrip('/')

    return '{}/{}'.format(base, path)
开发者ID:nityaoberoi,项目名称:rateflix,代码行数:58,代码来源:thumborz.py

示例10: own_thumbnail

def own_thumbnail(m, s):
    global thumbor

    proto = 'http%s' % s
    thumbor_base = config.thumbor % { 'proto': proto }

    if thumbor is None:
        thumbor = CryptoURL(key=config.thumbor_key)
    return thumbor_base+thumbor.generate(image_url=m(0), **config.thumbor_pars)
开发者ID:border-radius,项目名称:bnw,代码行数:9,代码来源:linkshit_format.py

示例11: fit_in_urls

 def fit_in_urls(self, original_url, sizes):
     crypto = CryptoURL(key=self._config.THUMBOR_SECURITY_KEY)
     unschemed_original_url = original_url.replace('http://', '')
     urls = {}
     for size in sizes:
         split_size = size.split('x')
         path = crypto.generate(image_url=unschemed_original_url, width=split_size[0], height=split_size[1], fit_in=True)
         urls[size] = self._config.THUMBOR_SERVER_URL.rstrip('/') + path
     return urls
开发者ID:globocom,项目名称:impim-api,代码行数:9,代码来源:thumbor_url_service.py

示例12: test_can_auto_convert_jpeg_from_result_storage

    def test_can_auto_convert_jpeg_from_result_storage(self, context_mock):
        context_mock.return_value = self.context
        crypto = CryptoURL('ACME-SEC')
        url = crypto.generate(image_url=quote("http://test.com/smart/image.jpg"))
        self.context.request = self.get_request(url=url, accepts_webp=True)
        with open('./tests/fixtures/images/image.webp', 'r') as f:
            self.context.modules.result_storage.put(f.read())

        response = self.get_as_webp(url)
        expect(response.code).to_equal(200)
        expect(response.headers).to_include('Vary')
        expect(response.headers['Vary']).to_include('Accept')
        expect(response.body).to_be_webp()
开发者ID:scorphus,项目名称:thumbor,代码行数:13,代码来源:test_base_handler.py

示例13: test_thumbor_filter

 def test_thumbor_filter(self):
     testing.setUp(settings={
         'thumbor.security_key': 'foo',
     })
     crypto = CryptoURL(key='foo')
     self.assertEqual(
         thumbor_filter({}, 'image', 25, 25),
         crypto.generate(width=25, height=25, image_url='image'))
     self.assertEqual(
         thumbor_filter({}, 'image', 25),
         crypto.generate(width=25, image_url='image'))
     self.assertEqual(
         thumbor_filter({}, 'image', 25, None),
         crypto.generate(width=25, height=0, image_url='image'))
开发者ID:universalcore,项目名称:springboard,代码行数:14,代码来源:test_filters.py

示例14: thumbor_filter

def thumbor_filter(ctx, image, width, height=0):
    registry = get_current_registry(context=ctx)
    security_key = registry.settings.get('thumbor.security_key')
    if not all([security_key, image]):
        return ''

    # libthumbor generates an invalid url when height is None:
    # https://github.com/thumbor/libthumbor/blob/master/libthumbor/url.py#L19
    # Coerce it to 0. This scales the height proportionally.
    if height is None:
        height = 0

    crypto = CryptoURL(key=security_key)
    return crypto.generate(width=width, height=height, image_url=image)
开发者ID:universalcore,项目名称:springboard,代码行数:14,代码来源:filters.py

示例15: test_image_with_utf8_url

 def test_image_with_utf8_url(self):
     with open('./tests/fixtures/images/maracujá.jpg', 'r') as f:
         self.context.modules.storage.put(
             quote(u"http://test.com/maracujá.jpg".encode('utf-8')),
             f.read()
         )
     crypto = CryptoURL('ACME-SEC')
     image_url = self.get_url(
         quote(u"/unsafe/http://test.com/maracujá.jpg".encode('utf-8'))
     )
     url = crypto.generate(
         image_url=quote(image_url)
     )
     response = self.fetch(url)
     expect(response.code).to_equal(200)
开发者ID:scorphus,项目名称:thumbor,代码行数:15,代码来源:test_base_handler.py


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