Skip to content

Commit

Permalink
legacy support for generators in requests
Browse files Browse the repository at this point in the history
  • Loading branch information
joamag committed Apr 18, 2018
1 parent d28b541 commit f7b9046
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/quorum/httpc.py
Expand Up @@ -556,6 +556,15 @@ def _resolve_legacy(url, method, headers, data, silent, timeout, **kwargs):

def _resolve_requests(url, method, headers, data, silent, timeout, **kwargs):
import requests

# verifies if the provided data is a generator, assumes that if the
# data is not invalid and not of types string then it's a generator
# and then if that's the case skips the first iteration (data size)
# and joins the rest of the buffer (in the generator), this must be
# done because requests is not compatible with generator data input
is_generator = not data == None and not legacy.is_string(data)
if is_generator: next(data); data = b"".join(list(data))

method = method.lower()
caller = getattr(requests, method)
result = caller(url, headers = headers, data = data, timeout = timeout)
Expand Down

0 comments on commit f7b9046

Please sign in to comment.