本文整理匯總了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)