ó
¨œž[c           @` sÇ  d  Z  d d l m Z m Z m Z d d l Z d d l Z d d l Z d d l Z d d l	 Z	 d d l
 Z
 d d l Z d d l m Z m Z m Z m Z m Z m Z d d l m Z d d l m Z d d l m Z d d l m Z m Z m Z y< y d d	 l m Z Wn! e k
 r*d d	 l m Z n XWn, e k
 rZd
 e j k rQ‚  n  d Z n Xyt y d d l! m" Z# Wn! e k
 r•d d l$ m" Z# n Xy d d l% m& Z& Wn! e k
 rÍd d l$ m& Z& n XWn? e k
 rd
 e j k rô‚  n  d d l
 m# Z# d „  Z& n Xe r&d d l' Z' n d d l( Z' d e) f d „  ƒ  YZ* d e) f d „  ƒ  YZ+ d e) f d „  ƒ  YZ, d e) f d „  ƒ  YZ- d e) f d „  ƒ  YZ. d „  Z/ d „  Z0 d „  Z1 d „  Z2 d „  Z3 d „  Z4 d e) f d  „  ƒ  YZ5 d! e6 f d" „  ƒ  YZ7 d# e6 f d$ „  ƒ  YZ8 d% e8 f d& „  ƒ  YZ9 d' e8 f d( „  ƒ  YZ: d) e8 f d* „  ƒ  YZ; d+ „  Z< d, e8 f d- „  ƒ  YZ= d. „  Z> dB d/ „ Z? e? Z@ d0 e8 f d1 „  ƒ  YZA dC d2 „ ZB d3 „  ZC dD d4 „ ZD d5 „  ZE d6 e6 f d7 „  ƒ  YZF eF ƒ  ZG eF ƒ  ZH d8 eH _  d9 e6 f d: „  ƒ  YZI e jJ d; d< d= g ƒ ZK d> „  ZL y d d lM ZM Wn  e k
 rne2 d? „  ƒ ZN n1 Xy eM jO ZN Wn  eP k
 ržeQ eM d@ ƒ ZN n XdA „  ZR e d k	 rÃe eR ƒ ZR n  d S(E   s@  ``tornado.gen`` implements generator-based coroutines.

.. note::

   The "decorator and generator" approach in this module is a
   precursor to native coroutines (using ``async def`` and ``await``)
   which were introduced in Python 3.5. Applications that do not
   require compatibility with older versions of Python should use
   native coroutines instead. Some parts of this module are still
   useful with native coroutines, notably `multi`, `sleep`,
   `WaitIterator`, and `with_timeout`. Some of these functions have
   counterparts in the `asyncio` module which may be used as well,
   although the two may not necessarily be 100% compatible.

Coroutines provide an easier way to work in an asynchronous
environment than chaining callbacks. Code using coroutines is
technically asynchronous, but it is written as a single generator
instead of a collection of separate functions.

For example, the following callback-based asynchronous handler:

.. testcode::

    class AsyncHandler(RequestHandler):
        @asynchronous
        def get(self):
            http_client = AsyncHTTPClient()
            http_client.fetch("http://example.com",
                              callback=self.on_fetch)

        def on_fetch(self, response):
            do_something_with_response(response)
            self.render("template.html")

.. testoutput::
   :hide:

could be written with ``gen`` as:

.. testcode::

    class GenAsyncHandler(RequestHandler):
        @gen.coroutine
        def get(self):
            http_client = AsyncHTTPClient()
            response = yield http_client.fetch("http://example.com")
            do_something_with_response(response)
            self.render("template.html")

.. testoutput::
   :hide:

Most asynchronous functions in Tornado return a `.Future`;
yielding this object returns its ``Future.result``.

You can also yield a list or dict of ``Futures``, which will be
started at the same time and run in parallel; a list or dict of results will
be returned when they are all finished:

.. testcode::

    @gen.coroutine
    def get(self):
        http_client = AsyncHTTPClient()
        response1, response2 = yield [http_client.fetch(url1),
                                      http_client.fetch(url2)]
        response_dict = yield dict(response3=http_client.fetch(url3),
                                   response4=http_client.fetch(url4))
        response3 = response_dict['response3']
        response4 = response_dict['response4']

.. testoutput::
   :hide:

If the `~functools.singledispatch` library is available (standard in
Python 3.4, available via the `singledispatch
<https://pypi.python.org/pypi/singledispatch>`_ package on older
versions), additional types of objects may be yielded. Tornado includes
support for ``asyncio.Future`` and Twisted's ``Deferred`` class when
``tornado.platform.asyncio`` and ``tornado.platform.twisted`` are imported.
See the `convert_yielded` function to extend this mechanism.

.. versionchanged:: 3.2
   Dict support added.

.. versionchanged:: 4.1
   Support added for yielding ``asyncio`` Futures and Twisted Deferreds
   via ``singledispatch``.

