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

fixes #1125 due to missing aync override #1126

Merged
merged 5 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
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
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 @@
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

Check warning on line 53 in aiobotocore/httpchecksum.py

View check run for this annotation

Codecov / codecov/patch

aiobotocore/httpchecksum.py#L51-L53

Added lines #L51 - L53 were not covered by tests

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

Check warning on line 60 in aiobotocore/httpchecksum.py

View check run for this annotation

Codecov / codecov/patch

aiobotocore/httpchecksum.py#L56-L60

Added lines #L56 - L60 were not covered by tests

def _validate_checksum(self):
if self._checksum.digest() != base64.b64decode(self._expected):
error_msg = (

Check warning on line 64 in aiobotocore/httpchecksum.py

View check run for this annotation

Codecov / codecov/patch

aiobotocore/httpchecksum.py#L63-L64

Added lines #L63 - L64 were not covered by tests
f"Expected checksum {self._expected} did not match calculated "
f"checksum: {self._checksum.b64digest()}"
)
raise FlexibleChecksumError(error_msg=error_msg)

Check warning on line 68 in aiobotocore/httpchecksum.py

View check run for this annotation

Codecov / codecov/patch

aiobotocore/httpchecksum.py#L68

Added line #L68 was not covered by tests


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


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

Check warning on line 117 in aiobotocore/httpchecksum.py

View check run for this annotation

Codecov / codecov/patch

aiobotocore/httpchecksum.py#L115-L117

Added lines #L115 - L117 were not covered by tests
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
Loading