Skip to content
This repository has been archived by the owner on Apr 14, 2022. It is now read-only.

Add support for async files as request body #217

Merged
merged 1 commit into from
May 11, 2020

Conversation

sethmlarson
Copy link
Contributor

This PR adds support async files like trio.wrap_file(open()) and anyio.aopen() and does some refactoring that will allow us to accept other async iterables as data sources easily.

  • Made set_file_position() and rewind_body() able to handle async files
  • Added an unasync.py file to hip.util for small unasync-related utilities like anext() and await_if_coro(). See Provide common replacement utils / functions many projects will need unasync#65 for more info here too.
  • Added read_timeout to AnyIOSocket.receive_some(), don't know how that bug wasn't caught earlier.
  • Turned a lot of the internal request data stream functions into return async iterators. This blazes the trail for accepting async iterables in body=.
  • Moved all tests related to file uploads into test/with_dummyserver/async/.
  • Added test/with_dummyserver/async_only/ for test cases that shouldn't be unasync-ed, things specific to an async library



# XX this should return an async iterator
def _request_bytes_iterable(request, state_machine):
"""
An iterable that serialises a set of bytes for the body.
"""

def all_pieces_iter():
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not super happy with this function, there's probably a simpler way to do this rather than a direct translation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly. Maybe @njsmith know how to improve this? In any case, this isn't blocking, so I'll merge this pull request.

@sethmlarson sethmlarson force-pushed the async-request-data branch 2 times, most recently from 69b3aab to 1d379e9 Compare May 10, 2020 22:48
@sethmlarson sethmlarson force-pushed the async-request-data branch from 1d379e9 to 7f6bd7e Compare May 10, 2020 23:01
@codecov
Copy link

codecov bot commented May 11, 2020

Codecov Report

Merging #217 into master will decrease coverage by 0.36%.
The diff coverage is 83.87%.

@@            Coverage Diff             @@
##           master     #217      +/-   ##
==========================================
- Coverage   99.15%   98.79%   -0.37%     
==========================================
  Files          21       22       +1     
  Lines        3196     3234      +38     
==========================================
+ Hits         3169     3195      +26     
- Misses         27       39      +12     
Impacted Files Coverage Δ
src/ahip/util/unasync.py 73.52% <79.16%> (ø)
src/ahip/connectionpool.py 99.77% <100.00%> (ø)
src/ahip/poolmanager.py 100.00% <100.00%> (ø)
src/ahip/util/request.py 96.05% <100.00%> (-3.95%) ⬇️

Copy link
Member

@pquentin pquentin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!



# XX this should return an async iterator
def _request_bytes_iterable(request, state_machine):
"""
An iterable that serialises a set of bytes for the body.
"""

def all_pieces_iter():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly. Maybe @njsmith know how to improve this? In any case, this isn't blocking, so I'll merge this pull request.

@pquentin pquentin merged commit 23ce1f6 into python-trio:master May 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants