Skip to content

Commit b438593

Browse files
committed
Await seek for AsyncIterable bodies
1 parent 46369b6 commit b438593

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

packages/aws-sdk-signers/src/aws_sdk_signers/interfaces/io.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,12 @@ class Seekable(Protocol):
2525
def seek(self, offset: int, whence: int = 0, /) -> int: ...
2626

2727
def tell(self) -> int: ...
28+
29+
30+
@runtime_checkable
31+
class AsyncSeekable(Protocol):
32+
"""An async file-like object with seek and tell implemented."""
33+
34+
async def seek(self, offset: int, whence: int = 0, /) -> int: ...
35+
36+
def tell(self) -> int: ...

packages/aws-sdk-signers/src/aws_sdk_signers/signers.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
import hmac
66
import io
77
import warnings
8+
from asyncio import iscoroutinefunction
89
from collections.abc import AsyncIterable, Iterable
910
from copy import deepcopy
1011
from hashlib import sha256
1112
from typing import Required, TypedDict
1213
from urllib.parse import parse_qsl, quote
1314

14-
from .interfaces.io import Seekable
15+
from .interfaces.io import AsyncSeekable, Seekable
1516
from ._http import URI, AWSRequest, Field
1617
from ._identity import AWSCredentialIdentity
1718
from ._io import AsyncBytesReader
@@ -757,11 +758,11 @@ async def _compute_payload_hash(
757758
)
758759

759760
checksum = sha256()
760-
if isinstance(body, Seekable):
761+
if isinstance(body, AsyncSeekable) and iscoroutinefunction(body.seek):
761762
position = body.tell()
762763
async for chunk in body:
763764
checksum.update(chunk)
764-
body.seek(position)
765+
await body.seek(position)
765766
else:
766767
buffer = io.BytesIO()
767768
async for chunk in body:

0 commit comments

Comments
 (0)