本文整理汇总了Python中r2.lib.utils.UrlParser.path方法的典型用法代码示例。如果您正苦于以下问题:Python UrlParser.path方法的具体用法?Python UrlParser.path怎么用?Python UrlParser.path使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类r2.lib.utils.UrlParser
的用法示例。
在下文中一共展示了UrlParser.path方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: resize_image
# 需要导入模块: from r2.lib.utils import UrlParser [as 别名]
# 或者: from r2.lib.utils.UrlParser import path [as 别名]
def resize_image(self, image, width=None, file_type=None, censor_nsfw=False,
max_ratio=None):
url = UrlParser(image['url'])
is_gif = url.path.endswith('.gif') and (file_type == 'mp4' or not file_type)
if is_gif:
url.hostname = g.imgix_gif_domain
else:
url.hostname = g.imgix_domain
# Let's encourage HTTPS; it's cool, works just fine on HTTP pages, and
# will prevent insecure content warnings on HTTPS pages.
url.scheme = 'https'
# g.s3_media_direct affects how preview image urls are stored
# True: http://{s3_media_domain}/mybucket/helloworld.jpg
# False: http://mybucket/helloworld.jpg
# If it's True, we'll need to strip the bucket out of the path
if g.s3_media_direct:
path_parts = url.path.split('/')
path_parts.pop(1)
url.path = '/'.join(path_parts)
if max_ratio:
url.update_query(fit='crop')
# http://www.imgix.com/docs/reference/size#param-crop
url.update_query(crop='faces,entropy')
url.update_query(arh=max_ratio)
if width:
if width > image['width']:
raise NotLargeEnough()
# http://www.imgix.com/docs/reference/size#param-w
url.update_query(w=width)
if file_type and file_type in ('gif', 'jpg', 'png', 'mp4'):
url.update_query(fm=file_type)
# We need to disable fragmented mp4s for proper playback in Firefox
if file_type == 'mp4':
url.update_query(**{'mp4-fragmented': 'false'})
if censor_nsfw:
# Do an initial blur to make sure we're getting rid of icky
# details.
#
# http://www.imgix.com/docs/reference/stylize#param-blur
url.update_query(blur=600)
# And then add pixellation to help the image compress well.
#
# http://www.imgix.com/docs/reference/stylize#param-px
url.update_query(px=32)
if g.imgix_signing:
if is_gif:
url = self._sign_url(url, g.secrets['imgix_gif_signing_token'])
else:
url = self._sign_url(url, g.secrets['imgix_signing_token'])
return url.unparse()
示例2: test_same_url
# 需要导入模块: from r2.lib.utils import UrlParser [as 别名]
# 或者: from r2.lib.utils.UrlParser import path [as 别名]
def test_same_url(self):
u = UrlParser('http://example.com:8000/a;b?foo=bar&bar=baz#spam')
u2 = UrlParser('http://example.com:8000/a;b?bar=baz&foo=bar#spam')
self.assertEquals(u, u2)
u3 = UrlParser('')
u3.scheme = 'http'
u3.hostname = 'example.com'
u3.port = 8000
u3.path = '/a'
u3.params = 'b'
u3.update_query(foo='bar', bar='baz')
u3.fragment = 'spam'
self.assertEquals(u, u3)