class_docstr: An non-blocking HTTP client.
  
  Example usage::
  
      def handle_response(response):
          if response.error:
              print("Error: %s" % response.error)
          else:
              print(response.body)
  
      http_client = AsyncHTTPClient()
      http_client.fetch("http://www.google.com/", handle_response)
  
  The constructor for this class is magic in several respects: It
  actually creates an instance of an implementation-specific
  subclass, and instances are reused as a kind of pseudo-singleton
  (one per `.IOLoop`).  The keyword argument ``force_instance=True``
  can be used to suppress this singleton behavior.  Unless
  ``force_instance=True`` is used, no arguments other than
  ``io_loop`` should be passed to the `AsyncHTTPClient` constructor.
  The implementation subclass as well as arguments to its
  constructor can be set with the static method `configure()`
  
  All `AsyncHTTPClient` implementations support a ``defaults``
  keyword argument, which can be used to set default values for
  `HTTPRequest` attributes.  For example::
  
      AsyncHTTPClient.configure(
          None, defaults=dict(user_agent="MyUserAgent"))
      # or with force_instance:
      client = AsyncHTTPClient(force_instance=True,
          defaults=dict(user_agent="MyUserAgent"))
  
  .. versionchanged:: 4.1
     The ``io_loop`` argument is deprecated.
class_docstr_tok: ["An","non-blocking","HTTP","client",".","Example","usage",":",":","def","handle_response","(","response",")",":","if","response.error",":","print","(","``","Error",":","%","s","''","%","response.error",")","else",":","print","(","response.body",")","http_client","=","AsyncHTTPClient","(",")","http_client.fetch","(","``","http",":","\/\/www.google.com\/","''",",","handle_response",")","The","constructor","for","this","class","is","magic","in","several","respects",":","It","actually","creates","an","instance","of","an","implementation-specific","subclass",",","and","instances","are","reused","as","a","kind","of","pseudo-singleton","(","one","per","`",".IOLoop","`",")",".","The","keyword","argument","``","force_instance=True","``","can","be","used","to","suppress","this","singleton","behavior",".","Unless","``","force_instance=True","``","is","used",",","no","arguments","other","than","``","io_loop","``","should","be","passed","to","the","`","AsyncHTTPClient","`","constructor",".","The","implementation","subclass","as","well","as","arguments","to","its","constructor","can","be","set","with","the","static","method","`","configure","(",")","`","All","`","AsyncHTTPClient","`","implementations","support","a","``","defaults","``","keyword","argument",",","which","can","be","used","to","set","default","values","for","`","HTTPRequest","`","attributes",".","For","example",":",":","AsyncHTTPClient.configure","(","None",",","defaults=dict","(","user_agent=","''","MyUserAgent","''",")",")","#","or","with","force_instance",":","client","=","AsyncHTTPClient","(","force_instance=True",",","defaults=dict","(","user_agent=","''","MyUserAgent","''",")",")","..","versionchanged",":",":","4.1","The","``","io_loop","``","argument","is","deprecated","."]
docstr: Executes a request, asynchronously returning an `HTTPResponse`.
  
  The request may be either a string URL or an `HTTPRequest` object.
  If it is a string, we construct an `HTTPRequest` using any additional
  kwargs: ``HTTPRequest(request, **kwargs)``
  
  This method returns a `.Future` whose result is an
  `HTTPResponse`. By default, the ``Future`` will raise an
  `HTTPError` if the request returned a non-200 response code
  (other errors may also be raised if the server could not be
  contacted). Instead, if ``raise_error`` is set to False, the
  response will always be returned regardless of the response
  code.
  
  If a ``callback`` is given, it will be invoked with the `HTTPResponse`.
  In the callback interface, `HTTPError` is not automatically raised.
  Instead, you must check the response's ``error`` attribute or
  call its `~HTTPResponse.rethrow` method.
code: def fetch(self, request, callback=None, raise_error=True, **kwargs):
      """Executes a request, asynchronously returning an `HTTPResponse`.
  
      The request may be either a string URL or an `HTTPRequest` object.
      If it is a string, we construct an `HTTPRequest` using any additional
      kwargs: ``HTTPRequest(request, **kwargs)``
  
      This method returns a `.Future` whose result is an
      `HTTPResponse`. By default, the ``Future`` will raise an
      `HTTPError` if the request returned a non-200 response code
      (other errors may also be raised if the server could not be
      contacted). Instead, if ``raise_error`` is set to False, the
      response will always be returned regardless of the response
      code.
  
      If a ``callback`` is given, it will be invoked with the `HTTPResponse`.
      In the callback interface, `HTTPError` is not automatically raised.
      Instead, you must check the response's ``error`` attribute or
      call its `~HTTPResponse.rethrow` method.
      """
      if self._closed:
          raise RuntimeError("fetch() called on closed AsyncHTTPClient")
      if not isinstance(request, HTTPRequest):
          request = HTTPRequest(url=request, **kwargs)
      else:
          if kwargs:
              raise ValueError(
                  "kwargs can't be used if request is an HTTPRequest object"
              )
      # We may modify this (to add Host, Accept-Encoding, etc),
      # so make sure we don't modify the caller's object.  This is also
      # where normal dicts get converted to HTTPHeaders objects.
      request.headers = httputil.HTTPHeaders(request.headers)
      request = _RequestProxy(request, self.defaults)
      future = TracebackFuture()
      if callback is not None:
          callback = stack_context.wrap(callback)
  
          def handle_future(future):
              exc = future.exception()
              if (
                  isinstance(exc, HTTPError)
                  and exc.response is not None
              ):
                  response = exc.response
              elif exc is not None:
                  response = HTTPResponse(
                      request,
                      599,
                      error=exc,
                      request_time=time.time() - request.start_time,
                  )
              else:
                  response = future.result()
              self.io_loop.add_callback(callback, response)
  
          future.add_done_callback(handle_future)
  
      def handle_response(response):
          if raise_error and response.error:
              future.set_exception(response.error)
          else:
              future.set_result(response)
  
      self.fetch_impl(request, handle_response)
      return future
  
imports: from __future__ import absolute_import, division, print_function
  import functools
  import time
  import weakref
  from tornado.concurrent import TracebackFuture
  from tornado.escape import utf8, native_str
  from tornado import httputil, stack_context
  from tornado.ioloop import IOLoop
  from tornado.util import Configurable
label_desc: Use image node_id 7 for calling the AsyncHTTPClient obj's underlying member method code with example usage: obj.fetch(request, callback, raise_error) and returns: future