Merge pull request #2402 from ploxiln/pycurl_py3_justbytes

CurlAsyncHTTPClient: remove ubuntu-12.10 python3 fix
This commit is contained in:
Ben Darnell 2018-05-27 20:25:52 -04:00 committed by GitHub
commit 9bb6463c07
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 1 additions and 11 deletions

View File

@ -319,17 +319,7 @@ class CurlAsyncHTTPClient(AsyncHTTPClient):
self.io_loop.add_callback(request.streaming_callback, chunk) self.io_loop.add_callback(request.streaming_callback, chunk)
else: else:
write_function = buffer.write write_function = buffer.write
if bytes is str: # py2 curl.setopt(pycurl.WRITEFUNCTION, write_function)
curl.setopt(pycurl.WRITEFUNCTION, write_function)
else: # py3
# Upstream pycurl doesn't support py3, but ubuntu 12.10 includes
# a fork/port. That version has a bug in which it passes unicode
# strings instead of bytes to the WRITEFUNCTION. This means that
# if you use a WRITEFUNCTION (which tornado always does), you cannot
# download arbitrary binary data. This needs to be fixed in the
# ported pycurl package, but in the meantime this lambda will
# make it work for downloading (utf8) text.
curl.setopt(pycurl.WRITEFUNCTION, lambda s: write_function(utf8(s)))
curl.setopt(pycurl.FOLLOWLOCATION, request.follow_redirects) curl.setopt(pycurl.FOLLOWLOCATION, request.follow_redirects)
curl.setopt(pycurl.MAXREDIRS, request.max_redirects) curl.setopt(pycurl.MAXREDIRS, request.max_redirects)
curl.setopt(pycurl.CONNECTTIMEOUT_MS, int(1000 * request.connect_timeout)) curl.setopt(pycurl.CONNECTTIMEOUT_MS, int(1000 * request.connect_timeout))