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


Python connection.OrdinaryCallingFormat方法代码示例

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


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

示例1: __init__

# 需要导入模块: from boto.s3 import connection [as 别名]
# 或者: from boto.s3.connection import OrdinaryCallingFormat [as 别名]
def __init__(self, region, access_key, secret_key, bucket_name, secure=True, num_retries=5, socket_timeout=15,
                 **kwargs):
        self.region          = region
        self.access_key      = access_key
        self.secret_key      = secret_key
        self.secure          = secure
        self.num_retries     = num_retries
        self.socket_timeout  = socket_timeout
        self.validate_bucket = kwargs.get("validate_bucket")
        # monkey patch for bucket_name with dots
        # https://github.com/boto/boto/issues/2836
        if self.secure and '.' in bucket_name:
            self.calling_format = OrdinaryCallingFormat()
        else:
            self.calling_format = SubdomainCallingFormat()

        for section in boto.config.sections():
            boto.config.remove_section(section)
        boto.config.add_section('Boto')
        boto.config.setbool('Boto', 'is_secure', self.secure)
        boto.config.set('Boto', 'http_socket_timeout', str(self.socket_timeout))
        boto.config.set('Boto', 'num_retries', str(self.num_retries))

        self._conn = None
        self.connect() 
开发者ID:Percona-Lab,项目名称:mongodb_consistent_backup,代码行数:27,代码来源:S3Session.py

示例2: connect_walrus

# 需要导入模块: from boto.s3 import connection [as 别名]
# 或者: from boto.s3.connection import OrdinaryCallingFormat [as 别名]
def connect_walrus(host, aws_access_key_id=None, aws_secret_access_key=None,
                   port=8773, path='/services/Walrus', is_secure=False,
                   **kwargs):
    """
    Connect to a Walrus service.

    :type host: string
    :param host: the host name or ip address of the Walrus server

    :type aws_access_key_id: string
    :param aws_access_key_id: Your AWS Access Key ID

    :type aws_secret_access_key: string
    :param aws_secret_access_key: Your AWS Secret Access Key

    :rtype: :class:`boto.s3.connection.S3Connection`
    :return: A connection to Walrus
    """
    from boto.s3.connection import S3Connection
    from boto.s3.connection import OrdinaryCallingFormat

    return S3Connection(aws_access_key_id, aws_secret_access_key,
                        host=host, port=port, path=path,
                        calling_format=OrdinaryCallingFormat(),
                        is_secure=is_secure, **kwargs) 
开发者ID:canvasnetworks,项目名称:canvas,代码行数:27,代码来源:__init__.py

示例3: _get_s3bucket

# 需要导入模块: from boto.s3 import connection [as 别名]
# 或者: from boto.s3.connection import OrdinaryCallingFormat [as 别名]
def _get_s3bucket(host, bucket, access_key, secret_key, force_bucket_suffix=True, create_if_missing=True):
    from boto.s3.connection import S3Connection, OrdinaryCallingFormat, S3ResponseError

    s3con = S3Connection(aws_access_key_id=access_key,
                         aws_secret_access_key=secret_key,
                         host=host, is_secure=False,
                         calling_format=OrdinaryCallingFormat())
    # add access key prefix to bucket name, unless explicitly prohibited
    if force_bucket_suffix and not bucket.lower().endswith('-' + access_key.lower()):
        bucket = bucket + '-' + access_key.lower()
    try:
        return s3con.get_bucket(bucket)
    except S3ResponseError as ex:
        if ex.status == 404:
            if create_if_missing:
                return s3con.create_bucket(bucket)
            else:
                raise IOError("Bucket {} does not exist".format(bucket))
        raise 
开发者ID:JDASoftwareGroup,项目名称:storefact,代码行数:21,代码来源:_boto.py

示例4: connect_walrus

# 需要导入模块: from boto.s3 import connection [as 别名]
# 或者: from boto.s3.connection import OrdinaryCallingFormat [as 别名]
def connect_walrus(host=None, aws_access_key_id=None,
                   aws_secret_access_key=None,
                   port=8773, path='/services/Walrus', is_secure=False,
                   **kwargs):
    """
    Connect to a Walrus service.

    :type host: string
    :param host: the host name or ip address of the Walrus server

    :type aws_access_key_id: string
    :param aws_access_key_id: Your AWS Access Key ID

    :type aws_secret_access_key: string
    :param aws_secret_access_key: Your AWS Secret Access Key

    :rtype: :class:`boto.s3.connection.S3Connection`
    :return: A connection to Walrus
    """
    from boto.s3.connection import S3Connection
    from boto.s3.connection import OrdinaryCallingFormat

    # Check for values in boto config, if not supplied as args
    if not aws_access_key_id:
        aws_access_key_id = config.get('Credentials',
                                       'euca_access_key_id',
                                       None)
    if not aws_secret_access_key:
        aws_secret_access_key = config.get('Credentials',
                                           'euca_secret_access_key',
                                           None)
    if not host:
        host = config.get('Boto', 'walrus_host', None)

    return S3Connection(aws_access_key_id, aws_secret_access_key,
                        host=host, port=port, path=path,
                        calling_format=OrdinaryCallingFormat(),
                        is_secure=is_secure, **kwargs) 
