Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subclass IOBase with StreamingBody #1361

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions botocore/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import xml.etree.cElementTree
import logging

from io import IOBase

from botocore import ScalarTypes
from botocore.hooks import first_non_none_response
from botocore.compat import json, set_socket_timeout, XMLParseError
Expand All @@ -26,7 +28,7 @@
logger = logging.getLogger(__name__)


class StreamingBody(object):
class StreamingBody(IOBase):
"""Wrapper class for an http response body.

This provides a few additional conveniences that do not exist
Expand All @@ -43,6 +45,9 @@ def __init__(self, raw_stream, content_length):
self._content_length = content_length
self._amount_read = 0

def readable(self):
return not self.closed

def set_socket_timeout(self, timeout):
"""Set the timeout seconds on the socket."""
# The problem we're trying to solve is to prevent .read() calls from
Expand Down Expand Up @@ -91,8 +96,9 @@ def _verify_content_length(self):
expected_bytes=int(self._content_length))

def close(self):
"""Close the underlying http response stream."""
"""Close the underlying http response stream and IOBase."""
self._raw_stream.close()
super(StreamingBody, self).close()


def get_response(operation_model, http_response):
Expand Down