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


Python CryptoURL.generate方法代码示例

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


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

示例1: GenerateWithUnsafeTestCase

# 需要导入模块: from libthumbor.crypto import CryptoURL [as 别名]
# 或者: from libthumbor.crypto.CryptoURL import generate [as 别名]
class GenerateWithUnsafeTestCase(TestCase):

    def setUp(self):
        self.crypto = CryptoURL(KEY)

    def test_should_pass_unsafe_to_generate_and_get_an_unsafe_url(self):
        url = self.crypto.generate(image_url=IMAGE_URL, crop=((10, 20), (30, 40)), unsafe=True)
        self.assertTrue(url.startswith('unsafe'), "url should starts with unsafe")

    def test_should_not_get_an_unsafe_url_when_unsafe_is_false(self):
        url = self.crypto.generate(image_url=IMAGE_URL, crop=((10, 20), (30, 40)), unsafe=False)
        self.assertFalse(url.startswith('unsafe'), "url should not starts with unsafe")
开发者ID:flaviamissi,项目名称:libthumbor,代码行数:14,代码来源:test_cryptourl.py

示例2: NewFormatUrl

# 需要导入模块: from libthumbor.crypto import CryptoURL [as 别名]
# 或者: from libthumbor.crypto.CryptoURL import generate [as 别名]
class NewFormatUrl(TestCase):
    def setUp(self):
        self.crypto = CryptoURL(KEY)

    def test_generated_url_1(self):
        url = self.crypto.generate(image_url=IMAGE_URL, width=300, height=200)
        assert url == '/8ammJH8D-7tXy6kU3lTvoXlhu4o=/300x200/my.server.com/some/path/to/image.jpg'

    def test_generated_url_2(self):
        url = self.crypto.generate(image_url=IMAGE_URL, width=300, height=200, crop=((10,10), (200,200)))
        assert url == '/B35oBEIwztbc3jm7vsdqLez2C78=/10x10:200x200/300x200/my.server.com/some/path/to/image.jpg'

    def test_generated_url_3(self):
        url = self.crypto.generate(image_url=IMAGE_URL, width=300, height=200, crop=((10,10), (200,200)), filters=("brightness(20)", "contrast(10)"))
        assert url == '/as8U2DbUUtTMgvPF26LkjS3MocY=/10x10:200x200/300x200/filters:brightness(20):contrast(10)/my.server.com/some/path/to/image.jpg'
开发者ID:EvandroLG,项目名称:libthumbor,代码行数:17,代码来源:test_cryptourl.py

示例3: test_decryption9

# 需要导入模块: from libthumbor.crypto import CryptoURL [as 别名]
# 或者: from libthumbor.crypto.CryptoURL import generate [as 别名]
def test_decryption9():
    '''test_decryption9
    Given
        A security key of 'my-security-key'
        And an image URL of "my.server.com/some/path/to/image.jpg"
        And a manual crop left-top point of (10, 20)
        And a manual crop right-bottom point of (30, 40)
    When
        I ask my library for an encrypted URL
        And I call the aforementioned 'decrypt_in_thumbor' method
    Then
        I get a decrypted dictionary that contains the following:
            crop['left'] = 10
            crop['top'] = 20
            crop['right'] = 30
            crop['bottom'] = 40
            image_hash = 84996242f65a4d864aceb125e1c4c5ba
    '''

    crypto = CryptoURL(KEY)
    url = crypto.generate(image_url=IMAGE_URL, crop=((10, 20), (30, 40)))
    decrypted = decrypt_in_thumbor(url)

    assert decrypted['crop']['left'] == 10
    assert decrypted['crop']['top'] == 20
    assert decrypted['crop']['right'] == 30
    assert decrypted['crop']['bottom'] == 40
    assert decrypted['image_hash'] == '84996242f65a4d864aceb125e1c4c5ba'
开发者ID:andrewsmedina,项目名称:libthumbor,代码行数:30,代码来源:test_cryptourl.py

示例4: test_passing_all_params

# 需要导入模块: from libthumbor.crypto import CryptoURL [as 别名]
# 或者: from libthumbor.crypto.CryptoURL import generate [as 别名]
        def test_passing_all_params(self):
            image_args = {
                'image_url': 'globo.com/media/img/my_image.jpg',
                'halign': 'left',
                'valign': 'middle',
                'meta': True,
                'smart': True,
                'width': 400,
                'height': 400,
                'flip': True,
                'flop': True
            }
            self.url_query.update(image_args)
            self.url_query.update({
                'crop_top': 100,
                'crop_left': 100,
                'crop_bottom': 200,
                'crop_right': 200
            })
            image_args.update({'crop': ((100, 100), (200, 200))})

            crypto = CryptoURL(settings.THUMBOR_SECURITY_KEY)

            response = self.client.get('/gen_url/?' + self.url_query.urlencode())

            assert HTTP_OK == response.status_code, "Got %d" % response.status_code
            assert response.content == b(settings.THUMBOR_SERVER + crypto.generate(**image_args).strip("/"))
开发者ID:nikvasilych,项目名称:libthumbor,代码行数:29,代码来源:test_generic_views.py