开发者ID:VirtueSecurity,项目名称:aws-extender,代码行数:40,代码来源:__init__.py

示例5: connect_ia

# 需要导入模块: from boto.s3 import connection [as 别名]
# 或者: from boto.s3.connection import OrdinaryCallingFormat [as 别名]
def connect_ia(ia_access_key_id=None, ia_secret_access_key=None,
               is_secure=False, **kwargs):
    """
    Connect to the Internet Archive via their S3-like API.

    :type ia_access_key_id: string
    :param ia_access_key_id: Your IA Access Key ID.  This will also look
        in your boto config file for an entry in the Credentials
        section called "ia_access_key_id"

    :type ia_secret_access_key: string
    :param ia_secret_access_key: Your IA Secret Access Key.  This will also
        look in your boto config file for an entry in the Credentials
        section called "ia_secret_access_key"

    :rtype: :class:`boto.s3.connection.S3Connection`
    :return: A connection to the Internet Archive
    """
    from boto.s3.connection import S3Connection
    from boto.s3.connection import OrdinaryCallingFormat

    access_key = config.get('Credentials', 'ia_access_key_id',
                            ia_access_key_id)
    secret_key = config.get('Credentials', 'ia_secret_access_key',
                            ia_secret_access_key)

    return S3Connection(access_key, secret_key,
                        host='s3.us.archive.org',
                        calling_format=OrdinaryCallingFormat(),
                        is_secure=is_secure, **kwargs) 
开发者ID:VirtueSecurity,项目名称:aws-extender,代码行数:32,代码来源:__init__.py

示例6: get_boto_connection

# 需要导入模块: from boto.s3 import connection [as 别名]
# 或者: from boto.s3.connection import OrdinaryCallingFormat [as 别名]
def get_boto_connection(aws_access_key_id, aws_secret_access_key, region=None, bucketname=None,
                        host=None):
    """
    Conection parameters must be different only if bucket name has a period
    """
    m = _AWS_ACCESS_KEY_ID_RE.match(aws_access_key_id)
    if m is None or m.group() != aws_access_key_id:
        logging.error('The provided aws_access_key_id is not in the correct format. It must \
                      be alphanumeric and contain between 16 and 32 characters.')

    if len(aws_access_key_id) > len(aws_secret_access_key):
        logging.warn("The AWS credential keys aren't in the usual size,"
                     " are you using the correct ones?")

    import boto
    from boto.s3.connection import OrdinaryCallingFormat
    extra_args = {}
    if host is not None:
        extra_args['host'] = host
    if bucketname is not None and '.' in bucketname:
        extra_args['calling_format'] = OrdinaryCallingFormat()
    if region is None:
        return boto.connect_s3(aws_access_key_id, aws_secret_access_key, **extra_args)
    return boto.s3.connect_to_region(region, aws_access_key_id=aws_access_key_id,
                                     aws_secret_access_key=aws_secret_access_key,
                                     **extra_args) 
开发者ID:scrapinghub,项目名称:exporters,代码行数:28,代码来源:utils.py

示例7: open_s3

# 需要导入模块: from boto.s3 import connection [as 别名]
# 或者: from boto.s3.connection import OrdinaryCallingFormat [as 别名]
def open_s3(self):
        """
        Opens connection to S3 returning bucket and key
        """
        conn = boto.connect_s3(
            self.AWS_ACCESS_KEY_ID,
            self.AWS_SECRET_ACCESS_KEY,
            is_secure=True,
            calling_format=OrdinaryCallingFormat() 
        )
        try:
            bucket = conn.get_bucket(self.AWS_STORAGE_BUCKET_NAME)
        except boto.exception.S3ResponseError:
            bucket = conn.create_bucket(self.AWS_STORAGE_BUCKET_NAME)
        return bucket, boto.s3.key.Key(bucket) 
开发者ID:skoczen,项目名称:mindful-browsing,代码行数:17,代码来源:fabfile.py

示例8: _get_boto_client

