Skip to content
Myr

prettier async patching

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Kenneth Reitz · committed by Kenneth Reitz · parent 12db157 · Browse files · 1 file+10 added−10 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+10 added−10 removed

  • other:+10 added−10 removed

1 file+10 added−10 removed

modified:requests/async.py+10 added-10 removed
26 unmodified lines
27 'get', 'head', 'post', 'put', 'patch', 'delete', 'request'28)293031def _patched(f):31def patched(f):32 """Patches a given API function to not send."""3334 def wrapped(*args, **kwargs):35 return f(*args, return_response=False, **kwargs)3637 return wrapped383940def _send(r, pools=None):40def send(r, pools=None):41 """Sends a given Request object."""4243 if pools:44 r._pools = pools
3 unmodified lines
48 return r.response495051# Patched requests.api functions.52get = _patched(api.get)53head = _patched(api.head)54post = _patched(api.post)55put = _patched(api.put)56patch = _patched(api.patch)57delete = _patched(api.delete)58request = _patched(api.request)52get = patched(api.get)53head = patched(api.head)54post = patched(api.post)55put = patched(api.put)56patch = patched(api.patch)57delete = patched(api.delete)58request = patched(api.request)596061def map(requests, prefetch=True):62 """Concurrently converts a list of Requests to Responses.
1 unmodified line
64 :param requests: a collection of Request objects.65 :param prefetch: If False, the content will not be downloaded immediately.66 """6768 jobs = [gevent.spawn(_send, r) for r in requests]68 jobs = [gevent.spawn(send, r) for r in requests]69 gevent.joinall(jobs)7071 if prefetch:72 [r.response.content for r in requests]
6 unmodified lines