forked from aio-libs/aiohttp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PR aio-libs#7775/5f64328c backport][3.9] Add codespell support: pre-…
…commit entry, configuration, some typoes get fixed (aio-libs#7800) **This is a backport of PR aio-libs#7775 as merged into master (5f64328).** See https://github.com/codespell-project/codespell for the codespell project. I like it and promote everywhere I go ;) but feel free to disregard this PR, may be take just last commit with 1 obvious typo and may be the "repr" typo fix. Another commit fixes typos it found and some were I guess whitelisted in docs/spelling_wordlist.txt where it fixed them too. What is the role/how that file is used? (I am not familiar, but found similar ones in jsonschema and few other projects) somewhat since there is following fix ``` if t is None: - t_repr = "<<Unkown>>" + t_repr = "<<Unknown>>" ``` so some reprs would be effected . another change is functional in the test (taking "an" not "ans" from "answer") but that must not be user visible please advise on either you see value for me to bother with CHANGES etc - [ ] I think the code is well written - [ ] Unit tests for the changes exist - [ ] Documentation reflects the changes - [ ] If you provide code modification, please add yourself to `CONTRIBUTORS.txt` * The format is <Name> <Surname>. * Please keep alphabetical order, the file is sorted by names. - [ ] Add a new news fragment into the `CHANGES` folder * name it `<issue_id>.<type>` for example (588.bugfix) * if you don't have an `issue_id` change it to the pr id after creating the pr * ensure type is one of the following: * `.feature`: Signifying a new feature. * `.bugfix`: Signifying a bug fix. * `.doc`: Signifying a documentation improvement. * `.removal`: Signifying a deprecation or removal of public API. * `.misc`: A ticket has been closed, but it is not of interest to users. * Make sure to use full sentences with correct case and punctuation, for example: "Fix issue with non-ascii contents in doctest text files." Co-authored-by: Yaroslav Halchenko <[email protected]>
- Loading branch information
1 parent
ff6ac61
commit a96fc47
Showing
10 changed files
with
99 additions
and
15 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
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,75 @@ | ||
""" | ||
Payload implementation for coroutines as data provider. | ||
As a simple case, you can upload data from file:: | ||
@aiohttp.streamer | ||
async def file_sender(writer, file_name=None): | ||
with open(file_name, 'rb') as f: | ||
chunk = f.read(2**16) | ||
while chunk: | ||
await writer.write(chunk) | ||
chunk = f.read(2**16) | ||
Then you can use `file_sender` like this: | ||
async with session.post('http://httpbin.org/post', | ||
data=file_sender(file_name='huge_file')) as resp: | ||
print(await resp.text()) | ||
..note:: Coroutine must accept `writer` as first argument | ||
""" | ||
|
||
import types | ||
import warnings | ||
from typing import Any, Awaitable, Callable, Dict, Tuple | ||
|
||
from .abc import AbstractStreamWriter | ||
from .payload import Payload, payload_type | ||
|
||
__all__ = ("streamer",) | ||
|
||
|
||
class _stream_wrapper: | ||
def __init__( | ||
self, | ||
coro: Callable[..., Awaitable[None]], | ||
args: Tuple[Any, ...], | ||
kwargs: Dict[str, Any], | ||
) -> None: | ||
self.coro = types.coroutine(coro) | ||
self.args = args | ||
self.kwargs = kwargs | ||
|
||
async def __call__(self, writer: AbstractStreamWriter) -> None: | ||
await self.coro(writer, *self.args, **self.kwargs) | ||
|
||
|
||
class streamer: | ||
def __init__(self, coro: Callable[..., Awaitable[None]]) -> None: | ||
warnings.warn( | ||
"@streamer is deprecated, use async generators instead", | ||
DeprecationWarning, | ||
stacklevel=2, | ||
) | ||
self.coro = coro | ||
|
||
def __call__(self, *args: Any, **kwargs: Any) -> _stream_wrapper: | ||
return _stream_wrapper(self.coro, args, kwargs) | ||
|
||
|
||
@payload_type(_stream_wrapper) | ||
class StreamWrapperPayload(Payload): | ||
async def write(self, writer: AbstractStreamWriter) -> None: | ||
await self._value(writer) | ||
|
||
|
||
@payload_type(streamer) | ||
class StreamPayload(StreamWrapperPayload): | ||
def __init__(self, value: Any, *args: Any, **kwargs: Any) -> None: | ||
super().__init__(value(), *args, **kwargs) | ||
|
||
async def write(self, writer: AbstractStreamWriter) -> None: | ||
await self._value(writer) |
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
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