i    (   t   absolute_importt   divisiont   print_functionN(   t   Futuret	   is_futuret   chain_futuret   future_set_exc_infot   future_add_done_callbackt"   future_set_result_unless_cancelled(   t   IOLoop(   t   app_log(   t   stack_context(   t   PY3t   raise_exc_infot   TimeoutError(   t   singledispatcht   APPENGINE_RUNTIME(   t	   Generator(   t   isawaitable(   t   GeneratorTypec         C` s   t  S(   N(   t   False(   t   x(    (    s*   lib/python2.7/site-packages/tornado/gen.pyR   Ž   s    t   KeyReuseErrorc           B` s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s*   lib/python2.7/site-packages/tornado/gen.pyR   —   s   t   UnknownKeyErrorc           B` s   e  Z RS(    (   R   R   (    (    (    s*   lib/python2.7/site-packages/tornado/gen.pyR   ›   s   t   LeakedCallbackErrorc           B` s   e  Z RS(    (   R   R   (    (    (    s*   lib/python2.7/site-packages/tornado/gen.pyR   Ÿ   s   t   BadYieldErrorc           B` s   e  Z RS(    (   R   R   (    (    (    s*   lib/python2.7/site-packages/tornado/gen.pyR   £   s   t   ReturnValueIgnoredErrorc           B` s   e  Z RS(    (   R   R   (    (    (    s*   lib/python2.7/site-packages/tornado/gen.pyR   §   s   c         C` sM   y |  j  SWn t k
 r n Xy |  j d SWn t t f k
 rH d  SXd  S(   Ni    (   t   valuet   AttributeErrort   argst
   IndexErrort   None(   t   e(    (    s*   lib/python2.7/site-packages/tornado/gen.pyt   _value_from_stopiteration«   s    c          C` sQ   t  ƒ  }  t |  d d ƒ } x/ | rL | d d } | t k rH | d =q Pq W|  S(   Nt   _source_tracebackiÿÿÿÿi    (    (   R   t   getattrt   __file__(   t   futuret   source_tracebackt   filename(    (    s*   lib/python2.7/site-packages/tornado/gen.pyt   _create_futureº   s    		
c         ` sD   t  j d t ƒ t ˆ  d t ƒ‰  t j ˆ  ƒ ‡  f d †  ƒ } | S(   s<  Callback-oriented decorator for asynchronous generators.

    This is an older interface; for new code that does not need to be
    compatible with versions of Tornado older than 3.0 the
    `coroutine` decorator is recommended instead.

    This decorator is similar to `coroutine`, except it does not
    return a `.Future` and the ``callback`` argument is not treated
    specially.

    In most cases, functions decorated with `engine` should take
    a ``callback`` argument and invoke it with their result when
    they are finished.  One notable exception is the
    `~tornado.web.RequestHandler` :ref:`HTTP verb methods <verbs>`,
    which use ``self.finish()`` in place of a callback argument.

    .. deprecated:: 5.1

       This decorator will be removed in 6.0. Use `coroutine` or
       ``async def`` instead.
    s@   gen.engine is deprecated, use gen.coroutine or async def insteadt   replace_callbackc          ` s2   ˆ  |  | Ž  } d „  } t  | t j | ƒ ƒ d  S(   Nc         S` s2   |  j  ƒ  d  k	 r. t d |  j  ƒ  f ƒ ‚ n  d  S(   Ns.   @gen.engine functions cannot return values: %r(   t   resultR!   R   (   R'   (    (    s*   lib/python2.7/site-packages/tornado/gen.pyt   final_callbackç   s    (   R   R   t   wrap(   R   t   kwargsR'   R-   (   t   func(    s*   lib/python2.7/site-packages/tornado/gen.pyt   wrapperã   s    	(   t   warningst   warnt   DeprecationWarningt   _make_coroutine_wrapperR   t	   functoolst   wraps(   R0   R1   (    (   R0   s*   lib/python2.7/site-packages/tornado/gen.pyt   engineÉ   s
    	c         C` s   t  |  d t ƒS(   sP  Decorator for asynchronous generators.

    Any generator that yields objects from this module must be wrapped
    in either this decorator or `engine`.

    Coroutines may "return" by raising the special exception
    `Return(value) <Return>`.  In Python 3.3+, it is also possible for
    the function to simply use the ``return value`` statement (prior to
    Python 3.3 generators were not allowed to also return values).
    In all versions of Python a coroutine that simply wishes to exit
    early may use the ``return`` statement without a value.

    Functions with this decorator return a `.Future`.  Additionally,
    they may be called with a ``callback`` keyword argument, which
    will be invoked with the future's result when it resolves.  If the
    coroutine fails, the callback will not be run and an exception
    will be raised into the surrounding `.StackContext`.  The
    ``callback`` argument is not visible inside the decorated
    function; it is handled by the decorator itself.

    .. warning::

       When exceptions occur inside a coroutine, the exception
       information will be stored in the `.Future` object. You must
       examine the result of the `.Future` object, or the exception
       may go unnoticed by your code. This means yielding the function
       if called from another coroutine, using something like
       `.IOLoop.run_sync` for top-level calls, or passing the `.Future`
       to `.IOLoop.add_future`.

    .. deprecated:: 5.1

       The ``callback`` argument is deprecated and will be removed in 6.0.
       Use the returned awaitable object instead.
    R+   (   R5   t   True(   R0   (    (    s*   lib/python2.7/site-packages/tornado/gen.pyt	   coroutineó   s    $c         ` s^   ˆ  } t  t d ƒ r' t j ˆ  ƒ ‰  n  t j | ƒ ‡  ‡ f d †  ƒ } | | _ t | _ | S(   sà   The inner workings of ``@gen.coroutine`` and ``@gen.engine``.

    The two decorators differ in their treatment of the ``callback``
    argument, so we cannot simply implement ``@engine`` in terms of
    ``@coroutine``.
    R:   c          ` s×  t  ƒ  } ˆ rb d | k rb t j d t d d ƒ| j d ƒ ‰  t j ƒ  j | ‡  f d †  ƒ n  y ˆ |  | Ž  } WnZ t t	 f k
 rœ } t
 | ƒ } n*t k
 rÑ t | t j ƒ  ƒ z | SWd  d  } Xnõ Xt | t ƒ rÆyP t j j } t | ƒ } t j j | k	 r0t  ƒ  } | j t j d ƒ ƒ n  WnO t	 t f k
 r_} t | t
 | ƒ ƒ nL t k
 r‚t | t j ƒ  ƒ n) Xt | | | ƒ ‰ | j ‡ f d †  ƒ d  } z | SWd  d  } Xn  t | | ƒ | S(   Nt   callbacksB   callback arguments are deprecated, use the returned Future insteadt
   stackleveli   c         ` s   ˆ  |  j  ƒ  ƒ S(   N(   R,   (   R'   (   R;   (    s*   lib/python2.7/site-packages/tornado/gen.pyt   <lambda>0  s    sY   stack_context inconsistency (probably caused by yield within a "with StackContext" block)c         ` s   ˆ  S(   N(    (   t   _(   t   runner(    s*   lib/python2.7/site-packages/tornado/gen.pyR=   [  s    (   R*   R2   R3   R4   t   popR	   t   currentt
   add_futuret   Returnt   StopIterationR#   t	   ExceptionR   t   syst   exc_infoR!   t
   isinstanceR   R   t   _statet   contextst   nextt   set_exceptiont   StackContextInconsistentErrorR   t   Runnert   add_done_callback(   R   R/   R'   R,   R"   t   orig_stack_contextst   yielded(   R0   R+   (   R;   R?   s*   lib/python2.7/site-packages/tornado/gen.pyR1   '  sJ    			


(   t   hasattrt   typesR:   R6   R7   t   __wrapped__R9   t   __tornado_coroutine__(   R0   R+   t   wrappedR1   (    (   R0   R+   s*   lib/python2.7/site-packages/tornado/gen.pyR5     s    	!E		c         C` s   t  |  d t ƒ S(   s‚   Return whether *func* is a coroutine function, i.e. a function
    wrapped with `~.gen.coroutine`.

    .. versionadded:: 4.5
    RU   (   R%   R   (   R0   (    (    s*   lib/python2.7/site-packages/tornado/gen.pyt   is_coroutine_functionq  s    RC   c           B` s   e  Z d  Z d d „ Z RS(   sõ  Special exception to return a value from a `coroutine`.

    If this exception is raised, its value argument is used as the
    result of the coroutine::

        @gen.coroutine
        def fetch_json(url):
            response = yield AsyncHTTPClient().fetch(url)
            raise gen.Return(json_decode(response.body))

    In Python 3.3, this exception is no longer necessary: the ``return``
    statement can be used directly to return a value (previously
    ``yield`` and ``return`` with a value could not be combined in the
    same function).

    By analogy with the return statement, the value argument is optional,
    but it is never necessary to ``raise gen.Return()``.  The ``return``
    statement can be used with no arguments instead.
    c         C` s,   t  t |  ƒ j ƒ  | |  _ | f |  _ d  S(   N(   t   superRC   t   __init__R   R   (   t   selfR   (    (    s*   lib/python2.7/site-packages/tornado/gen.pyRY   Ž  s    	N(   R   R   t   __doc__R!   RY   (    (    (    s*   lib/python2.7/site-packages/tornado/gen.pyRC   z  s   t   WaitIteratorc           B` sM   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 RS(   s˜  Provides an iterator to yield the results of futures as they finish.

    Yielding a set of futures like this:

    ``results = yield [future1, future2]``

    pauses the coroutine until both ``future1`` and ``future2``
    return, and then restarts the coroutine with the results of both
    futures. If either future is an exception, the expression will
    raise that exception and all the results will be lost.

    If you need to get the result of each future as soon as possible,
    or if you need the result of some futures even if others produce
    errors, you can use ``WaitIterator``::

      wait_iterator = gen.WaitIterator(future1, future2)
      while not wait_iterator.done():
          try:
              result = yield wait_iterator.next()
          except Exception as e:
              print("Error {} from {}".format(e, wait_iterator.current_future))
          else:
              print("Result {} received from {} at {}".format(
                  result, wait_iterator.current_future,
                  wait_iterator.current_index))

    Because results are returned as soon as they are available the
    output from the iterator *will not be in the same order as the
    input arguments*. If you need to know which future produced the
    current result, you can use the attributes
    ``WaitIterator.current_future``, or ``WaitIterator.current_index``
    to get the index of the future from the input list. (if keyword
    arguments were used in the construction of the `WaitIterator`,
    ``current_index`` will use the corresponding keyword).

    On Python 3.5, `WaitIterator` implements the async iterator
    protocol, so it can be used with the ``async for`` statement (note
    that in this version the entire iteration is aborted if any value
    raises an exception, while the previous example can continue past
    individual errors)::

      async for result in gen.WaitIterator(future1, future2):
          print("Result {} received from {} at {}".format(
              result, wait_iterator.current_future,
              wait_iterator.current_index))

    .. versionadded:: 4.1

    .. versionchanged:: 4.3
       Added ``async for`` support in Python 3.5.

    c         O` sÇ   | r | r t  d ƒ ‚ n  | rU t d „  | j ƒ  Dƒ ƒ |  _ t | j ƒ  ƒ } n% t d „  t | ƒ Dƒ ƒ |  _ | } t j ƒ  |  _	 d  |  _ |  _ d  |  _ x | D] } t | |  j ƒ q© Wd  S(   Ns)   You must provide args or kwargs, not bothc         s` s!   |  ] \ } } | | f Vq d  S(   N(    (   t   .0t   kt   f(    (    s*   lib/python2.7/site-packages/tornado/gen.pys	   <genexpr>Ð  s    c         s` s!   |  ] \ } } | | f Vq d  S(   N(    (   R]   t   iR_   (    (    s*   lib/python2.7/site-packages/tornado/gen.pys	   <genexpr>Ó  s    (   t
   ValueErrort   dictt   itemst   _unfinishedt   listt   valuest	   enumeratet   collectionst   dequet	   _finishedR!   t   current_indext   current_futuret   _running_futureR   t   _done_callback(   RZ   R   R/   t   futuresR'   (    (    s*   lib/python2.7/site-packages/tornado/gen.pyRY   Ê  s    	c         C` s*   |  j  s |  j r t Sd |  _ |  _ t S(   s2   Returns True if this iterator has no more results.N(   Rj   Rd   R   R!   Rk   Rl   R9   (   RZ   (    (    s*   lib/python2.7/site-packages/tornado/gen.pyt   doneÝ  s    c         C` s5   t  ƒ  |  _ |  j r. |  j |  j j ƒ  ƒ n  |  j S(   s£   Returns a `.Future` that will yield the next available result.

        Note that this `.Future` will not be the same object as any of
        the inputs.
        (   R   Rm   Rj   t   _return_resultt   popleft(   RZ   (    (    s*   lib/python2.7/site-packages/tornado/gen.pyRK   å  s    	c         C` s=   |  j  r) |  j  j ƒ  r) |  j | ƒ n |  j j | ƒ d  S(   N(   Rm   Rp   Rq   Rj   t   append(   RZ   Rp   (    (    s*   lib/python2.7/site-packages/tornado/gen.pyRn   ò  s    c         C` s2   t  | |  j ƒ | |  _ |  j j | ƒ |  _ d S(   sƒ   Called set the returned future's state that of the future
        we yielded, and set the current future for the iterator.
        N(   R   Rm   Rl   Rd   R@   Rk   (   RZ   Rp   (    (    s*   lib/python2.7/site-packages/tornado/gen.pyRq   ø  s    	c         C` s   |  S(   N(    (   RZ   (    (    s*   lib/python2.7/site-packages/tornado/gen.pyt	   __aiter__  s    c         C` s+   |  j  ƒ  r! t t d ƒ ƒ  ‚ n  |  j ƒ  S(   Nt   StopAsyncIteration(   Rp   R%   t   builtinsRK   (   RZ   (    (    s*   lib/python2.7/site-packages/tornado/gen.pyt	   __anext__  s    (
   R   R   R[   RY   Rp   RK   Rn   Rq   Rt   Rw   (    (    (    s*   lib/python2.7/site-packages/tornado/gen.pyR\   •  s   4							t
   YieldPointc           B` s2   e  Z d  Z d „  Z d „  Z d „  Z d „  Z RS(   sÄ   Base class for objects that may be yielded from the generator.

    .. deprecated:: 4.0
       Use `Futures <.Future>` instead. This class and all its subclasses
       will be removed in 6.0
    c         C` s   t  j d t ƒ d  S(   Ns-   YieldPoint is deprecated, use Futures instead(   R2   R3   R4   (   RZ   (    (    s*   lib/python2.7/site-packages/tornado/gen.pyRY     s    	c         C` s   t  ƒ  ‚ d S(   sˆ   Called by the runner after the generator has yielded.

        No other methods will be called on this object before ``start``.
        N(   t   NotImplementedError(   RZ   R?   (    (    s*   lib/python2.7/site-packages/tornado/gen.pyt   start  s    c         C` s   t  ƒ  ‚ d S(   s…   Called by the runner to determine whether to resume the generator.

        Returns a boolean; may be called more than once.
        N(   Ry   (   RZ   (    (    s*   lib/python2.7/site-packages/tornado/gen.pyt   is_ready  s    c         C` s   t  ƒ  ‚ d S(   s¬   Returns the value to use as the result of the yield expression.

        This method will only be called once, and only after `is_ready`
        has returned true.
        N(   Ry   (   RZ   (    (    s*   lib/python2.7/site-packages/tornado/gen.pyt
   get_result$  s    (   R   R   R[   RY   Rz   R{   R|   (    (    (    s*   lib/python2.7/site-packages/tornado/gen.pyRx     s
   			t   Callbackc           B` s2   e  Z d  Z d „  Z d „  Z d „  Z d „  Z RS(   s„  Returns a callable object that will allow a matching `Wait` to proceed.

    The key may be any value suitable for use as a dictionary key, and is
    used to match ``Callbacks`` to their corresponding ``Waits``.  The key
    must be unique among outstanding callbacks within a single run of the
    generator function, but may be reused across different runs of the same
    function (so constants generally work fine).

    The callback may be called with zero or one arguments; if an argument
    is given it will be returned by `Wait`.

    .. deprecated:: 4.0
       Use `Futures <.Future>` instead. This class will be removed in 6.0.
    c         C` s   t  j d t ƒ | |  _ d  S(   Ns/   gen.Callback is deprecated, use Futures instead(   R2   R3   R4   t   key(   RZ   R~   (    (    s*   lib/python2.7/site-packages/tornado/gen.pyRY   <  s    	c         C` s   | |  _  | j |  j ƒ d  S(   N(   R?   t   register_callbackR~   (   RZ   R?   (    (    s*   lib/python2.7/site-packages/tornado/gen.pyRz   A  s    	c         C` s   t  S(   N(   R9   (   RZ   (    (    s*   lib/python2.7/site-packages/tornado/gen.pyR{   E  s    c         C` s   |  j  j |  j ƒ S(   N(   R?   t   result_callbackR~   (   RZ   (    (    s*   lib/python2.7/site-packages/tornado/gen.pyR|   H  s    (   R   R   R[   RY   Rz   R{   R|   (    (    (    s*   lib/python2.7/site-packages/tornado/gen.pyR}   -  s
   			t   Waitc           B` s2   e  Z d  Z d „  Z d „  Z d „  Z d „  Z RS(   s¬   Returns the argument passed to the result of a previous `Callback`.

    .. deprecated:: 4.0
       Use `Futures <.Future>` instead. This class will be removed in 6.0.
    c         C` s   t  j d t ƒ | |  _ d  S(   Ns+   gen.Wait is deprecated, use Futures instead(   R2   R3   R4   R~   (   RZ   R~   (    (    s*   lib/python2.7/site-packages/tornado/gen.pyRY   R  s    	c         C` s   | |  _  d  S(   N(   R?   (   RZ   R?   (    (    s*   lib/python2.7/site-packages/tornado/gen.pyRz   W  s    c         C` s   |  j  j |  j ƒ S(   N(   R?   R{   R~   (   RZ   (    (    s*   lib/python2.7/site-packages/tornado/gen.pyR{   Z  s    c         C` s   |  j  j |  j ƒ S(   N(   R?   t
   pop_resultR~   (   RZ   (    (    s*   lib/python2.7/site-packages/tornado/gen.pyR|   ]  s    (   R   R   R[   RY   Rz   R{   R|   (    (    (    s*   lib/python2.7/site-packages/tornado/gen.pyR   L  s
   			t   WaitAllc           B` s2   e  Z d  Z d „  Z d „  Z d „  Z d „  Z RS(   s[  Returns the results of multiple previous `Callbacks <Callback>`.

    The argument is a sequence of `Callback` keys, and the result is
    a list of results in the same order.

    `WaitAll` is equivalent to yielding a list of `Wait` objects.

    .. deprecated:: 4.0
       Use `Futures <.Future>` instead. This class will be removed in 6.0.
    c         C` s   t  j d t ƒ | |  _ d  S(   Ns0   gen.WaitAll is deprecated, use gen.multi instead(   R2   R3   R4   t   keys(   RZ   R„   (    (    s*   lib/python2.7/site-packages/tornado/gen.pyRY   l  s    	c         C` s   | |  _  d  S(   N(   R?   (   RZ   R?   (    (    s*   lib/python2.7/site-packages/tornado/gen.pyRz   q  s    c         ` s   t  ‡  f d †  ˆ  j Dƒ ƒ S(   Nc         3` s!   |  ] } ˆ  j  j | ƒ Vq d  S(   N(   R?   R{   (   R]   R~   (   RZ   (    s*   lib/python2.7/site-packages/tornado/gen.pys	   <genexpr>u  s    (   t   allR„   (   RZ   (    (   RZ   s*   lib/python2.7/site-packages/tornado/gen.pyR{   t  s    c         C` s&   g  |  j  D] } |  j j | ƒ ^ q
 S(   N(   R„   R?   R‚   (   RZ   R~   (    (    s*   lib/python2.7/site-packages/tornado/gen.pyR|   w  s    (   R   R   R[   RY   Rz   R{   R|   (    (    (    s*   lib/python2.7/site-packages/tornado/gen.pyRƒ   a  s
   
			c      	   ` sj   t  j d t ƒ t ƒ  ‰  ‡  f d †  } ‡  f d †  } t j | ƒ  |  d t | ƒ | | Ž Wd QXˆ  S(   sA  Adapts a callback-based asynchronous function for use in coroutines.

    Takes a function (and optional additional arguments) and runs it with
    those arguments plus a ``callback`` keyword argument.  The argument passed
    to the callback is returned as the result of the yield expression.

    .. versionchanged:: 4.0
       ``gen.Task`` is now a function that returns a `.Future`, instead of
       a subclass of `YieldPoint`.  It still behaves the same way when
       yielded.

    .. deprecated:: 5.1
       This function is deprecated and will be removed in 6.0.
    s+   gen.Task is deprecated, use Futures insteadc         ` s*   ˆ  j  ƒ  r t St ˆ  |  | | f ƒ t S(   N(   Rp   R   R   R9   (   t   typR   t   tb(   R'   (    s*   lib/python2.7/site-packages/tornado/gen.pyt   handle_exceptionŽ  s    c         ` s!   ˆ  j  ƒ  r d  St ˆ  |  ƒ d  S(   N(   Rp   R   (   R,   (   R'   (    s*   lib/python2.7/site-packages/tornado/gen.pyt
   set_result”  s    R;   N(   R2   R3   R4   R*   R   t   ExceptionStackContextt   _argument_adapter(   R0   R   R/   Rˆ   R‰   (    (   R'   s*   lib/python2.7/site-packages/tornado/gen.pyt   Task{  s    		t   YieldFuturec           B` s,   e  Z d  „  Z d „  Z d „  Z d „  Z RS(   c         C` s,   t  j d t ƒ | |  _ t j ƒ  |  _ d S(   sû   Adapts a `.Future` to the `YieldPoint` interface.

        .. versionchanged:: 5.0
           The ``io_loop`` argument (deprecated since version 4.1) has been removed.

        .. deprecated:: 5.1
           This class will be removed in 6.0.
        s.   YieldFuture is deprecated, use Futures insteadN(   R2   R3   R4   R'   R	   RA   t   io_loop(   RZ   R'   (    (    s*   lib/python2.7/site-packages/tornado/gen.pyRY   ž  s    			c         C` su   |  j  j ƒ  sY | |  _ t ƒ  |  _ | j |  j ƒ |  j j |  j  | j |  j ƒ ƒ n d  |  _ |  j  j
 |  _ d  S(   N(   R'   Rp   R?   t   objectR~   R   RŽ   RB   R€   R!   R,   t	   result_fn(   RZ   R?   (    (    s*   lib/python2.7/site-packages/tornado/gen.pyRz   ¬  s    	%	c         C` s*   |  j  d  k	 r" |  j  j |  j ƒ St Sd  S(   N(   R?   R!   R{   R~   R9   (   RZ   (    (    s*   lib/python2.7/site-packages/tornado/gen.pyR{   ¶  s    c         C` s6   |  j  d  k	 r( |  j  j |  j ƒ j ƒ  S|  j ƒ  Sd  S(   N(   R?   R!   R‚   R~   R,   R   (   RZ   (    (    s*   lib/python2.7/site-packages/tornado/gen.pyR|   ¼  s    (   R   R   RY   Rz   R{   R|   (    (    (    s*   lib/python2.7/site-packages/tornado/gen.pyR     s   		
	c         C` sP   t  |  t ƒ r) t d „  |  j ƒ  Dƒ ƒ St  |  t ƒ rL t d „  |  Dƒ ƒ St S(   s›   Returns True if ``children`` contains any YieldPoints.

    ``children`` may be a dict or a list, as used by `MultiYieldPoint`
    and `multi_future`.
    c         s` s   |  ] } t  | t ƒ Vq d  S(   N(   RH   Rx   (   R]   R`   (    (    s*   lib/python2.7/site-packages/tornado/gen.pys	   <genexpr>Ê  s    c         s` s   |  ] } t  | t ƒ Vq d  S(   N(   RH   Rx   (   R]   R`   (    (    s*   lib/python2.7/site-packages/tornado/gen.pys	   <genexpr>Ì  s    (   RH   Rb   t   anyRf   Re   R   (   t   children(    (    s*   lib/python2.7/site-packages/tornado/gen.pyt   _contains_yieldpointÃ  s
    c         C` s0   t  |  ƒ r t |  d | ƒSt |  d | ƒSd S(   s  Runs multiple asynchronous operations in parallel.

    ``children`` may either be a list or a dict whose values are
    yieldable objects. ``multi()`` returns a new yieldable
    object that resolves to a parallel structure containing their
    results. If ``children`` is a list, the result is a list of
    results in the same order; if it is a dict, the result is a dict
    with the same keys.

    That is, ``results = yield multi(list_of_futures)`` is equivalent
    to::

        results = []
        for future in list_of_futures:
            results.append(yield future)

    If any children raise exceptions, ``multi()`` will raise the first
    one. All others will be logged, unless they are of types
    contained in the ``quiet_exceptions`` argument.

    If any of the inputs are `YieldPoints <YieldPoint>`, the returned
    yieldable object is a `YieldPoint`. Otherwise, returns a `.Future`.
    This means that the result of `multi` can be used in a native
    coroutine if and only if all of its children can be.

    In a ``yield``-based coroutine, it is not normally necessary to
    call this function directly, since the coroutine runner will
    do it automatically when a list or dict is yielded. However,
    it is necessary in ``await``-based coroutines, or to pass
    the ``quiet_exceptions`` argument.

    This function is available under the names ``multi()`` and ``Multi()``
    for historical reasons.

    Cancelling a `.Future` returned by ``multi()`` does not cancel its
    children. `asyncio.gather` is similar to ``multi()``, but it does
    cancel its children.

    .. versionchanged:: 4.2
       If multiple yieldables fail, any exceptions after the first
       (which is raised) will be logged. Added the ``quiet_exceptions``
       argument to suppress this logging for selected exception types.

    .. versionchanged:: 4.3
       Replaced the class ``Multi`` and the function ``multi_future``
       with a unified function ``multi``. Added support for yieldables
       other than `YieldPoint` and `.Future`.

    t   quiet_exceptionsN(   R“   t   MultiYieldPointt   multi_future(   R’   R”   (    (    s*   lib/python2.7/site-packages/tornado/gen.pyt   multiÐ  s    2R•   c           B` s5   e  Z d  Z d d „ Z d „  Z d „  Z d „  Z RS(   sÍ  Runs multiple asynchronous operations in parallel.

    This class is similar to `multi`, but it always creates a stack
    context even when no children require it. It is not compatible with
    native coroutines.

    .. versionchanged:: 4.2
       If multiple ``YieldPoints`` fail, any exceptions after the first
       (which is raised) will be logged. Added the ``quiet_exceptions``
       argument to suppress this logging for selected exception types.

    .. versionchanged:: 4.3
       Renamed from ``Multi`` to ``MultiYieldPoint``. The name ``Multi``
       remains as an alias for the equivalent `multi` function.

    .. deprecated:: 4.3
       Use `multi` instead. This class will be removed in 6.0.
    c         C` sí   t  j d t ƒ d  |  _ t | t ƒ rL t | j ƒ  ƒ |  _ | j ƒ  } n  g  |  _	 xW | D]O } t | t
 ƒ s€ t | ƒ } n  t | ƒ r› t | ƒ } n  |  j	 j | ƒ q\ Wt d „  |  j	 Dƒ ƒ sÎ t ‚ t |  j	 ƒ |  _ | |  _ d  S(   Ns2   MultiYieldPoint is deprecated, use Futures insteadc         s` s   |  ] } t  | t ƒ Vq d  S(   N(   RH   Rx   (   R]   R`   (    (    s*   lib/python2.7/site-packages/tornado/gen.pys	   <genexpr>,  s    (   R2   R3   R4   R!   R„   RH   Rb   Re   Rf   R’   Rx   t   convert_yieldedR   R   Rs   R…   t   AssertionErrort   sett   unfinished_childrenR”   (   RZ   R’   R”   R`   (    (    s*   lib/python2.7/site-packages/tornado/gen.pyRY     s     			c         C` s%   x |  j  D] } | j | ƒ q
 Wd  S(   N(   R’   Rz   (   RZ   R?   R`   (    (    s*   lib/python2.7/site-packages/tornado/gen.pyRz   0  s    c         C` s6   t  t j d „  |  j ƒ ƒ } |  j j | ƒ |  j S(   Nc         S` s
   |  j  ƒ  S(   N(   R{   (   R`   (    (    s*   lib/python2.7/site-packages/tornado/gen.pyR=   6  s    (   Re   t	   itertoolst	   takewhileR›   t   difference_update(   RZ   t   finished(    (    s*   lib/python2.7/site-packages/tornado/gen.pyR{   4  s    	c         C` sÜ   g  } d  } x |  j D]v } y | j | j ƒ  ƒ Wq t k
 r‹ } | d  k r` t j ƒ  } qŒ t | |  j ƒ sŒ t	 j
 d d t ƒqŒ q Xq W| d  k	 r© t | ƒ n  |  j d  k	 rÎ t t |  j | ƒ ƒ St | ƒ Sd  S(   Ns!   Multiple exceptions in yield listRG   (   R!   R’   Rs   R|   RE   RF   RG   RH   R”   R
   t   errorR9   R   R„   Rb   t   zipRe   (   RZ   t   result_listRG   R_   R"   (    (    s*   lib/python2.7/site-packages/tornado/gen.pyR|   :  s     (    (   R   R   R[   RY   Rz   R{   R|   (    (    (    s*   lib/python2.7/site-packages/tornado/gen.pyR•     s
   		c         ` s  t  ˆ  t ƒ r0 t ˆ  j ƒ  ƒ ‰ ˆ  j ƒ  ‰  n d ‰ t t t ˆ  ƒ ƒ ‰  t d „  ˆ  Dƒ ƒ sg t	 ‚ t
 ˆ  ƒ ‰ t ƒ  ‰ ˆ  s¤ t ˆ ˆ d k	 rš i  n g  ƒ n  ‡  ‡ ‡ ‡ ‡ f d †  } t
 ƒ  } x7 ˆ  D]/ } | | k rÏ | j | ƒ t | | ƒ qÏ qÏ Wˆ S(   s×  Wait for multiple asynchronous futures in parallel.

    This function is similar to `multi`, but does not support
    `YieldPoints <YieldPoint>`.

    .. versionadded:: 4.0

    .. versionchanged:: 4.2
       If multiple ``Futures`` fail, any exceptions after the first (which is
       raised) will be logged. Added the ``quiet_exceptions``
       argument to suppress this logging for selected exception types.

    .. deprecated:: 4.3
       Use `multi` instead.
    c         s` s*   |  ]  } t  | ƒ p! t | t ƒ Vq d  S(   N(   R   RH   t   _NullFuture(   R]   R`   (    (    s*   lib/python2.7/site-packages/tornado/gen.pys	   <genexpr>e  s    c         ` sì   ˆ j  |  ƒ ˆ sè g  } x‚ ˆ  D]z }  y | j |  j ƒ  ƒ Wq  t k
 r™ } ˆ j ƒ  rƒ t | ˆ ƒ s– t j d d t ƒq– qš t	 ˆ t
 j ƒ  ƒ q  Xq  Wˆ j ƒ  sè ˆ d  k	 rÕ t ˆ t t ˆ | ƒ ƒ ƒ qå t ˆ | ƒ qè n  d  S(   Ns!   Multiple exceptions in yield listRG   (   t   removeRs   R,   RE   Rp   RH   R
   R    R9   R   RF   RG   R!   R   Rb   R¡   (   R_   R¢   R"   (   R’   R'   R„   R”   R›   (    s*   lib/python2.7/site-packages/tornado/gen.pyR;   m  s"    N(   RH   Rb   Re   R„   Rf   R!   t   mapR˜   R…   R™   Rš   R*   R   t   addR   (   R’   R”   R;   t	   listeningR_   (    (   R’   R'   R„   R”   R›   s*   lib/python2.7/site-packages/tornado/gen.pyR–   O  s$    		c         C` s.   t  |  ƒ r |  St ƒ  } | j |  ƒ | Sd S(   s  Converts ``x`` into a `.Future`.

    If ``x`` is already a `.Future`, it is simply returned; otherwise
    it is wrapped in a new `.Future`.  This is suitable for use as
    ``result = yield gen.maybe_future(f())`` when you don't know whether
    ``f()`` returns a `.Future` or not.

    .. deprecated:: 4.3
       This function only handles ``Futures``, not other yieldable objects.
       Instead of `maybe_future`, check for the non-future result types
       you expect (often just ``None``), and ``yield`` anything unknown.
    N(   R   R*   R‰   (   R   t   fut(    (    s*   lib/python2.7/site-packages/tornado/gen.pyt   maybe_futureŠ  s
    	c         ` s¯   t  ˆ ƒ ‰ t ƒ  ‰ t ˆ ˆ ƒ t j ƒ  ‰ ‡ f d †  ‰  ‡  ‡ ‡ f d †  } ˆ j |  | ƒ ‰ t ˆ t ƒ r t ˆ ‡ ‡ f d †  ƒ n ˆ j	 ˆ ‡ ‡ f d †  ƒ ˆ S(   s  Wraps a `.Future` (or other yieldable object) in a timeout.

    Raises `tornado.util.TimeoutError` if the input future does not
    complete before ``timeout``, which may be specified in any form
    allowed by `.IOLoop.add_timeout` (i.e. a `datetime.timedelta` or
    an absolute time relative to `.IOLoop.time`)

    If the wrapped `.Future` fails after it has timed out, the exception
    will be logged unless it is of a type contained in ``quiet_exceptions``
    (which may be an exception type or a sequence of types).

    Does not support `YieldPoint` subclasses.

    The wrapped `.Future` is not canceled when the timeout expires,
    permitting it to be reused. `asyncio.wait_for` is similar to this
    function but it does cancel the wrapped `.Future` on timeout.

    .. versionadded:: 4.0

    .. versionchanged:: 4.1
       Added the ``quiet_exceptions`` argument and the logging of unhandled
       exceptions.

    .. versionchanged:: 4.4
       Added support for yieldable objects other than `.Future`.

    c         ` sP   y |  j  ƒ  Wn; t k
 rK } t | ˆ  ƒ sL t j d |  d t ƒqL n Xd  S(   Ns$   Exception in Future %r after timeoutRG   (   R,   RE   RH   R
   R    R9   (   R'   R"   (   R”   (    s*   lib/python2.7/site-packages/tornado/gen.pyt   error_callbackÈ  s    	c           ` s3   ˆ j  ƒ  s" ˆ j t d ƒ ƒ n  t ˆ ˆ  ƒ d  S(   Nt   Timeout(   Rp   RL   R   R   (    (   Rª   R'   R,   (    s*   lib/python2.7/site-packages/tornado/gen.pyt   timeout_callbackÐ  s    c         ` s   ˆ  j  ˆ ƒ S(   N(   t   remove_timeout(   R'   (   RŽ   t   timeout_handle(    s*   lib/python2.7/site-packages/tornado/gen.pyR=   Ü  s    c         ` s   ˆ  j  ˆ ƒ S(   N(   R­   (   R'   (   RŽ   R®   (    s*   lib/python2.7/site-packages/tornado/gen.pyR=   á  s    (
   R˜   R*   R   R	   RA   t   add_timeoutRH   R   R   RB   (   t   timeoutR'   R”   R¬   (    (   Rª   R'   RŽ   R”   R,   R®   s*   lib/python2.7/site-packages/tornado/gen.pyt   with_timeoutŸ  s    $	c         ` s,   t  ƒ  ‰  t j ƒ  j |  ‡  f d †  ƒ ˆ  S(   s¯  Return a `.Future` that resolves after the given number of seconds.

    When used with ``yield`` in a coroutine, this is a non-blocking
    analogue to `time.sleep` (which should not be used in coroutines
    because it is blocking)::

        yield gen.sleep(0.5)

    Note that calling this function on its own does nothing; you must
    wait on the `.Future` it returns (usually by yielding it).

    .. versionadded:: 4.1
    c           ` s   t  ˆ  d  ƒ S(   N(   R   R!   (    (   R_   (    s*   lib/python2.7/site-packages/tornado/gen.pyR=   õ  s    (   R*   R	   RA   t
   call_later(   t   duration(    (   R_   s*   lib/python2.7/site-packages/tornado/gen.pyt   sleepå  s    	R£   c           B` s    e  Z d  Z d „  Z d „  Z RS(   sÐ   _NullFuture resembles a Future that finished with a result of None.

    It's not actually a `Future` to avoid depending on a particular event loop.
    Handled as a special case in the coroutine runner.
    c         C` s   d  S(   N(   R!   (   RZ   (    (    s*   lib/python2.7/site-packages/tornado/gen.pyR,   ÿ  s    c         C` s   t  S(   N(   R9   (   RZ   (    (    s*   lib/python2.7/site-packages/tornado/gen.pyRp     s    (   R   R   R[   R,   Rp   (    (    (    s*   lib/python2.7/site-packages/tornado/gen.pyR£   ù  s   	sŒ  A special object which may be yielded to allow the IOLoop to run for
one iteration.

This is not needed in normal use but it can be helpful in long-running
coroutines that are likely to yield Futures that are ready instantly.

Usage: ``yield gen.moment``

.. versionadded:: 4.0

.. deprecated:: 4.5
   ``yield None`` (or ``yield`` with no argument) is now equivalent to
    ``yield gen.moment``.
RN   c           B` sh   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z RS(   sÏ   Internal implementation of `tornado.gen.engine`.

    Maintains information about pending callbacks and their results.

    The results of the generator are stored in ``result_future`` (a
    `.Future`)
    c         C` s—   | |  _  | |  _ t |  _ d  |  _ d  |  _ d  |  _ t |  _	 t |  _
 t |  _ t j ƒ  |  _ d  |  _ |  j | ƒ r“ d  } } } |  j ƒ  n  d  S(   N(   t   gent   result_futuret   _null_futureR'   R!   t   yield_pointt   pending_callbackst   resultsR   t   runningRŸ   t   had_exceptionR	   RA   RŽ   t   stack_context_deactivatet   handle_yieldt   run(   RZ   Rµ   R¶   t   first_yielded(    (    s*   lib/python2.7/site-packages/tornado/gen.pyRY   %  s    										c         C` s`   |  j  d k r' t ƒ  |  _  i  |  _ n  | |  j  k rL t d | f ƒ ‚ n  |  j  j | ƒ d S(   s&   Adds ``key`` to the list of callbacks.s   key %r is already pendingN(   R¹   R!   Rš   Rº   R   R¦   (   RZ   R~   (    (    s*   lib/python2.7/site-packages/tornado/gen.pyR   :  s    c         C` sA   |  j  d k s | |  j  k r4 t d | f ƒ ‚ n  | |  j k S(   s2   Returns true if a result is available for ``key``.s   key %r is not pendingN(   R¹   R!   R   Rº   (   RZ   R~   (    (    s*   lib/python2.7/site-packages/tornado/gen.pyR{   D  s    c         C` s‚   | |  j  | <|  j d k	 r~ |  j j ƒ  r~ y t |  j |  j j ƒ  ƒ Wn t |  j t j	 ƒ  ƒ n Xd |  _ |  j
 ƒ  n  d S(   sA   Sets the result for ``key`` and attempts to resume the generator.N(   Rº   R¸   R!   R{   R   R'   R|   R   RF   RG   R¿   (   RZ   R~   R,   (    (    s*   lib/python2.7/site-packages/tornado/gen.pyR‰   J  s    		c         C` s    |  j  j | ƒ |  j j | ƒ S(   s2   Returns the result for ``key`` and unregisters it.(   R¹   R¤   Rº   R@   (   RZ   R~   (    (    s*   lib/python2.7/site-packages/tornado/gen.pyR‚   V  s    c         C` s  |  j  s |  j r d Szæt |  _  xÖt rú|  j } | j ƒ  sD d Sd |  _ yÄ t j j } d } y | j	 ƒ  } Wn& t
 k
 rš t |  _ t j ƒ  } n Xd } | d k	 rÐ z |  j j | Œ  } Wd d } Xn |  j j | ƒ } t j j | k	 r|  j j t j d ƒ ƒ n  WnÊ t t f k
 r‘} t |  _ t |  _ |  j rd|  j rdt d |  j ƒ ‚ n  t |  j t | ƒ ƒ d |  _ |  j ƒ  d St
 k
 rÝt |  _ t |  _ t |  j t j ƒ  ƒ d |  _ |  j ƒ  d SX|  j | ƒ sñd Sd } q% WWd t |  _  Xd S(   sk   Starts or resumes the generator, running until it reaches a
        yield point that is not ready.
        NsY   stack_context inconsistency (probably caused by yield within a "with StackContext" block)s)   finished without waiting for callbacks %r(   R»   RŸ   R9   R'   Rp   R!   R   RI   RJ   R,   RE   R¼   RF   RG   Rµ   t   throwt   sendRM   RD   RC   R·   R¹   R   R   R¶   R#   t   _deactivate_stack_contextR   R¾   R   (   RZ   R'   RP   RG   R   RQ   R"   (    (    s*   lib/python2.7/site-packages/tornado/gen.pyR¿   [  sd    					
					
			
c         ` sY  t  ˆ ƒ r t ˆ ƒ ‰ n  t ˆ t ƒ r® t ƒ  ˆ  _ ‡  ‡ f d †  ‰ ˆ  j d  k r¤ t j	 ˆ  j
 ƒ 6 } | ˆ  _ ‡  ‡ f d †  } ˆ  j j | ƒ t SWd  QXq÷ ˆ ƒ  nI y t ˆ ƒ ˆ  _ Wn3 t k
 rö t ƒ  ˆ  _ t ˆ  j t j ƒ  ƒ n Xˆ  j t k rˆ  j j ˆ  j ƒ t Sˆ  j j ƒ  sU‡  f d †  } ˆ  j j ˆ  j | ƒ t St S(   Nc           ` sy   y? ˆ j  ˆ  ƒ ˆ j ƒ  r5 t ˆ  j ˆ j ƒ  ƒ n	 ˆ ˆ  _ Wn3 t k
 rt t ƒ  ˆ  _ t ˆ  j t	 j
 ƒ  ƒ n Xd  S(   N(   Rz   R{   R   R'   R|   R¸   RE   R   R   RF   RG   (    (   RZ   RQ   (    s*   lib/python2.7/site-packages/tornado/gen.pyt   start_yield_pointª  s    c           ` s   ˆ ƒ  ˆ  j  ƒ  d  S(   N(   R¿   (    (   RZ   RÄ   (    s*   lib/python2.7/site-packages/tornado/gen.pyt   cb¼  s    c         ` s   d  }  ˆ  j ƒ  d  S(   N(   R!   R¿   (   R_   (   RZ   (    s*   lib/python2.7/site-packages/tornado/gen.pyt   innerÎ  s    (   R“   R—   RH   Rx   R   R'   R½   R!   R   RŠ   Rˆ   RŽ   t   add_callbackR   R˜   R   R   RF   RG   t   momentR¿   Rp   RB   R9   (   RZ   RQ   t
   deactivateRÅ   RÆ   (    (   RZ   RÄ   RQ   s*   lib/python2.7/site-packages/tornado/gen.pyR¾   Ÿ  s6    	
	c         C` s"   t  j t t j |  j | ƒ ƒ ƒ S(   N(   R   R.   R‹   R6   t   partialR‰   (   RZ   R~   (    (    s*   lib/python2.7/site-packages/tornado/gen.pyR€   ×  s    	c         C` sO   |  j  rG |  j rG t ƒ  |  _ t |  j | | | f ƒ |  j ƒ  t St Sd  S(   N(   R»   RŸ   R   R'   R   R¿   R9   R   (   RZ   R†   R   R‡   (    (    s*   lib/python2.7/site-packages/tornado/gen.pyRˆ   Û  s    
c         C` s)   |  j  d  k	 r% |  j  ƒ  d  |  _  n  d  S(   N(   R½   R!   (   RZ   (    (    s*   lib/python2.7/site-packages/tornado/gen.pyRÃ   ä  s    
(   R   R   R[   RY   R   R{   R‰   R‚   R¿   R¾   R€   Rˆ   RÃ   (    (    (    s*   lib/python2.7/site-packages/tornado/gen.pyRN     s   		
				D	8			t	   ArgumentsR   R/   c         ` s   ‡  f d †  } | S(   s  Returns a function that when invoked runs ``callback`` with one arg.

    If the function returned by this function is called with exactly
    one argument, that argument is passed to ``callback``.  Otherwise
    the args tuple and kwargs dict are wrapped in an `Arguments` object.
    c          ` sS   | s t  |  ƒ d k r. ˆ  t |  | ƒ ƒ n! |  rE ˆ  |  d ƒ n
 ˆ  d  ƒ d  S(   Ni   i    (   t   lenRË   R!   (   R   R/   (   R;   (    s*   lib/python2.7/site-packages/tornado/gen.pyR1   ô  s
    (    (   R;   R1   (    (   R;   s*   lib/python2.7/site-packages/tornado/gen.pyR‹   í  s    c         c` s‹  t  |  d ƒ r |  j ƒ  } n t |  ƒ } y t | ƒ } Wn t k
 r[ } t | ƒ } n Xxy | V} Wn¹ t k
 r­ } y | j } Wn t k
 rœ n X| ƒ  | ‚ q_ t	 k
 r%} t
 j ƒ  } y | j } Wn t k
 rî | ‚ qwXy | | Œ  } Wqwt k
 r!} t | ƒ } PqwXq_ Xy. | d  k rDt | ƒ } n | j | ƒ } Wq_ t k
 rv} t | ƒ } Pq_ Xq_ Wt | ƒ ‚ d  S(   Nt	   __await__(   RR   RÍ   t   iterRK   RD   R#   t   GeneratorExitt   closeR   t   BaseExceptionRF   RG   RÁ   R!   RÂ   RC   (   R   t   _it   _yt   _et   _rt   _st   _mt   _x(    (    s*   lib/python2.7/site-packages/tornado/gen.pyt   _wrap_awaitable  sH    	
		t   asyncc         C` sˆ   |  d k s |  t k r t S|  t k r, t St |  t t f ƒ rK t |  ƒ St |  ƒ r[ |  St |  ƒ rq t	 |  ƒ St
 d |  f ƒ ‚ d S(   s¿  Convert a yielded object into a `.Future`.

    The default implementation accepts lists, dictionaries, and Futures.

    If the `~functools.singledispatch` library is available, this function
    may be extended to support additional types. For example::

        @convert_yielded.register(asyncio.Future)
        def _(asyncio_future):
            return tornado.platform.asyncio.to_tornado_future(asyncio_future)

    .. versionadded:: 4.1
    s   yielded unknown object %rN(   R!   RÈ   R·   RH   Re   Rb   R—   R   R   RÙ   R   (   RQ   (    (    s*   lib/python2.7/site-packages/tornado/gen.pyR˜   9  s    

(    (    (    (S   R[   t
   __future__R    R   R   Rh   R6   Rœ   t   osRF   RS   R2   t   tornado.concurrentR   R   R   R   R   R   t   tornado.ioloopR	   t   tornado.logR
   t   tornadoR   t   tornado.utilR   R   R   R   t   ImportErrort   environR!   t   collections.abcR   R   t   backports_abct   inspectR   Rv   t   __builtin__RE   R   R   R   R   R   R#   R*   R8   R:   R5   RW   RC   R   R\   Rx   R}   R   Rƒ   RŒ   R   R“   R—   t   MultiR•   R–   R©   R±   R´   R£   R·   RÈ   RN   t
   namedtupleRË   R‹   t   asyncioRÙ   t   ensure_futureR   R%   R˜   (    (    (    s*   lib/python2.7/site-packages/tornado/gen.pyt   <module>Z   s¨   .
			*	'	W		v"	"&	8D;	F				Í	-	