From: Ben Darnell Date: Tue, 22 Feb 2011 20:14:32 +0000 (-0800) Subject: Move USE_SIMPLE_HTTPCLIENT environment check out of curl_httpclient X-Git-Tag: v2.0.0~129 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=83d4e933f6a190c3a9039fa55281ab2a63bcbf9f;p=thirdparty%2Ftornado.git Move USE_SIMPLE_HTTPCLIENT environment check out of curl_httpclient --- diff --git a/tornado/curl_httpclient.py b/tornado/curl_httpclient.py index f662918a0..c00f1945f 100644 --- a/tornado/curl_httpclient.py +++ b/tornado/curl_httpclient.py @@ -26,14 +26,7 @@ import errno import httplib import logging import os -try: - import pycurl -except ImportError: - # See the other check for this variable at end of file - if os.environ.get('USE_SIMPLE_HTTPCLIENT'): - pycurl = None - else: - raise +import pycurl import sys import threading import time @@ -473,15 +466,5 @@ def _curl_debug(debug_type, debug_msg): elif debug_type == 4: logging.debug('%s %r', debug_types[debug_type], debug_msg) - - -# If the environment variable USE_SIMPLE_HTTPCLIENT is set to a non-empty -# string, use SimpleAsyncHTTPClient instead of AsyncHTTPClient. -# This is provided as a convenience for testing SimpleAsyncHTTPClient, -# and may be removed or replaced with a better way of specifying the preferred -# HTTPClient implementation before the next release. -if os.environ.get('USE_SIMPLE_HTTPCLIENT'): - from tornado.simple_httpclient import SimpleAsyncHTTPClient as AsyncHTTPClient - if __name__ == "__main__": main() diff --git a/tornado/httpclient.py b/tornado/httpclient.py index ae028b77a..39f7102ac 100644 --- a/tornado/httpclient.py +++ b/tornado/httpclient.py @@ -1,4 +1,5 @@ import httplib +import os import time from tornado.escape import utf8 @@ -207,7 +208,15 @@ def main(): if options.print_body: print response.body -from tornado.curl_httpclient import AsyncHTTPClient +# If the environment variable USE_SIMPLE_HTTPCLIENT is set to a non-empty +# string, use simple_httpclient instead of curl_httpclient. +# This is provided as a convenience for testing simple_httpclient, +# and may be removed or replaced with a better way of specifying the preferred +# HTTPClient implementation before the next release. +if os.environ.get("USE_SIMPLE_HTTPCLIENT"): + from tornado.simple_httpclient import AsyncHTTPClient +else: + from tornado.curl_httpclient import AsyncHTTPClient if __name__ == "__main__": main() diff --git a/tornado/simple_httpclient.py b/tornado/simple_httpclient.py index 3a7884ef2..333d3efaf 100644 --- a/tornado/simple_httpclient.py +++ b/tornado/simple_httpclient.py @@ -29,7 +29,7 @@ except ImportError: _DEFAULT_CA_CERTS = os.path.dirname(__file__) + '/ca-certificates.crt' -class SimpleAsyncHTTPClient(object): +class AsyncHTTPClient(object): """Non-blocking HTTP client with no external dependencies. This class implements an HTTP 1.1 client on top of Tornado's IOStreams. @@ -61,9 +61,9 @@ class SimpleAsyncHTTPClient(object): max_simultaneous_connections=None, force_instance=False, hostname_mapping=None): - """Creates a SimpleAsyncHTTPClient. + """Creates a AsyncHTTPClient. - Only a single SimpleAsyncHTTPClient instance exists per IOLoop + Only a single AsyncHTTPClient instance exists per IOLoop in order to provide limitations on the number of pending connections. force_instance=True may be used to suppress this behavior. @@ -82,7 +82,7 @@ class SimpleAsyncHTTPClient(object): if io_loop in cls._ASYNC_CLIENTS and not force_instance: return cls._ASYNC_CLIENTS[io_loop] else: - instance = super(SimpleAsyncHTTPClient, cls).__new__(cls) + instance = super(AsyncHTTPClient, cls).__new__(cls) instance.io_loop = io_loop instance.max_clients = max_clients instance.queue = collections.deque() @@ -393,6 +393,8 @@ def match_hostname(cert, hostname): raise CertificateError("no appropriate commonName or " "subjectAltName fields were found") +# Alias for backwards compatibility +SimpleAsyncHTTPClient = AsyncHTTPClient def main(): from tornado.options import define, options, parse_command_line @@ -400,7 +402,7 @@ def main(): define("print_body", type=bool, default=True) define("follow_redirects", type=bool, default=True) args = parse_command_line() - client = SimpleAsyncHTTPClient() + client = AsyncHTTPClient() io_loop = IOLoop.instance() for arg in args: def callback(response):