# 需要导入模块: from boto.s3 import connection [as 别名]
# 或者: from boto.s3.connection import OrdinaryCallingFormat [as 别名]
def _get_boto_client(cluster, access_key, secret_key):
    """
    Returns a boto client object that can be used to communicate with the Object
    Storage cluster.
    """
    client = boto.connect_s3(aws_access_key_id=access_key,
                             aws_secret_access_key=secret_key,
                             host=BASE_URL_TEMPLATE.format(cluster),
                             calling_format=OrdinaryCallingFormat())

    # set this for later use
    client.obj_cluster = cluster

    return client 
开发者ID:linode,项目名称:linode-cli,代码行数:16,代码来源:obj.py

示例9: authenticate

# 需要导入模块: from boto.s3 import connection [as 别名]
# 或者: from boto.s3.connection import OrdinaryCallingFormat [as 别名]
def authenticate(self, calling_format=None):
        access_key_id = self.account_username()
        secret_access_key = self.options.get('SECRET_ACCESS_KEY', '')
        bucket = self.account_container()
        kwargs = {'calling_format': calling_format} if calling_format else {}
        try:
            self.d['connection'] = S3Connection(access_key_id,
                                                secret_access_key, **kwargs)
            self.d['bucket'] = self.d['connection'].get_bucket(bucket)
        except CertificateError as e:
            # work-around for upstream boto bug for buckets containing dots:
            # https://github.com/boto/boto/issues/2836
            if calling_format:
                raise e
            self.authenticate(calling_format=OrdinaryCallingFormat()) 
开发者ID:meeb,项目名称:django-distill,代码行数:17,代码来源:amazon_s3.py

示例10: connect_ia

# 需要导入模块: from boto.s3 import connection [as 别名]
# 或者: from boto.s3.connection import OrdinaryCallingFormat [as 别名]
def connect_ia(ia_access_key_id=None, ia_secret_access_key=None,
               is_secure=False, **kwargs):
    """
    Connect to the Internet Archive via their S3-like API.

    :type ia_access_key_id: string
    :param ia_access_key_id: Your IA Access Key ID.  This will also look in your
                             boto config file for an entry in the Credentials
                             section called "ia_access_key_id"

    :type ia_secret_access_key: string
    :param ia_secret_access_key: Your IA Secret Access Key.  This will also look in your
                                 boto config file for an entry in the Credentials
                                 section called "ia_secret_access_key"

    :rtype: :class:`boto.s3.connection.S3Connection`
    :return: A connection to the Internet Archive
    """
    from boto.s3.connection import S3Connection
    from boto.s3.connection import OrdinaryCallingFormat

    access_key = config.get('Credentials', 'ia_access_key_id',
                            ia_access_key_id)
    secret_key = config.get('Credentials', 'ia_secret_access_key',
                            ia_secret_access_key)

    return S3Connection(access_key, secret_key,
                        host='s3.us.archive.org',
                        calling_format=OrdinaryCallingFormat(),
                        is_secure=is_secure, **kwargs) 
开发者ID:canvasnetworks,项目名称:canvas,代码行数:32,代码来源:__init__.py

示例11: connect

# 需要导入模块: from boto.s3 import connection [as 别名]
# 或者: from boto.s3.connection import OrdinaryCallingFormat [as 别名]
def connect(self, access_key_id=None, secret_access_key=None, **kwargs):
        """
        Opens a connection to appropriate provider, depending on provider
        portion of URI. Requires Credentials defined in boto config file (see
        boto/pyami/config.py).
        @type storage_uri: StorageUri
        @param storage_uri: StorageUri specifying a bucket or a bucket+object
        @rtype: L{AWSAuthConnection<boto.gs.connection.AWSAuthConnection>}
        @return: A connection to storage service provider of the given URI.
        """

        connection_args = dict(self.connection_args or ())
        # Use OrdinaryCallingFormat instead of boto-default
        # SubdomainCallingFormat because the latter changes the hostname
        # that's checked during cert validation for HTTPS connections,
        # which will fail cert validation (when cert validation is enabled).
        # Note: the following import can't be moved up to the start of
        # this file else it causes a config import failure when run from
        # the resumable upload/download tests.
        from boto.s3.connection import OrdinaryCallingFormat
        connection_args['calling_format'] = OrdinaryCallingFormat()
        connection_args.update(kwargs)
        if not self.connection:
            if self.scheme == 's3':
                from boto.s3.connection import S3Connection
                self.connection = S3Connection(access_key_id,
                                               secret_access_key,
                                               **connection_args)
            elif self.scheme == 'gs':
                from boto.gs.connection import GSConnection
                self.connection = GSConnection(access_key_id,
                                               secret_access_key,
                                               **connection_args)
            elif self.scheme == 'file':
                from boto.file.connection import FileConnection
                self.connection = FileConnection(self)
            else:
                raise InvalidUriError('Unrecognized scheme "%s"' %
                                      self.scheme)
        self.connection.debug = self.debug
        return self.connection 
