Skip to content

Commit 7154abc

Browse files
authored
fixes #1125 due to missing aync override (#1126)
1 parent eae9743 commit 7154abc

4 files changed

Lines changed: 46 additions & 2 deletions

File tree

CHANGES.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
Changes
22
-------
3+
2.13.2 (2024-07-18)
4+
^^^^^^^^^^^^^^^^^^^
5+
* fix for #1125 due to missing patch of StreamingChecksumBody
36

47
2.13.1 (2024-06-24)
58
^^^^^^^^^^^^^^^^^^^

aiobotocore/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '2.13.1'
1+
__version__ = '2.13.2'

aiobotocore/httpchecksum.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
AwsChunkedWrapper,
66
FlexibleChecksumError,
77
_apply_request_header_checksum,
8-
_handle_streaming_response,
98
base64,
109
conditionally_calculate_md5,
1110
determine_content_length,
1211
logger,
1312
)
1413

1514
from aiobotocore._helpers import resolve_awaitable
15+
from aiobotocore.response import StreamingBody
1616

1717

1818
class AioAwsChunkedWrapper(AwsChunkedWrapper):
@@ -44,6 +44,30 @@ async def __anext__(self):
4444
raise StopAsyncIteration()
4545

4646

47+
# unfortunately we can't inherit from botocore's StreamingChecksumBody due to
48+
# subclassing
49+
class StreamingChecksumBody(StreamingBody):
50+
def __init__(self, raw_stream, content_length, checksum, expected):
51+
super().__init__(raw_stream, content_length)
52+
self._checksum = checksum
53+
self._expected = expected
54+
55+
async def read(self, amt=None):
56+
chunk = await super().read(amt=amt)
57+
self._checksum.update(chunk)
58+
if amt is None or (not chunk and amt > 0):
59+
self._validate_checksum()
60+
return chunk
61+
62+
def _validate_checksum(self):
63+
if self._checksum.digest() != base64.b64decode(self._expected):
64+
error_msg = (
65+
f"Expected checksum {self._expected} did not match calculated "
66+
f"checksum: {self._checksum.b64digest()}"
67+
)
68+
raise FlexibleChecksumError(error_msg=error_msg)
69+
70+
4771
async def handle_checksum_body(
4872
http_response, response, context, operation_model
4973
):
@@ -87,6 +111,17 @@ async def handle_checksum_body(
87111
)
88112

89113

114+
def _handle_streaming_response(http_response, response, algorithm):
115+
checksum_cls = _CHECKSUM_CLS.get(algorithm)
116+
header_name = "x-amz-checksum-%s" % algorithm
117+
return StreamingChecksumBody(
118+
http_response.raw,
119+
response["headers"].get("content-length"),
120+
checksum_cls(),
121+
response["headers"][header_name],
122+
)
123+
124+
90125
async def _handle_bytes_response(http_response, response, algorithm):
91126
body = await http_response.content
92127
header_name = "x-amz-checksum-%s" % algorithm

tests/test_patches.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,10 @@
5252
from botocore.hooks import EventAliaser, HierarchicalEmitter
5353
from botocore.httpchecksum import (
5454
AwsChunkedWrapper,
55+
StreamingChecksumBody,
5556
_apply_request_trailer_checksum,
5657
_handle_bytes_response,
58+
_handle_streaming_response,
5759
apply_request_checksum,
5860
handle_checksum_body,
5961
)
@@ -647,6 +649,10 @@
647649
handle_checksum_body: {
648650
'898cee7a7a5e5a02af7e0e65dcbb8122257b85df',
649651
},
652+
_handle_streaming_response: {'7ce971e012f9d4b04889f0af83f67281ed6a9e6e'},
653+
StreamingChecksumBody: {
654+
'2c6eb22268d46abae261ce386eb2deabbc3a0dcd',
655+
},
650656
_handle_bytes_response: {'0761c4590c6addbe8c674e40fca9f7dd375a184b'},
651657
AwsChunkedWrapper._make_chunk: {
652658
'097361692f0fd6c863a17dd695739629982ef7e4'

0 commit comments

Comments
 (0)