Skip to content

Commit

Permalink
fixes aio-libs#1125 due to missing aync override (aio-libs#1126)
Browse files Browse the repository at this point in the history
  • Loading branch information
thehesiod authored and chemelli74 committed Aug 29, 2024
1 parent aa86c2b commit fb3303e
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
Changes
-------
2.13.2 (2024-07-18)
^^^^^^^^^^^^^^^^^^^
* fix for #1125 due to missing patch of StreamingChecksumBody

2.13.1 (2024-06-24)
^^^^^^^^^^^^^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion aiobotocore/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '2.13.1'
__version__ = '2.13.2'
37 changes: 36 additions & 1 deletion aiobotocore/httpchecksum.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
AwsChunkedWrapper,
FlexibleChecksumError,
_apply_request_header_checksum,
_handle_streaming_response,
base64,
conditionally_calculate_md5,
determine_content_length,
logger,
)

from aiobotocore._helpers import resolve_awaitable
from aiobotocore.response import StreamingBody


class AioAwsChunkedWrapper(AwsChunkedWrapper):
Expand Down Expand Up @@ -44,6 +44,30 @@ async def __anext__(self):
raise StopAsyncIteration()


# unfortunately we can't inherit from botocore's StreamingChecksumBody due to
# subclassing
class StreamingChecksumBody(StreamingBody):
def __init__(self, raw_stream, content_length, checksum, expected):
super().__init__(raw_stream, content_length)
self._checksum = checksum
self._expected = expected

async def read(self, amt=None):
chunk = await super().read(amt=amt)
self._checksum.update(chunk)
if amt is None or (not chunk and amt > 0):
self._validate_checksum()
return chunk

def _validate_checksum(self):
if self._checksum.digest() != base64.b64decode(self._expected):
error_msg = (
f"Expected checksum {self._expected} did not match calculated "
f"checksum: {self._checksum.b64digest()}"
)
raise FlexibleChecksumError(error_msg=error_msg)


async def handle_checksum_body(
http_response, response, context, operation_model
):
Expand Down Expand Up @@ -87,6 +111,17 @@ async def handle_checksum_body(
)


def _handle_streaming_response(http_response, response, algorithm):
checksum_cls = _CHECKSUM_CLS.get(algorithm)
header_name = "x-amz-checksum-%s" % algorithm
return StreamingChecksumBody(
http_response.raw,
response["headers"].get("content-length"),
checksum_cls(),
response["headers"][header_name],
)


async def _handle_bytes_response(http_response, response, algorithm):
body = await http_response.content
header_name = "x-amz-checksum-%s" % algorithm
Expand Down
6 changes: 6 additions & 0 deletions tests/test_patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@
from botocore.hooks import EventAliaser, HierarchicalEmitter
from botocore.httpchecksum import (
AwsChunkedWrapper,
StreamingChecksumBody,
_apply_request_trailer_checksum,
_handle_bytes_response,
_handle_streaming_response,
apply_request_checksum,
handle_checksum_body,
)
Expand Down Expand Up @@ -647,6 +649,10 @@
handle_checksum_body: {
'898cee7a7a5e5a02af7e0e65dcbb8122257b85df',
},
_handle_streaming_response: {'7ce971e012f9d4b04889f0af83f67281ed6a9e6e'},
StreamingChecksumBody: {
'2c6eb22268d46abae261ce386eb2deabbc3a0dcd',
},
_handle_bytes_response: {'0761c4590c6addbe8c674e40fca9f7dd375a184b'},
AwsChunkedWrapper._make_chunk: {
'097361692f0fd6c863a17dd695739629982ef7e4'
Expand Down

0 comments on commit fb3303e

Please sign in to comment.