本文整理汇总了Python中django.utils.encoding.filepath_to_uri方法的典型用法代码示例。如果您正苦于以下问题:Python encoding.filepath_to_uri方法的具体用法?Python encoding.filepath_to_uri怎么用?Python encoding.filepath_to_uri使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.utils.encoding
的用法示例。
在下文中一共展示了encoding.filepath_to_uri方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: url
# 需要导入模块: from django.utils import encoding [as 别名]
# 或者: from django.utils.encoding import filepath_to_uri [as 别名]
def url(self, name, parameters=None, expire=None, http_method=None):
# Preserve the trailing slash after normalizing the path.
name = self._normalize_name(self._clean_name(name))
if expire is None:
expire = self.querystring_expire
if self.custom_domain:
url = "{}//{}/{}".format(
self.url_protocol, self.custom_domain, filepath_to_uri(name))
if self.querystring_auth and self.cloudfront_signer:
expiration = datetime.utcnow() + timedelta(seconds=expire)
return self.cloudfront_signer.generate_presigned_url(url, date_less_than=expiration)
return url
params = parameters.copy() if parameters else {}
params['Bucket'] = self.bucket.name
params['Key'] = name
url = self.bucket.meta.client.generate_presigned_url('get_object', Params=params,
ExpiresIn=expire, HttpMethod=http_method)
if self.querystring_auth:
return url
return self._strip_signing_parameters(url)
示例2: url
# 需要导入模块: from django.utils import encoding [as 别名]
# 或者: from django.utils.encoding import filepath_to_uri [as 别名]
def url(self, name, expire=None):
name = self._get_valid_path(name)
if expire is None:
expire = self.expiration_secs
make_blob_url_kwargs = {}
if expire:
sas_token = self.custom_service.generate_blob_shared_access_signature(
self.azure_container, name, permission=BlobPermissions.READ, expiry=self._expire_at(expire))
make_blob_url_kwargs['sas_token'] = sas_token
return self.custom_service.make_blob_url(
container_name=self.azure_container,
blob_name=filepath_to_uri(name),
protocol=self.azure_protocol,
**make_blob_url_kwargs)
示例3: url
# 需要导入模块: from django.utils import encoding [as 别名]
# 或者: from django.utils.encoding import filepath_to_uri [as 别名]
def url(self, name):
if self.base_url is None:
raise ValueError("This file is not accessible via a URL.")
gridfs, filename = self._get_gridfs(name)
try:
file_oid = gridfs.get_last_version(filename=name).__getattr__('_id')
except NoFile:
# In case not found by filename
try:
# Check is a valid ObjectId
file_oid = ObjectId(name)
except (InvalidId, TypeError, ValueError):
return None
# Check if exist a file with that ObjectId
if not gridfs.exists(file_oid):
return None
return urljoin(self.base_url, filepath_to_uri(str(file_oid)))
示例4: url
# 需要导入模块: from django.utils import encoding [as 别名]
# 或者: from django.utils.encoding import filepath_to_uri [as 别名]
def url(self, name):
if self.base_url is None:
raise ValueError("This file is not accessible via a URL.")
return urljoin(self.base_url, filepath_to_uri(name))
示例5: url
# 需要导入模块: from django.utils import encoding [as 别名]
# 或者: from django.utils.encoding import filepath_to_uri [as 别名]
def url(self, name):
name = self._normalize_name(self._clean_name(name))
name = filepath_to_uri(name)
protocol = u'https://' if self.secure_url else u'http://'
return urljoin(protocol + self.bucket_domain, name)
示例6: get_thumbnail_url
# 需要导入模块: from django.utils import encoding [as 别名]
# 或者: from django.utils.encoding import filepath_to_uri [as 别名]
def get_thumbnail_url(self):
"""
Returns the (absolute) URL for the image's thumbnail version.
"""
return urljoin(settings.MEDIA_URL, filepath_to_uri(self.get_thumbnail_path()))
示例7: url
# 需要导入模块: from django.utils import encoding [as 别名]
# 或者: from django.utils.encoding import filepath_to_uri [as 别名]
def url(self, name, parameters=None, expire=None):
url = super().url(name, parameters, expire)
if hasattr(settings, 'AWS_PRIVATE_CUSTOM_DOMAIN'):
# Django storage doesn't handle custom domains with auth strings
custom_domain = settings.AWS_PRIVATE_CUSTOM_DOMAIN
parts = list(parse.urlsplit(url))
parts[1:3] = custom_domain, filepath_to_uri(name)
return parse.urlunsplit(parts)
return url
示例8: url
# 需要导入模块: from django.utils import encoding [as 别名]
# 或者: from django.utils.encoding import filepath_to_uri [as 别名]
def url(self, name):
if self.base_url is None:
raise ValueError("This file is not accessible via a URL.")
url = filepath_to_uri(name)
if url is not None:
url = url.lstrip('/')
return urljoin(self.base_url, url)
示例9: url
# 需要导入模块: from django.utils import encoding [as 别名]
# 或者: from django.utils.encoding import filepath_to_uri [as 别名]
def url(self, name):
name = self._normalize_name(self._clean_name(name))
# name = filepath_to_uri(name) # 这段会导致二次encode
name = name.encode('utf8')
# 做这个转化,是因为下面的_make_url会用urllib.quote转码,转码不支持unicode,会报错,在python2环境下。
return self.bucket._make_url(self.bucket_name, name)