开发者ID:canvasnetworks,项目名称:canvas,代码行数:43,代码来源:storage_uri.py

示例12: connect_s3

# 需要导入模块: from boto.s3 import connection [as 别名]
# 或者: from boto.s3.connection import OrdinaryCallingFormat [as 别名]
def connect_s3(host, port, bucket_name):
    is_secure = port == 443
    conn = S3Connection(
        os.environ['AWS_ACCESS_KEY_ID'],
        os.environ['AWS_SECRET_ACCESS_KEY'],
        is_secure=is_secure,
        port=port,
        host=host,
        calling_format=OrdinaryCallingFormat()
    )

    conn.create_bucket(bucket_name)
    return conn.get_bucket(bucket_name) 
开发者ID:osm2vectortiles,项目名称:osm2vectortiles,代码行数:15,代码来源:export_remote.py

示例13: handle

# 需要导入模块: from boto.s3 import connection [as 别名]
# 或者: from boto.s3.connection import OrdinaryCallingFormat [as 别名]
def handle(self, *args, **options):
        ids = [79, 328, 329, 383, 407, 516, 598, 602, 679, 680, 736, 817, 841, 842, 843, 844, 845, 846, 847, 848, 849, 850, 851, 852, 853, 857, 1025, 2138, 2405, 2597, 2713, 2885, 3344, 3987, 4110, 4252, 4653, 4742, 4743, 4744, 4745, 4746, 5019, 5110, 5216, 5217, 5218, 6007, 6009, 6026, 6802, 6803, 6804, 6809, 6810, 6811, 6818, 6819, 6820, 6821, 6822, 6839, 6840, 6842, 6874, 6875, 6876, 6877, 6878, 6879, 6880, 6881, 6882, 7013, 7209, 7211, 7369, 7630, 8727, 11008, 11009, 11010, 11011, 11012, 11013, 11014, 11015, 11016, 11017, 11018, 11019, 11020, 11021, 11022, 11023, 11024, 11025, 11026, 11027, 11028, 11029, 11030, 11031, 11032, 11033, 11034, 11035, 11036, 11037, 11038, 11039, 11040, 11041, 11042, 11043, 11044, 11045, 11046, 11047, 11048, 11049, 11050, 11051, 11052, 11053, 11054, 11055, 11056, 11057, 11058, 11059, 11060, 11061, 11062, 11063, 12173, 14799, 16364, 16976, 17166, 17274, 17275, 17276, 17278, 17281, 21851, 21864, 21919, 22009, 22038, 23336, 23337, 25799, 27277, 29572, 30730, 31180, 31181, 31182, 31183, 31185, 31186, 31189, 31190, 31191, 31193, 31194, 31195, 31196, 31197, 31198, 31199, 31200, 31201, 31202, 31204, 31205, 31206, 31207, 31208, 31209, 31210, 31211, 31212, 31213, 31214, 31215, 31217, 31218, 31219, 31220, 31221, 31222, 31223, 31224, 31225, 31226, 31227, 31228, 32260, 32262, 34471, 36447, 36448, 36676, 36678, 36679, 36680, 36681]

        # Match the files which aren't UUIDs.
        exp = re.compile(r'^uploads\/replay_files\/[A-F0-9]{8}4[A-F0-9]{23}\.replay$')

        conn = boto.s3.connect_to_region('eu-west-1', aws_access_key_id=os.getenv('AWS_ACCESS_KEY_ID'), aws_secret_access_key=os.getenv('AWS_SECRET_ACCESS_KEY'), calling_format=OrdinaryCallingFormat())
        bucket = conn.get_bucket('media.rocketleaguereplays.com')
        s3_files = [
            key.name.replace('uploads/replay_files/', '')
            for key in bucket.list(prefix='uploads/replay_files')
            if re.match(exp, key.name) is None and
            key.name != 'uploads/replay_files/'
        ]

        # Now we need to parse the header for each of these files and determine
        # what their replay ID is.

        replay_mappings = {}

        for s3_file in s3_files:
            local_file_path = os.path.join(settings.MEDIA_ROOT, 'uploads/replay_files', s3_file)

            with open(local_file_path, 'rb') as f:
                try:
                    replay = Replay(f.read())
                    replay_mappings[replay.header['Id']] = s3_file
                except:
                    pass

        for i in ids:
            r = ReplayModel.objects.get(pk=i)

            if r.replay_id in replay_mappings:
                print('Replay.objects.get(pk={}).update(file="uploads/replay_files/{}")'.format(i, replay_mappings[r.replay_id]))
            else:
                print('#', i, 'not found :(') 
