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


Python response.StreamingBody方法代码示例

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


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

示例1: deserialize

# 需要导入模块: from botocore import response [as 别名]
# 或者: from botocore.response import StreamingBody [as 别名]
def deserialize(obj):
    """Convert JSON dicts back into objects."""
    # Be careful of shallow copy here
    target = dict(obj)
    class_name = None
    if "__class__" in target:
        class_name = target.pop("__class__")
    if "__module__" in obj:
        obj.pop("__module__")
    # Use getattr(module, class_name) for custom types if needed
    if class_name == "datetime":
        return datetime(tzinfo=utc, **target)
    if class_name == "StreamingBody":
        return StringIO(target["body"])
    # Return unrecognized structures as-is
    return obj 
开发者ID:cloud-custodian,项目名称:cloud-custodian,代码行数:18,代码来源:zpill.py

示例2: gen_s3_object_content

# 需要导入模块: from botocore import response [as 别名]
# 或者: from botocore.response import StreamingBody [as 别名]
def gen_s3_object_content(content):
    """Convert a string or dict to S3 object body.

    Args:
        content (Union[str, Dict[str, Any]]): S3 object body

    Returns:
        botocore.response.StreamingBody Used in the Body of a
            s3.get_object response.

    """
    if isinstance(content, dict):
        content = json.dumps(content, default=json_serial)
    encoded_content = content.encode()
    return StreamingBody(io.BytesIO(encoded_content),
                         len(encoded_content)) 
开发者ID:onicagroup,项目名称:runway,代码行数:18,代码来源:test_context.py

示例3: test_streaming_s3_objects

# 需要导入模块: from botocore import response [as 别名]
# 或者: from botocore.response import StreamingBody [as 别名]
def test_streaming_s3_objects():
    # GH17135
    # botocore gained iteration support in 1.10.47, can now be used in read_*
    pytest.importorskip('botocore', minversion='1.10.47')
    from botocore.response import StreamingBody

    data = [
        b'foo,bar,baz\n1,2,3\n4,5,6\n',
        b'just,the,header\n',
    ]
    for el in data:
        body = StreamingBody(BytesIO(el), content_length=len(el))
        read_csv(body) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:15,代码来源:test_s3.py

示例4: convert_to_response_dict

# 需要导入模块: from botocore import response [as 别名]
# 或者: from botocore.response import StreamingBody [as 别名]
def convert_to_response_dict(http_response, operation_model):
    """Convert an HTTP response object to a request dict.

    This converts the requests library's HTTP response object to
    a dictionary.

    :type http_response: botocore.vendored.requests.model.Response
    :param http_response: The HTTP response from an AWS service request.

    :rtype: dict
    :return: A response dictionary which will contain the following keys:
        * headers (dict)
        * status_code (int)
        * body (string or file-like object)

    """
    response_dict = {
        'headers': http_response.headers,
        'status_code': http_response.status_code,
    }
    if response_dict['status_code'] >= 300:
        response_dict['body'] = http_response.content
    elif operation_model.has_streaming_output:
        response_dict['body'] = StreamingBody(
            http_response.raw, response_dict['headers'].get('content-length'))
    else:
        response_dict['body'] = http_response.content
    return response_dict 
开发者ID:skarlekar,项目名称:faces,代码行数:30,代码来源:endpoint.py

示例5: test_get_contents_from_url_returns_string_content

# 需要导入模块: from botocore import response [as 别名]
# 或者: from botocore.response import StreamingBody [as 别名]
def test_get_contents_from_url_returns_string_content(self, resource_mock):
        body_mock = Mock(spec=StreamingBody)
        body_mock.read.return_value = b'Foo'

        resource_mock.return_value.Object.return_value.get.return_value = {"Body": body_mock}

        result = S3().get_contents_from_url('s3://my-bucket/my/key/file.json')
        self.assertEqual("Foo", result) 
开发者ID:cfn-sphere,项目名称:cfn-sphere,代码行数:10,代码来源:s3_tests.py

示例6: convert_to_response_dict

# 需要导入模块: from botocore import response [as 别名]
# 或者: from botocore.response import StreamingBody [as 别名]
def convert_to_response_dict(http_response, operation_model):
    """Convert an HTTP response object to a request dict.

    This converts the requests library's HTTP response object to
    a dictionary.

    :type http_response: botocore.vendored.requests.model.Response
    :param http_response: The HTTP response from an AWS service request.

    :rtype: dict
    :return: A response dictionary which will contain the following keys:
        * headers (dict)
        * status_code (int)
        * body (string or file-like object)

    """
    response_dict = {
        'headers': http_response.headers,
        'status_code': http_response.status_code,
        'context': {
            'operation_name': operation_model.name,
        }
    }
    if response_dict['status_code'] >= 300:
        response_dict['body'] = http_response.content
    elif operation_model.has_event_stream_output:
        response_dict['body'] = http_response.raw
    elif operation_model.has_streaming_output:
        length = response_dict['headers'].get('content-length')
        response_dict['body'] = StreamingBody(http_response.raw, length)
    else:
        response_dict['body'] = http_response.content
    return response_dict 
开发者ID:QData,项目名称:deepWordBug,代码行数:35,代码来源:endpoint.py

示例7: serialize

# 需要导入模块: from botocore import response [as 别名]
# 或者: from botocore.response import StreamingBody [as 别名]
def serialize(obj):
    """Convert objects into JSON structures."""
    # Record class and module information for deserialization
    result = {"__class__": obj.__class__.__name__}
    try:
        result["__module__"] = obj.__module__
    except AttributeError:
        pass

    # Convert objects to dictionary representation based on type
    if isinstance(obj, datetime):
        result["year"] = obj.year
        result["month"] = obj.month
        result["day"] = obj.day
        result["hour"] = obj.hour
        result["minute"] = obj.minute
        result["second"] = obj.second
        result["microsecond"] = obj.microsecond
        return result
    if isinstance(obj, StreamingBody):
        result["body"] = obj.read()
        obj._raw_stream = StringIO(result["body"])
        obj._amount_read = 0
        return result
    if isinstance(obj, bytes):
        return obj.decode('utf8')

    # Raise a TypeError if the object isn't recognized
    raise TypeError("Type not serializable") 
开发者ID:cloud-custodian,项目名称:cloud-custodian,代码行数:31,代码来源:zpill.py


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