]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Move USE_SIMPLE_HTTPCLIENT environment check out of curl_httpclient
authorBen Darnell <ben@bendarnell.com>
Tue, 22 Feb 2011 20:14:32 +0000 (12:14 -0800)
committerBen Darnell <ben@bendarnell.com>
Tue, 22 Feb 2011 20:14:32 +0000 (12:14 -0800)
tornado/curl_httpclient.py
tornado/httpclient.py
tornado/simple_httpclient.py

index f662918a06dfb8da80c99aa3cf566b8a7ae99c9d..c00f1945f9ad102c69997e4fee359265eeec42bc 100644 (file)
@@ -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()
index ae028b77a8c4e0768bbbe125b3be697fc54f47a6..39f7102ac730c8498e9897ee993e0cfd87255b2c 100644 (file)
@@ -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()
index 3a7884ef220fa20a61fc5b1f834c691218c96ee3..333d3efaf9e94216830bd68c83d81940cfddaa22 100644 (file)
@@ -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):