當前位置: 首頁>>代碼示例>>Python>>正文


Python encoding.filepath_to_uri方法代碼示例

本文整理匯總了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) 
開發者ID:jschneier,項目名稱:django-storages,代碼行數:27,代碼來源:s3boto3.py

示例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) 
開發者ID:jschneier,項目名稱:django-storages,代碼行數:19,代碼來源:azure_storage.py

示例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))) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:19,代碼來源:storage.py

示例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)) 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:6,代碼來源:storage.py

示例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) 
開發者ID:glasslion,項目名稱:django-qiniu-storage,代碼行數:7,代碼來源:backends.py

示例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())) 
開發者ID:fausecteam,項目名稱:ctf-gameserver,代碼行數:7,代碼來源:fields.py

示例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 
開發者ID:OpenTechFund,項目名稱:hypha,代碼行數:13,代碼來源:storage_backends.py

示例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) 
開發者ID:neon-jungle,項目名稱:wagtailvideos,代碼行數:9,代碼來源:storage.py

示例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) 
開發者ID:xiewenya,項目名稱:django-aliyun-oss2-storage,代碼行數:8,代碼來源:backends.py


注:本文中的django.utils.encoding.filepath_to_uri方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。