开发者ID:rocket-league-replays,项目名称:rocket-league-replays,代码行数:39,代码来源:fix_replays.py

示例14: connect

# 需要导入模块: from boto.s3 import connection [as 别名]
# 或者: from boto.s3.connection import OrdinaryCallingFormat [as 别名]
def connect(self):
        """
            Establishes the actual connection to the referred RSE.

            :param: credentials needed to establish a connection with the stroage.

            :raises RSEAccessDenied: if no connection could be established.
        """
        try:
            scheme, prefix = self.attributes.get('scheme'), self.attributes.get('prefix')
            netloc, port = self.attributes['hostname'], self.attributes.get('port', 80)
            service_url = '%(scheme)s://%(netloc)s:%(port)s' % locals()

            access_key, secret_key, is_secure = None, None, None
            if 'S3_ACCESS_KEY' in os.environ:
                access_key = os.environ['S3_ACCESS_KEY']
            if 'S3_SECRET_KEY' in os.environ:
                secret_key = os.environ['S3_SECRET_KEY']
            if 'S3_IS_SECURE' in os.environ:
                if str(os.environ['S3_IS_SECURE']).lower() == 'true':
                    is_secure = True
                elif str(os.environ['S3_IS_SECURE']).lower() == 'false':
                    is_secure = False

            if is_secure is None or access_key is None or secret_key is None:
                credentials = get_rse_credentials()
                self.rse['credentials'] = credentials.get(self.rse['rse'])

                if not access_key:
                    access_key = self.rse['credentials']['access_key']
                if not secret_key:
                    secret_key = self.rse['credentials']['secret_key']
                if not is_secure:
                    is_secure = self.rse['credentials'].get('is_secure', {}).\
                        get(service_url, False)

            self._disable_http_proxy()
            self.__conn = connect_s3(host=self.attributes['hostname'],
                                     port=int(port),
                                     aws_access_key_id=access_key,
                                     aws_secret_access_key=secret_key,
                                     is_secure=is_secure,
                                     calling_format=OrdinaryCallingFormat())
            self._reset_http_proxy()
        except Exception as e:
            self._reset_http_proxy()
            raise exception.RSEAccessDenied(e) 
开发者ID:rucio,项目名称:rucio,代码行数:49,代码来源:s3boto.py

示例15: __init__

# 需要导入模块: from boto.s3 import connection [as 别名]
# 或者: from boto.s3.connection import OrdinaryCallingFormat [as 别名]
def __init__(self, **kwargs):
        """
            - create the conn object
            - create the bucket (if it doesn't exist)
                - if not given, awsaccessKey_nmapreport
            - may raise exception (ie in case of conflict bucket name)
            - sample :
            To connect to walrus:
            from libnmap.plugins.backendpluginFactory import
                            BackendPluginFactory
            walrusBackend =
              BackendPluginFactory.create(
                    plugin_name='s3',
                    host="walrus.ecc.eucalyptus.com",
                    path="/services/Walrus",port=8773,
                    is_secure=False,
                    aws_access_key_id='UU72FLVJCAYRATLXI70YH',
                    aws_secret_access_key=
                               'wFg7gP5YFHjVlxakw1g1uCC8UR2xVW5ax9ErZCut')
           To connect to S3:
           mybackend_S3 =
             BackendPluginFactory.create(
                plugin_name='s3',
                is_secure=True,
                aws_access_key_id='MYACCESSKEY',
                aws_secret_access_key='MYSECRET')
        """
        NmapBackendPlugin.__init__(self)
        try:
            calling_format = OrdinaryCallingFormat()
            if 'bucket' not in kwargs:
                self.bucket_name = ''.join(
                    [kwargs['aws_access_key_id'].lower(),
                     "_nmapreport"])
            else:
                self.bucket_name = kwargs['bucket']
                del kwargs['bucket']
            kwargs['calling_format'] = calling_format
            self.conn = S3Connection(**kwargs)
            self.bucket = self.conn.lookup(self.bucket_name)
            if self.bucket is None:
                self.bucket = self.conn.create_bucket(self.bucket_name)
        except:
            raise 
开发者ID:imiyoo2010,项目名称:teye_scanner_for_book,代码行数:46,代码来源:s3.py


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