示例5: test_generate_url_with_params_via_get

# 需要导入模块: from libthumbor.crypto import CryptoURL [as 别名]
# 或者: from libthumbor.crypto.CryptoURL import generate [as 别名]
    def test_generate_url_with_params_via_get(self):
        crypto = CryptoURL(THUMBOR_SECURITY_KEY)

        response = self.get('/gen_url/', image_url='globo.com/media/img/my_image.jpg')

        assert HTTP_OK == response.code, "Got %d" % response.code
        assert response.body == THUMBOR_SERVER + crypto.generate(image_url='globo.com/media/img/my_image.jpg').strip("/")
开发者ID:bantana,项目名称:tornado-thumbor-url,代码行数:9,代码来源:test_handlers.py

示例6: test_generate_url_with_params_via_get

# 需要导入模块: from libthumbor.crypto import CryptoURL [as 别名]
# 或者: from libthumbor.crypto.CryptoURL import generate [as 别名]
        def test_generate_url_with_params_via_get(self):
            crypto = CryptoURL(settings.THUMBOR_SECURITY_KEY)
            image_args = {'image_url': 'globo.com/media/img/my_image.jpg'}
            self.url_query.update(image_args)

            response = self.client.get('/gen_url/?' + self.url_query.urlencode())

            assert HTTP_OK == response.status_code, "Got %d" % response.status_code
            assert response.content == b(settings.THUMBOR_SERVER + crypto.generate(**image_args).strip("/"))
开发者ID:nikvasilych,项目名称:libthumbor,代码行数:11,代码来源:test_generic_views.py

示例7: generate_url

# 需要导入模块: from libthumbor.crypto import CryptoURL [as 别名]
# 或者: from libthumbor.crypto.CryptoURL import generate [as 别名]
def generate_url(request):
    if request.method != 'GET':
        return HttpResponseNotAllowed(['GET'])

    crypto = CryptoURL(THUMBOR_SECURITY_KEY)

    args = request.GET
    args = dict(zip(map(str, args.keys()), args.values()))
    error_message = None

    try:
        if 'width' in args:
            args['width'] = int(args['width'])
    except ValueError as e:
        error_message = "The width value '%s' is not an integer." % \
            args['width']

    try:
        if 'height' in args:
            args['height'] = int(args['height'])
    except ValueError as e:
        error_message = "The height value '%s' is not an integer." % \
            args['height']

    try:
        if 'crop_top' in args or 'crop_left' in args or 'crop_right' in args or 'crop_bottom' in args:
            args['crop'] = (
                (int(args['crop_left']), int(args['crop_top'])),
                (int(args['crop_right']), int(args['crop_bottom']))
            )
    except KeyError as e:
        error_message = '''
            Missing values for cropping.
            Expected all 'crop_left', 'crop_top',
            'crop_right', 'crop_bottom' values.
        '''
    except ValueError as e:
        error_message = '''
            Invalid values for cropping.
            Expected all 'crop_left', 'crop_top',
            'crop_right', 'crop_bottom' to be integers.
        '''

    if error_message is not None:
        logging.warning(error_message)
        return HttpResponseBadRequest(error_message)

    try:
        return HttpResponse(THUMBOR_SERVER + crypto.generate(**args).strip("/"), content_type="text/plain")
    except (ValueError, KeyError) as e:
        error_message = str(e)
        logging.warning(error_message)
        return HttpResponseBadRequest(error_message)
开发者ID:aectann,项目名称:libthumbor,代码行数:55,代码来源:views.py

示例8: image

# 需要导入模块: from libthumbor.crypto import CryptoURL [as 别名]
# 或者: from libthumbor.crypto.CryptoURL import generate [as 别名]
 def image(self, **kwargs):
     with current_app.app_context():
         global crypto_url
         if crypto_url == None:
             crypto_url = CryptoURL(key=current_app.config['THUMBOR_SECURITY_KEY'])
         if self and len(self) > 0:
             _img = '/'.join(self.split('/')[2:])
             _url = urlparse(current_app.config['THUMBOR_HOST'])
             _url = '{u.scheme}://{u.netloc}'.format(u=_url)
             _img = crypto_url.generate(image_url=_img, **kwargs)
             _url = urljoin(_url, _img)
             return _url
     return ''
开发者ID:gerasim13,项目名称:libthumbor,代码行数:15,代码来源:field.py

示例9: test_decription2

