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
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()
import httplib
+import os
import time
from tornado.escape import utf8
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()
_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.
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.
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()
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
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):