Skip to content

Commit 15be976

Browse files
Reverting a potential breaking change
1 parent bf9b590 commit 15be976

File tree

4 files changed

+16
-13
lines changed

4 files changed

+16
-13
lines changed

Diff for: aws_lambda_powertools/utilities/streaming/_s3_seekable_io.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
)
1515

1616
import boto3
17-
from botocore.response import StreamingBody
1817

1918
from aws_lambda_powertools.shared import user_agent
19+
from aws_lambda_powertools.utilities.streaming.compat import PowertoolsStreamingBody
2020

2121
if TYPE_CHECKING:
2222
from mmap import mmap
@@ -68,7 +68,7 @@ def __init__(
6868
self._size: Optional[int] = None
6969

7070
self._s3_client: Optional["Client"] = boto3_client
71-
self._raw_stream: Optional[StreamingBody] = None
71+
self._raw_stream: Optional[PowertoolsStreamingBody] = None
7272

7373
self._sdk_options = sdk_options
7474
self._sdk_options["Bucket"] = bucket
@@ -100,7 +100,7 @@ def size(self) -> int:
100100
return self._size
101101

102102
@property
103-
def raw_stream(self) -> StreamingBody:
103+
def raw_stream(self) -> PowertoolsStreamingBody:
104104
"""
105105
Returns the boto3 StreamingBody, starting the stream from the seeked position.
106106
"""
@@ -110,7 +110,7 @@ def raw_stream(self) -> StreamingBody:
110110
self._raw_stream = self.s3_client.get_object(Range=range_header, **self._sdk_options).get("Body")
111111
self._closed = False
112112

113-
return cast(StreamingBody, self._raw_stream)
113+
return cast(PowertoolsStreamingBody, self._raw_stream)
114114

115115
def seek(self, offset: int, whence: int = io.SEEK_SET) -> int:
116116
"""

Diff for: aws_lambda_powertools/utilities/streaming/compat.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from botocore.response import StreamingBody
2+
3+
PowertoolsStreamingBody = StreamingBody

Diff for: examples/streaming/src/assert_transformation.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import boto3
44
from assert_transformation_module import UpperTransform
55
from botocore import stub
6-
from botocore.response import StreamingBody
76

87
from aws_lambda_powertools.utilities.streaming import S3Object
8+
from aws_lambda_powertools.utilities.streaming.compat import PowertoolsStreamingBody
99

1010

1111
def test_upper_transform():
@@ -24,7 +24,7 @@ def test_s3_object_with_upper_transform():
2424
s3_stub = stub.Stubber(s3_client)
2525
s3_stub.add_response(
2626
"get_object",
27-
{"Body": StreamingBody(raw_stream=io.BytesIO(payload), content_length=len(payload))},
27+
{"Body": PowertoolsStreamingBody(raw_stream=io.BytesIO(payload), content_length=len(payload))},
2828
)
2929
s3_stub.activate()
3030

Diff for: tests/functional/streaming/test_s3_seekable_io.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import boto3
44
import pytest
55
from botocore import stub
6-
from botocore.response import StreamingBody
76

87
from aws_lambda_powertools.utilities.streaming._s3_seekable_io import _S3SeekableIO
8+
from aws_lambda_powertools.utilities.streaming.compat import PowertoolsStreamingBody
99

1010

1111
@pytest.fixture
@@ -89,7 +89,7 @@ def test_raw_stream_fetches_with_range_header_after_seek(s3_seekable_obj, s3_cli
8989

9090
def test_read(s3_seekable_obj, s3_client_stub):
9191
payload = b"hello world"
92-
streaming_body = StreamingBody(raw_stream=io.BytesIO(payload), content_length=len(payload))
92+
streaming_body = PowertoolsStreamingBody(raw_stream=io.BytesIO(payload), content_length=len(payload))
9393

9494
s3_client_stub.add_response(
9595
"get_object",
@@ -105,7 +105,7 @@ def test_read(s3_seekable_obj, s3_client_stub):
105105

106106
def test_readline(s3_seekable_obj, s3_client_stub):
107107
payload = b"hello world\nworld hello"
108-
streaming_body = StreamingBody(raw_stream=io.BytesIO(payload), content_length=len(payload))
108+
streaming_body = PowertoolsStreamingBody(raw_stream=io.BytesIO(payload), content_length=len(payload))
109109

110110
s3_client_stub.add_response(
111111
"get_object",
@@ -120,7 +120,7 @@ def test_readline(s3_seekable_obj, s3_client_stub):
120120

121121
def test_readlines(s3_seekable_obj, s3_client_stub):
122122
payload = b"hello world\nworld hello"
123-
streaming_body = StreamingBody(raw_stream=io.BytesIO(payload), content_length=len(payload))
123+
streaming_body = PowertoolsStreamingBody(raw_stream=io.BytesIO(payload), content_length=len(payload))
124124

125125
s3_client_stub.add_response(
126126
"get_object",
@@ -134,7 +134,7 @@ def test_readlines(s3_seekable_obj, s3_client_stub):
134134

135135
def test_closed(s3_seekable_obj, s3_client_stub):
136136
payload = b"test"
137-
streaming_body = StreamingBody(raw_stream=io.BytesIO(payload), content_length=len(payload))
137+
streaming_body = PowertoolsStreamingBody(raw_stream=io.BytesIO(payload), content_length=len(payload))
138138

139139
s3_client_stub.add_response(
140140
"get_object",
@@ -148,7 +148,7 @@ def test_closed(s3_seekable_obj, s3_client_stub):
148148

149149
def test_next(s3_seekable_obj, s3_client_stub):
150150
payload = b"test"
151-
streaming_body = StreamingBody(raw_stream=io.BytesIO(payload), content_length=len(payload))
151+
streaming_body = PowertoolsStreamingBody(raw_stream=io.BytesIO(payload), content_length=len(payload))
152152

153153
s3_client_stub.add_response(
154154
"get_object",
@@ -163,7 +163,7 @@ def test_next(s3_seekable_obj, s3_client_stub):
163163

164164
def test_context_manager(s3_seekable_obj, s3_client_stub):
165165
payload = b"test"
166-
streaming_body = StreamingBody(raw_stream=io.BytesIO(payload), content_length=len(payload))
166+
streaming_body = PowertoolsStreamingBody(raw_stream=io.BytesIO(payload), content_length=len(payload))
167167

168168
s3_client_stub.add_response(
169169
"get_object",

0 commit comments

Comments
 (0)