class_docstr: An non-blocking HTTP client.
  
  Example usage::
  
      async def f():
          http_client = AsyncHTTPClient()
          try:
              response = await http_client.fetch("http://www.google.com")
          except Exception as e:
              print("Error: %s" % e)
          else:
              print(response.body)
  
  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 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:: 5.0
     The ``io_loop`` argument (deprecated since version 4.1) has been removed.
class_docstr_tok: ["An","non-blocking","HTTP","client",".","Example","usage",":",":","async","def","f","(",")",":","http_client","=","AsyncHTTPClient","(",")","try",":","response","=","await","http_client.fetch","(","``","http",":","\/\/www.google.com","''",")","except","Exception","as","e",":","print","(","``","Error",":","%","s","''","%","e",")","else",":","print","(","response.body",")","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","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",":",":","5.0","The","``","io_loop","``","argument","(","deprecated","since","version","4.1",")","has","been","removed","."]
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.
  
  .. versionchanged:: 6.0
  
     The ``callback`` argument was removed. Use the returned
     `.Future` instead.
  
     The ``raise_error=False`` argument only affects the
     `HTTPError` raised when a non-200 response code is used,
     instead of suppressing all errors.
docstr_tok: ["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",".","..","versionchanged",":",":","6.0","The","``","callback","``","argument","was","removed",".","Use","the","returned","`",".Future","`","instead",".","The","``","raise_error=False","``","argument","only","affects","the","`","HTTPError","`","raised","when","a","non-200","response","code","is","used",",","instead","of","suppressing","all","errors","."]
code: def fetch(
      self,
      request: Union[str, "HTTPRequest"],
      raise_error: bool = True,
      **kwargs: Any,
  ) -> "Future[HTTPResponse]":
      """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.
  
      .. versionchanged:: 6.0
  
         The ``callback`` argument was removed. Use the returned
         `.Future` instead.
  
         The ``raise_error=False`` argument only affects the
         `HTTPError` raised when a non-200 response code is used,
         instead of suppressing all errors.
      """
      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_proxy = _RequestProxy(request, self.defaults)
      future = Future()  # type: Future[HTTPResponse]
  
      def handle_response(response: "HTTPResponse") -> None:
          if response.error:
              if raise_error or not response._error_is_response_code:
                  future_set_exception_unless_cancelled(
                      future, response.error
                  )
                  return
          future_set_result_unless_cancelled(future, response)
  
      self.fetch_impl(cast(HTTPRequest, request_proxy), handle_response)
      return future
  
imports: import datetime
  import functools
  from io import BytesIO
  import ssl
  import time
  import weakref
  from tornado.concurrent import Future, future_set_result_unless_cancelled, future_set_exception_unless_cancelled
  from tornado.escape import utf8, native_str
  from tornado import gen, httputil
  from tornado.ioloop import IOLoop
  from tornado.util import Configurable
  from typing import Type, Any, Union, Dict, Callable, Optional, cast
label_desc: Use image node_id 7 for calling the AsyncHTTPClient obj's underlying member method code with example usage: obj.fetch(request, raise_error) and returns: future