-
-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AioAWSResponse and AioAWSRequest (#934)
- Loading branch information
Showing
22 changed files
with
879 additions
and
264 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = '2.2.0' | ||
__version__ = '2.3.0' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import inspect | ||
|
||
|
||
async def resolve_awaitable(obj): | ||
if inspect.isawaitable(obj): | ||
return await obj | ||
|
||
return obj | ||
|
||
|
||
async def async_any(items): | ||
for item in items: | ||
if await resolve_awaitable(item): | ||
return True | ||
|
||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from botocore.awsrequest import AWSResponse | ||
import botocore.utils | ||
|
||
|
||
class AioAWSResponse(AWSResponse): | ||
# Unlike AWSResponse, these return awaitables | ||
|
||
async def _content_prop(self): | ||
"""Content of the response as bytes.""" | ||
|
||
if self._content is None: | ||
# NOTE: this will cache the data in self.raw | ||
self._content = await self.raw.read() or bytes() | ||
|
||
return self._content | ||
|
||
@property | ||
def content(self): | ||
return self._content_prop() | ||
|
||
async def _text_prop(self): | ||
encoding = botocore.utils.get_encoding_from_headers(self.headers) | ||
if encoding: | ||
return (await self.content).decode(encoding) | ||
else: | ||
return (await self.content).decode('utf-8') | ||
|
||
@property | ||
def text(self): | ||
return self._text_prop() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.