本文整理汇总了Python中botocore.compat.six.string_types方法的典型用法代码示例。如果您正苦于以下问题:Python six.string_types方法的具体用法?Python six.string_types怎么用?Python six.string_types使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类botocore.compat.six
的用法示例。
在下文中一共展示了six.string_types方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: upload_file
# 需要导入模块: from botocore.compat import six [as 别名]
# 或者: from botocore.compat.six import string_types [as 别名]
def upload_file(self, filename, bucket, key,
callback=None, extra_args=None):
"""Upload a file to an S3 object.
Variants have also been injected into S3 client, Bucket and Object.
You don't have to use S3Transfer.upload_file() directly.
"""
if not isinstance(filename, six.string_types):
raise ValueError('Filename must be a string')
subscribers = self._get_subscribers(callback)
future = self._manager.upload(
filename, bucket, key, extra_args, subscribers)
try:
future.result()
# If a client error was raised, add the backwards compatibility layer
# that raises a S3UploadFailedError. These specific errors were only
# ever thrown for upload_parts but now can be thrown for any related
# client error.
except ClientError as e:
raise S3UploadFailedError(
"Failed to upload %s to %s: %s" % (
filename, '/'.join([bucket, key]), e))
示例2: download_file
# 需要导入模块: from botocore.compat import six [as 别名]
# 或者: from botocore.compat.six import string_types [as 别名]
def download_file(self, bucket, key, filename, extra_args=None,
callback=None):
"""Download an S3 object to a file.
Variants have also been injected into S3 client, Bucket and Object.
You don't have to use S3Transfer.download_file() directly.
"""
if not isinstance(filename, six.string_types):
raise ValueError('Filename must be a string')
subscribers = self._get_subscribers(callback)
future = self._manager.download(
bucket, key, filename, extra_args, subscribers)
try:
future.result()
# This is for backwards compatibility where when retries are
# exceeded we need to throw the same error from boto3 instead of
# s3transfer's built in RetriesExceededError as current users are
# catching the boto3 one instead of the s3transfer exception to do
# their own retries.
except S3TransferRetriesExceededError as e:
raise RetriesExceededError(e.last_exception)
示例3: _convert_to_string
# 需要导入模块: from botocore.compat import six [as 别名]
# 或者: from botocore.compat.six import string_types [as 别名]
def _convert_to_string(data):
scalar_types = six.string_types + six.integer_types
if isinstance(data, six.binary_type):
if sys.version_info[0] >= 3:
return data.decode('utf8')
else:
return data
elif isinstance(data, six.text_type):
if sys.version_info[0] >= 3:
return data
else:
return data.encode('utf8')
elif isinstance(data, scalar_types) or hasattr(data, '__str__'):
return str(data)
else:
LOG.error('echo called with an unsupported data type')
LOG.debug('data class = ' + data.__class__.__name__)
示例4: _extract_paging_params
# 需要导入模块: from botocore.compat import six [as 别名]
# 或者: from botocore.compat.six import string_types [as 别名]
def _extract_paging_params(self, kwargs):
pagination_config = kwargs.pop('PaginationConfig', {})
max_items = pagination_config.get('MaxItems', None)
if max_items is not None:
max_items = int(max_items)
page_size = pagination_config.get('PageSize', None)
if page_size is not None:
if self._limit_key is None:
raise PaginationError(
message="PageSize parameter is not supported for the "
"pagination interface for this operation.")
input_members = self._model.input_shape.members
limit_key_shape = input_members.get(self._limit_key)
if limit_key_shape.type_name == 'string':
if not isinstance(page_size, six.string_types):
page_size = str(page_size)
else:
page_size = int(page_size)
return {
'MaxItems': max_items,
'StartingToken': pagination_config.get('StartingToken', None),
'PageSize': page_size,
}
示例5: __init__
# 需要导入模块: from botocore.compat import six [as 别名]
# 或者: from botocore.compat.six import string_types [as 别名]
def __init__(self, data, parent=None):
super(DataNode, self).__init__(parent)
if not isinstance(data, six.string_types):
raise ValueError("Expecting string type, %s given." % type(data))
self.data = data
示例6: _get_body_as_dict
# 需要导入模块: from botocore.compat import six [as 别名]
# 或者: from botocore.compat.six import string_types [as 别名]
def _get_body_as_dict(self, request):
# For query services, request.data is form-encoded and is already a
# dict, but for other services such as rest-json it could be a json
# string or bytes. In those cases we attempt to load the data as a
# dict.
data = request.data
if isinstance(data, six.binary_type):
data = json.loads(data.decode('utf-8'))
elif isinstance(data, six.string_types):
data = json.loads(data)
return data
示例7: is_compatible
# 需要导入模块: from botocore.compat import six [as 别名]
# 或者: from botocore.compat.six import string_types [as 别名]
def is_compatible(cls, download_target, osutil):
return isinstance(download_target, six.string_types)
示例8: is_compatible
# 需要导入模块: from botocore.compat import six [as 别名]
# 或者: from botocore.compat.six import string_types [as 别名]
def is_compatible(cls, upload_source):
return isinstance(upload_source, six.string_types)
示例9: _is_string
# 需要导入模块: from botocore.compat import six [as 别名]
# 或者: from botocore.compat.six import string_types [as 别名]
def _is_string(self, value):
if isinstance(value, six.string_types):
return True
return False
示例10: _handle_first_request
# 需要导入模块: from botocore.compat import six [as 别名]
# 或者: from botocore.compat.six import string_types [as 别名]
def _handle_first_request(self, parsed, primary_result_key,
starting_truncation):
# If the payload is an array or string, we need to slice into it
# and only return the truncated amount.
starting_truncation = self._parse_starting_token()[1]
all_data = primary_result_key.search(parsed)
if isinstance(all_data, (list, six.string_types)):
data = all_data[starting_truncation:]
else:
data = None
set_value_from_jmespath(
parsed,
primary_result_key.expression,
data
)
# We also need to truncate any secondary result keys
# because they were not truncated in the previous last
# response.
for token in self.result_keys:
if token == primary_result_key:
continue
sample = token.search(parsed)
if isinstance(sample, list):
empty_value = []
elif isinstance(sample, six.string_types):
empty_value = ''
elif isinstance(sample, (int, float)):
empty_value = 0
else:
empty_value = None
set_value_from_jmespath(parsed, token.expression, empty_value)
return starting_truncation
示例11: is_compatible
# 需要导入模块: from botocore.compat import six [as 别名]
# 或者: from botocore.compat.six import string_types [as 别名]
def is_compatible(cls, download_target, osutil):
return isinstance(download_target, six.string_types) and \
osutil.is_special_file(download_target)