Update tornado
This commit is contained in:
Regular → Executable
+14
-8
@@ -16,7 +16,7 @@
|
||||
|
||||
"""Blocking and non-blocking HTTP client implementations using pycurl."""
|
||||
|
||||
from __future__ import with_statement
|
||||
from __future__ import absolute_import, division, with_statement
|
||||
|
||||
import cStringIO
|
||||
import collections
|
||||
@@ -32,6 +32,7 @@ from tornado import stack_context
|
||||
from tornado.escape import utf8
|
||||
from tornado.httpclient import HTTPRequest, HTTPResponse, HTTPError, AsyncHTTPClient, main
|
||||
|
||||
|
||||
class CurlAsyncHTTPClient(AsyncHTTPClient):
|
||||
def initialize(self, io_loop=None, max_clients=10,
|
||||
max_simultaneous_connections=None):
|
||||
@@ -109,15 +110,17 @@ class CurlAsyncHTTPClient(AsyncHTTPClient):
|
||||
if self._timeout is not None:
|
||||
self.io_loop.remove_timeout(self._timeout)
|
||||
self._timeout = self.io_loop.add_timeout(
|
||||
time.time() + msecs/1000.0, self._handle_timeout)
|
||||
time.time() + msecs / 1000.0, self._handle_timeout)
|
||||
|
||||
def _handle_events(self, fd, events):
|
||||
"""Called by IOLoop when there is activity on one of our
|
||||
file descriptors.
|
||||
"""
|
||||
action = 0
|
||||
if events & ioloop.IOLoop.READ: action |= pycurl.CSELECT_IN
|
||||
if events & ioloop.IOLoop.WRITE: action |= pycurl.CSELECT_OUT
|
||||
if events & ioloop.IOLoop.READ:
|
||||
action |= pycurl.CSELECT_IN
|
||||
if events & ioloop.IOLoop.WRITE:
|
||||
action |= pycurl.CSELECT_OUT
|
||||
while True:
|
||||
try:
|
||||
ret, num_handles = self._socket_action(fd, action)
|
||||
@@ -250,7 +253,6 @@ class CurlAsyncHTTPClient(AsyncHTTPClient):
|
||||
except Exception:
|
||||
self.handle_callback_exception(info["callback"])
|
||||
|
||||
|
||||
def handle_callback_exception(self, callback):
|
||||
self.io_loop.handle_callback_exception(callback)
|
||||
|
||||
@@ -372,7 +374,7 @@ def _curl_setup_request(curl, request, buffer, headers):
|
||||
|
||||
# Handle curl's cryptic options for every individual HTTP method
|
||||
if request.method in ("POST", "PUT"):
|
||||
request_buffer = cStringIO.StringIO(utf8(request.body))
|
||||
request_buffer = cStringIO.StringIO(utf8(request.body))
|
||||
curl.setopt(pycurl.READFUNCTION, request_buffer.read)
|
||||
if request.method == "POST":
|
||||
def ioctl(cmd):
|
||||
@@ -393,8 +395,11 @@ def _curl_setup_request(curl, request, buffer, headers):
|
||||
curl.unsetopt(pycurl.USERPWD)
|
||||
logging.debug("%s %s", request.method, request.url)
|
||||
|
||||
if request.client_key is not None or request.client_cert is not None:
|
||||
raise ValueError("Client certificate not supported with curl_httpclient")
|
||||
if request.client_cert is not None:
|
||||
curl.setopt(pycurl.SSLCERT, request.client_cert)
|
||||
|
||||
if request.client_key is not None:
|
||||
curl.setopt(pycurl.SSLKEY, request.client_key)
|
||||
|
||||
if threading.activeCount() > 1:
|
||||
# libcurl/pycurl is not thread-safe by default. When multiple threads
|
||||
@@ -420,6 +425,7 @@ def _curl_header_callback(headers, header_line):
|
||||
return
|
||||
headers.parse_line(header_line)
|
||||
|
||||
|
||||
def _curl_debug(debug_type, debug_msg):
|
||||
debug_types = ('I', '<', '>', '<', '>')
|
||||
if debug_type == 0:
|
||||
|
||||
Reference in New Issue
Block a user