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


Python Bucket.get_website_endpoint方法代码示例

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


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

示例1: S3Bucket

# 需要导入模块: from boto.s3.bucket import Bucket [as 别名]
# 或者: from boto.s3.bucket.Bucket import get_website_endpoint [as 别名]
class S3Bucket(object):
    """A class for..."""

#===================================================================================================
#                                                                                       C L A S S

    LOCATIONS   = Location
    PUBLIC_READ = 'public-read'
    PRIVATE     = 'private'

    _UPLOAD_CONDITIONS = [
        '{"bucket":"%(bucket)s"}',
        '{"acl":"private"}',
        '{"key":"%(key)s"}',
        '{"success_action_status":"200"}',
        '["content-length-range", 0, %(maxSize)s]',
        '{"x-amz-meta-uuid": "14365123651274"}',
        '["starts-with", "$x-amz-meta-tag", ""]',
        '{"x-amz-algorithm": "AWS4-HMAC-SHA256"}',
        '{"x-amz-credential": "%(awsid)/%{isoDate}/%{region}/s3/aws4_request"}'
        '{"x-amz-date": "%{isoDate}T000000Z" }']

    _UPLOAD_POLICY = '{"expiration":"%s", "conditions":[%s]}'

#___________________________________________________________________________________________________ __init__
    def __init__(self, bucketName, awsId, awsSecret, location =None):
        """Creates a new instance of S3Bucket."""
        self._bucketName = bucketName
        self._awsId      = awsId
        self._awsSecret  = awsSecret

        if location:
            self._conn = s3.connect_to_region(
                region_name=location,
                aws_access_key_id=self._awsId,
                aws_secret_access_key=self._awsSecret,
                calling_format=boto.s3.connection.OrdinaryCallingFormat())
        else:
            self._conn = S3Connection(
                aws_access_key_id=self._awsId,
                aws_secret_access_key=self._awsSecret)

        self._bucket = Bucket(self._conn, bucketName)


#===================================================================================================
#                                                                                   G E T / S E T

#___________________________________________________________________________________________________ GS: bucketName
    @property
    def bucketName(self):
        return self._bucketName

#===================================================================================================
#                                                                                     P U B L I C

#___________________________________________________________________________________________________ generateUrl
    def generateUrl(self, keyName, secure =True, expires =0, expiresInHours =0, expiresInDays =0):
        """ Creates a url for the specified key name that expires in the specified number of
            seconds. Alternatively you can specify the expiresInHours or expiresInDays for easy
            conversion to alternate time periods. """
        if not expires:
            if expiresInHours:
                expires = int(3600.0*float(expiresInHours))
            elif expiresInDays:
                expires = int(24.0*3600.0*float(expiresInDays))

        if expires == 0:
            proto = 'http'
            if secure:
                proto += 's'
            return proto + '://' + self._bucket.get_website_endpoint() + '/' + keyName.lstrip('/')

        key = self.getKey(keyName, createIfMissing=True)
        return key.generate_url(
            expires_in=expires,
            query_auth=bool(expires > 0),
            force_http=not secure)

#___________________________________________________________________________________________________ listKeys
    def listKeys(self, path, pathFilter =None, includeDirs =True, includeFiles =True):
        if len(path) > 0 and path[0] == '/':
            path = path[1:]

        objs = self._bucket.list(path)
        out  = []
        for obj in objs:
            isDir = obj.name[-1] == '/' and obj.size == 0
            if isDir and not includeDirs:
                continue
            if not isDir and not includeFiles:
                continue

            if pathFilter is None or obj.name.find(pathFilter) != -1:
                out.append(obj)

        return out

#___________________________________________________________________________________________________ printBucketContents
    def printBucketContents(self, path, fileFilter, logger =None):
#.........这里部分代码省略.........
开发者ID:sernst,项目名称:PyAid,代码行数:103,代码来源:S3Bucket.py


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