# 需要导入模块: from libthumbor.crypto import CryptoURL [as 别名]
# 或者: from libthumbor.crypto.CryptoURL import generate [as 别名]
def test_decription2():
    '''test_decription2
    Given
        A security key of 'my-security-key'
        And an image URL of "my.server.com/some/path/to/image.jpg"
        And a width of 300
        And a height of 200
    When
        I ask my library for an encrypted URL
        And I call the aforementioned 'decrypt_in_thumbor' method
    Then
        I get a decrypted dictionary that contains the following:
            horizontal_flip = False
            vertical_flip = False
            smart = False
            fit_in = False
            meta = False
            crop['left'] = 0
            crop['top'] = 0
            crop['right'] = 0
            crop['bottom'] = 0
            valign = "middle"
            halign = "center"
            width = 300
            height = 200
            image_hash = 84996242f65a4d864aceb125e1c4c5ba
    '''
    crypto = CryptoURL(KEY)
    url = crypto.generate(image_url=IMAGE_URL, width=300, height=200)
    decrypted = decrypt_in_thumbor(url)

    assert decrypted['horizontal_flip'] == False
    assert decrypted['vertical_flip'] == False
    assert decrypted['smart'] == False
    assert decrypted['fit_in'] == False
    assert decrypted['meta'] == False
    assert decrypted['crop']['left'] == 0
    assert decrypted['crop']['top'] == 0
    assert decrypted['crop']['right'] == 0
    assert decrypted['crop']['bottom'] == 0
    assert decrypted['valign'] == "middle"
    assert decrypted['halign'] == "center"
    assert decrypted['width'] == 300
    assert decrypted['height'] == 200
    assert decrypted['image_hash'] == '84996242f65a4d864aceb125e1c4c5ba'
开发者ID:flaviamissi,项目名称:libthumbor,代码行数:47,代码来源:test_cryptourl.py

示例10: test_decryption1

# 需要导入模块: from libthumbor.crypto import CryptoURL [as 别名]
# 或者: from libthumbor.crypto.CryptoURL import generate [as 别名]
def test_decryption1():
    '''test_decryption1
    Given
        A security key of 'my-security-key'
        And an image URL of "my.server.com/some/path/to/image.jpg"
        And a width of 300
        And a height of 200
    When
        I ask my library for an encrypted URL
    Then
        I get
        '/l42l54VqaV_J-EcB5quNMP6CnsN9BX7htrh-QbPuDv0C7adUXX7LTo6DHm_woJtZ/my.server.com/some/path/to/image.jpg'
        as url
    '''
    crypto = CryptoURL(KEY)
    url = crypto.generate(image_url=IMAGE_URL, width=300, height=200)

    assert url == '/l42l54VqaV_J-EcB5quNMP6CnsN9BX7htrh-QbPuDv0C7adUXX7' + \
                  'LTo6DHm_woJtZ/my.server.com/some/path/to/image.jpg'
开发者ID:andrewsmedina,项目名称:libthumbor,代码行数:21,代码来源:test_cryptourl.py

示例11: test_decryption3

# 需要导入模块: from libthumbor.crypto import CryptoURL [as 别名]
# 或者: from libthumbor.crypto.CryptoURL import generate [as 别名]
def test_decryption3():
    '''test_decryption3
    Given
        A security key of 'my-security-key'
        And an image URL of "my.server.com/some/path/to/image.jpg"
        And the meta flag
    When
        I ask my library for an encrypted URL
        And I call the aforementioned 'decrypt_in_thumbor' method
    Then
        I get a decrypted dictionary that contains the following:
            meta = True
            image_hash = 84996242f65a4d864aceb125e1c4c5ba
    '''

    crypto = CryptoURL(KEY)
    url = crypto.generate(image_url=IMAGE_URL, meta=True)
    decrypted = decrypt_in_thumbor(url)

    assert decrypted['meta'] == True
    assert decrypted['image_hash'] == '84996242f65a4d864aceb125e1c4c5ba'
开发者ID:andrewsmedina,项目名称:libthumbor,代码行数:23,代码来源:test_cryptourl.py

示例12: test_decryption10

# 需要导入模块: from libthumbor.crypto import CryptoURL [as 别名]
# 或者: from libthumbor.crypto.CryptoURL import generate [as 别名]
def test_decryption10():
    '''test_decryption10
    Given
        A security key of 'my-security-key'
        And an image URL of "my.server.com/some/path/to/image.jpg"
        And a quality filter with 20% quality
        And a brightness filter with 10% improvement
    When
        I ask my library for an encrypted URL
        And I call the aforementioned 'decrypt_in_thumbor' method
    Then
        I get a decrypted dictionary that contains the following:
            filters = ["quality(20)", "brightness(10)"]
            image_hash = 84996242f65a4d864aceb125e1c4c5ba
    '''

    crypto = CryptoURL(KEY)
    url = crypto.generate(image_url=IMAGE_URL, filters=["quality(20)", "brightness(10)"], old=True)
    decrypted = decrypt_in_thumbor(url)

    assert "quality(20)" in decrypted['filters']
    assert "brightness(10)" in decrypted['filters']
    assert decrypted['image_hash'] == '84996242f65a4d864aceb125e1c4c5ba'
开发者ID:APSL,项目名称:libthumbor,代码行数:25,代码来源:test_cryptourl.py

示例13: generate_url

# 需要导入模块: from libthumbor.crypto import CryptoURL [as 别名]
# 或者: from libthumbor.crypto.CryptoURL import generate [as 别名]
 def generate_url(self, parameters):
     crypto = CryptoURL(self.settings['thumbor_security_key'])
     return crypto.generate(**parameters).strip("/")
开发者ID:bantana,项目名称:tornado-thumbor-url,代码行数:5,代码来源:handlers.py


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