ó
­œž[c           @` sf  d  Z  d d l m Z m Z m Z d d l Z d d l Z d d l m Z m	 Z	 m
 Z
 d d l 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 d d
 l m Z d d l m Z m Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e j f d „  ƒ  YZ d e j  f d „  ƒ  YZ! d e f d „  ƒ  YZ" d S(   sF   Client and server implementations of HTTP/1.x.

.. versionadded:: 4.0
i    (   t   absolute_importt   divisiont   print_functionN(   t   Futuret   future_add_done_callbackt"   future_set_result_unless_cancelled(   t
   native_strt   utf8(   t   gen(   t   httputil(   t   iostream(   t   gen_logt   app_log(   t   stack_context(   t   GzipDecompressort   PY3t   _QuietExceptionc           B` s   e  Z d  „  Z RS(   c         C` s   d  S(   N(    (   t   self(    (    s6   lib/python2.7/site-packages/tornado/http1connection.pyt   __init__&   s    (   t   __name__t
   __module__R   (    (    (    s6   lib/python2.7/site-packages/tornado/http1connection.pyR   %   s   t   _ExceptionLoggingContextc           B` s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   s°   Used with the ``with`` statement when calling delegate methods to
    log any exceptions with the given logger.  Any exceptions caught are
    converted to _QuietException
    c         C` s   | |  _  d  S(   N(   t   logger(   R   R   (    (    s6   lib/python2.7/site-packages/tornado/http1connection.pyR   /   s    c         C` s   d  S(   N(    (   R   (    (    s6   lib/python2.7/site-packages/tornado/http1connection.pyt	   __enter__2   s    c         C` s8   | d  k	 r4 |  j j d d | | | f ƒt ‚ n  d  S(   Ns   Uncaught exceptiont   exc_info(   t   NoneR   t   errorR   (   R   t   typt   valuet   tb(    (    s6   lib/python2.7/site-packages/tornado/http1connection.pyt   __exit__5   s    (   R   R   t   __doc__R   R   R   (    (    (    s6   lib/python2.7/site-packages/tornado/http1connection.pyR   *   s   		t   HTTP1ConnectionParametersc           B` s,   e  Z d  Z e d d d d d e d „ Z RS(   sD   Parameters for `.HTTP1Connection` and `.HTTP1ServerConnection`.
    c         C` sO   | |  _  | p d |  _ | p! d |  _ | |  _ | |  _ | |  _ | |  _ d S(   s;  
        :arg bool no_keep_alive: If true, always close the connection after
            one request.
        :arg int chunk_size: how much data to read into memory at once
        :arg int max_header_size:  maximum amount of data for HTTP headers
        :arg float header_timeout: how long to wait for all headers (seconds)
        :arg int max_body_size: maximum amount of data for body
        :arg float body_timeout: how long to wait while reading body (seconds)
        :arg bool decompress: if true, decode incoming
            ``Content-Encoding: gzip``
        i   N(   t   no_keep_alivet
   chunk_sizet   max_header_sizet   header_timeoutt   max_body_sizet   body_timeoutt
   decompress(   R   R!   R"   R#   R$   R%   R&   R'   (    (    s6   lib/python2.7/site-packages/tornado/http1connection.pyR   >   s    				N(   R   R   R   t   FalseR   R   (    (    (    s6   lib/python2.7/site-packages/tornado/http1connection.pyR    ;   s   	t   HTTP1Connectionc           B` s  e  Z d  Z d d d „ Z d „  Z e j d „  ƒ Z d „  Z	 d „  Z
 d „  Z d „  Z d „  Z d	 „  Z d
 „  Z d d d „ Z d „  Z d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z e j d „  ƒ Z e j d „  ƒ Z e j d „  ƒ Z RS(   s…   Implements the HTTP/1.x protocol.

    This class can be on its own for clients, or via `HTTP1ServerConnection`
    for servers.
    c         C` sÝ   | |  _  | |  _ | d k r* t ƒ  } n  | |  _ | |  _ | j |  _ |  j j p] |  j j |  _	 |  j j
 |  _ t |  _ t |  _ t ƒ  |  _ t |  _ |  j ƒ  d |  _ d |  _ d |  _ d |  _ d |  _ d |  _ d S(   s  
        :arg stream: an `.IOStream`
        :arg bool is_client: client or server
        :arg params: a `.HTTP1ConnectionParameters` instance or ``None``
        :arg context: an opaque application-defined object that can be accessed
            as ``connection.context``.
        N(   t	   is_clientt   streamR   R    t   paramst   contextR!   R%   t   max_buffer_sizet   _max_body_sizeR&   t   _body_timeoutR(   t   _write_finishedt   _read_finishedR   t   _finish_futuret   _disconnect_on_finisht   _clear_callbackst   _request_start_linet   _response_start_linet   _request_headerst   _chunking_outputt   _expected_content_remainingt   _pending_write(   R   R+   R*   R,   R-   (    (    s6   lib/python2.7/site-packages/tornado/http1connection.pyR   [   s*    							
					c         C` s1   |  j  j r$ t | |  j  j ƒ } n  |  j | ƒ S(   sH  Read a single HTTP response.

        Typical client-mode usage is to write a request using `write_headers`,
        `write`, and `finish`, and then call ``read_response``.

        :arg delegate: a `.HTTPMessageDelegate`

        Returns a `.Future` that resolves to None after the full response has
        been read.
        (   R,   R'   t   _GzipMessageDelegateR"   t   _read_message(   R   t   delegate(    (    s6   lib/python2.7/site-packages/tornado/http1connection.pyt   read_response‹   s    c         c` sµ  t  } zbyù|  j j d d |  j j ƒ} |  j j d  k rF | V} nf y6 t j |  j j	 j
 ƒ  |  j j | d t j ƒV} Wn- t j k
 r« |  j ƒ  t j t  ƒ ‚ n X|  j | ƒ \ } } |  j rå t j | ƒ } | |  _ n! t j | ƒ } | |  _ | |  _ |  j | | ƒ |  _ t } t t ƒ + | j | | ƒ } | d  k	 rU| Vn  Wd  QX|  j d  k r‚t  } t j t  ƒ ‚ n  t  } |  j r3|  j d  k	 r»|  j j d k r»t } n  | j } | d k rÙt } n  | d k re| d k  red | k s	d	 | k rt j  d
 | ƒ ‚ n  |  j! | ƒ Vqen2 | j" d ƒ d k re|  j# re|  j j$ d ƒ n  | s2|  j% |  j rƒ| j n d | | ƒ }	 |	 d  k	 r2|  j& d  k rµ|	 Vq/y1 t j |  j j	 j
 ƒ  |  j& |	 d t j ƒVWq/t j k
 r+t' j( d |  j) ƒ |  j j ƒ  t j t  ƒ ‚ q/Xq2n  t |  _* |  j# sN|  j rtt  } t t ƒ  | j+ ƒ  Wd  QXn  |  j, j- ƒ  rÁ|  j d  k	 rÁ|  j j. ƒ  rÁ|  j j/ |  j0 ƒ |  j, Vn  |  j rà|  j rà|  j ƒ  n  |  j d  k rt j t  ƒ ‚ n  Wnb t j  k
 rf}
 t' j( d |  j) |
 ƒ |  j sJ|  j j$ d ƒ Vn  |  j ƒ  t j t  ƒ ‚ n XWd  | r‘t t ƒ  | j1 ƒ  Wd  QXn  d  } |  j2 ƒ  Xt j t ƒ ‚ d  S(   Ns   ?
?
t	   max_bytest   quiet_exceptionst   HEADi0  id   iÈ   s   Content-Lengths   Transfer-Encodings!   Response code %d cannot have bodyt   Expects   100-continues   HTTP/1.1 100 (Continue)

i    s   Timeout reading body from %ss"   Malformed HTTP message from %s: %ss   HTTP/1.1 400 Bad Request

(3   R(   R+   t   read_until_regexR,   R#   R$   R   R   t   with_timeoutt   io_loopt   timeR
   t   StreamClosedErrort   TimeoutErrort   closet   Returnt   _parse_headersR*   R	   t   parse_response_start_lineR7   t   parse_request_start_lineR6   R8   t   _can_keep_aliveR4   t   TrueR   R   t   headers_receivedt   methodt   codet   HTTPInputErrorR=   t   getR1   t   writet
   _read_bodyR0   R   t   infoR-   R2   t   finishR3   t   donet   closedt   set_close_callbackt   _on_connection_closet   on_connection_closeR5   (   R   R>   t   need_delegate_closet   header_futuret   header_datat
   start_linet   headerst	   skip_bodyRS   t   body_futuret   e(    (    s6   lib/python2.7/site-packages/tornado/http1connection.pyR=   š   sº     	

							
!	
			
c         C` sA   d |  _ d |  _ d |  _ |  j d k	 r= |  j j d ƒ n  d S(   sª   Clears the callback attributes.

        This allows the request handler to be garbage collected more
        quickly in CPython by breaking up reference cycles.
        N(   R   t   _write_callbackt   _write_futuret   _close_callbackR+   R\   (   R   (    (    s6   lib/python2.7/site-packages/tornado/http1connection.pyR5   
  s
    			c         C` s   t  j | ƒ |  _ d S(   s$  Sets a callback that will be run when the connection is closed.

        Note that this callback is slightly different from
        `.HTTPMessageDelegate.on_connection_close`: The
        `.HTTPMessageDelegate` method is called when the connection is
        closed while recieving a message. This callback is used when
        there is not an active delegate (for example, on the server
        side this callback is used if the client closes the connection
        after sending its request but before receiving all the
        response.
        N(   R   t   wrapRi   (   R   t   callback(    (    s6   lib/python2.7/site-packages/tornado/http1connection.pyR\     s    c         C` s[   |  j  d  k	 r+ |  j  } d  |  _  | ƒ  n  |  j j ƒ  sM t |  j d  ƒ n  |  j ƒ  d  S(   N(   Ri   R   R3   RZ   R   R5   (   R   Rk   (    (    s6   lib/python2.7/site-packages/tornado/http1connection.pyR]   $  s    		
c         C` sO   |  j  d  k	 r |  j  j ƒ  n  |  j ƒ  |  j j ƒ  sK t |  j d  ƒ n  d  S(   N(   R+   R   RJ   R5   R3   RZ   R   (   R   (    (    s6   lib/python2.7/site-packages/tornado/http1connection.pyRJ   0  s
    
c         C` sB   |  j  ƒ  |  j } d |  _ |  j j ƒ  s> t |  j d ƒ n  | S(   s>  Take control of the underlying stream.

        Returns the underlying `.IOStream` object and stops all further
        HTTP processing.  May only be called during
        `.HTTPMessageDelegate.headers_received`.  Intended for implementing
        protocols like websockets that tunnel over an HTTP handshake.
        N(   R5   R+   R   R3   RZ   R   (   R   R+   (    (    s6   lib/python2.7/site-packages/tornado/http1connection.pyt   detach7  s    
		c         C` s   | |  _  d S(   st   Sets the body timeout for a single request.

        Overrides the value from `.HTTP1ConnectionParameters`.
        N(   R0   (   R   t   timeout(    (    s6   lib/python2.7/site-packages/tornado/http1connection.pyt   set_body_timeoutF  s    c         C` s   | |  _  d S(   sw   Sets the body size limit for a single request.

        Overrides the value from `.HTTP1ConnectionParameters`.
        N(   R/   (   R   R%   (    (    s6   lib/python2.7/site-packages/tornado/http1connection.pyt   set_max_body_sizeM  s    c   
      C` s,  g  } |  j  rj | |  _ | j t d | d | d f ƒ ƒ | j d k oa d | k oa d | k |  _ nð | |  _ | j t d	 | d | d
 f ƒ ƒ |  j j d k oì | j d  k oì | j d k  s× | j d k oì d | k oì d | k |  _ |  j j d k r|  j	 rd | d <n  |  j j d k rZ|  j
 j d d ƒ j ƒ  d k rZd | d <n  |  j rpd | d <n  |  j  r§|  j j d k s›| j d k r§d |  _ n+ d | k rÉt | d ƒ |  _ n	 d! |  _ d „  | j ƒ  Dƒ } t r| j d „  | Dƒ ƒ n | j | ƒ x3 | D]+ } d | k rt d t | ƒ ƒ ‚ qqWd! } |  j j ƒ  rt ƒ  } |  _ | j t j ƒ  ƒ | j ƒ  n˜ | d! k	 rÁt j d t ƒ t  j! | ƒ |  _" n t ƒ  } |  _ d j# | ƒ d }	 | r |	 |  j$ | ƒ 7}	 n  |  j j% |	 ƒ |  _& t' |  j& |  j( ƒ | S("   s+   Implements `.HTTPConnection.write_headers`.s   %s %s HTTP/1.1i    i   t   POSTt   PUTt   PATCHs   Content-Lengths   Transfer-Encodings   HTTP/1.1 %d %si   s   HTTP/1.1iÌ   i0  id   iÈ   RJ   t
   Connections   HTTP/1.0t    s
   keep-alives
   Keep-Alivet   chunkedRB   c         s` s/   |  ]% \ } } t  | ƒ d  t  | ƒ Vq d S(   s   : N(   R   (   t   .0t   nt   v(    (    s6   lib/python2.7/site-packages/tornado/http1connection.pys	   <genexpr>†  s    c         s` s   |  ] } | j  d  ƒ Vq d S(   t   latin1N(   t   encode(   Rv   t   l(    (    s6   lib/python2.7/site-packages/tornado/http1connection.pys	   <genexpr>ˆ  s    s   
s   Newline in header: s<   callback argument is deprecated, use returned Future insteads   
s   

(   Rp   Rq   Rr   (   iÌ   i0  N()   R*   R6   t   appendR   RR   R9   R7   t   versionRS   R4   R8   RU   t   lowerR:   t   intR   t   get_allR   t   extendt
   ValueErrort   reprR+   R[   R   Rh   t   set_exceptionR
   RH   t	   exceptiont   warningst   warnt   DeprecationWarningR   Rj   Rg   t   joint   _format_chunkRV   R;   R   t   _on_write_complete(
   R   Rb   Rc   t   chunkRk   t   linest   header_linest   linet   futuret   data(    (    s6   lib/python2.7/site-packages/tornado/http1connection.pyt   write_headersT  sf    		%	%!	
		c         C` sŒ   |  j  d  k	 rU |  j  t | ƒ 8_  |  j  d k  rU |  j j ƒ  t j d ƒ ‚ qU n  |  j r„ | r„ t d t | ƒ ƒ d | d S| Sd  S(   Ni    s,   Tried to write more data than Content-Lengths   %xs   
(	   R:   R   t   lenR+   RJ   R	   t   HTTPOutputErrorR9   R   (   R   RŒ   (    (    s6   lib/python2.7/site-packages/tornado/http1connection.pyRŠ   ¡  s     c         C` sÁ   d } |  j j ƒ  rK t ƒ  } |  _ |  j j t j ƒ  ƒ |  j j ƒ  nr | d k	 r| t	 j
 d t ƒ t j | ƒ |  _ n t ƒ  } |  _ |  j j |  j | ƒ ƒ |  _ |  j j |  j ƒ | S(   sÒ   Implements `.HTTPConnection.write`.

        For backwards compatibility it is allowed but deprecated to
        skip `write_headers` and instead call `write()` with a
        pre-encoded header block.
        s<   callback argument is deprecated, use returned Future insteadN(   R   R+   R[   R   Rh   R„   R
   RH   R…   R†   R‡   Rˆ   R   Rj   Rg   RV   RŠ   R;   t   add_done_callbackR‹   (   R   RŒ   Rk   R   (    (    s6   lib/python2.7/site-packages/tornado/http1connection.pyRV   °  s    	c         C` sþ   |  j  d k	 rT |  j  d k rT |  j j ƒ  rT |  j j ƒ  t j d |  j  ƒ ‚ n  |  j rš |  j j ƒ  sš |  j j d ƒ |  _	 |  j	 j
 |  j ƒ qš n  t |  _ |  j s¸ t |  _ n  |  j j t ƒ |  j	 d k rç |  j d ƒ n t |  j	 |  j ƒ d S(   s$   Implements `.HTTPConnection.finish`.i    s0   Tried to write %d bytes less than Content-Lengths   0

N(   R:   R   R+   R[   RJ   R	   R”   R9   RV   R;   R•   R‹   RP   R1   R2   R4   t   set_nodelayt   _finish_requestR   (   R   (    (    s6   lib/python2.7/site-packages/tornado/http1connection.pyRY   Ç  s$    			c         C` s¤   | j  ƒ  } | d  k	 r8 t | t j ƒ r8 | j ƒ  n  |  j d  k	 ro |  j } d  |  _ |  j j j	 | ƒ n  |  j
 d  k	 r  |  j
 } d  |  _
 t | d  ƒ n  d  S(   N(   R…   R   t
   isinstanceR
   RH   t   resultRg   R+   RF   t   add_callbackRh   R   (   R   R   t   excRk   (    (    s6   lib/python2.7/site-packages/tornado/http1connection.pyR‹   ä  s    				c         C` s£   |  j  j r t S| j d ƒ } | d  k	 r: | j ƒ  } n  | j d k rS | d k Sd | k s• | j d d ƒ j ƒ  d k s• t | d d  ƒ d k rŸ | d k St S(   NRs   s   HTTP/1.1RJ   s   Content-Lengths   Transfer-EncodingRt   Ru   RR   RB   t   GETs
   keep-alive(   RB   Rœ   (   R,   R!   R(   RU   R   R~   R}   t   getattr(   R   Rb   Rc   t   connection_header(    (    s6   lib/python2.7/site-packages/tornado/http1connection.pyRO   ñ  s    

c         C` sa   |  j  ƒ  |  j r+ |  j r+ |  j ƒ  d  S|  j j t ƒ |  j j ƒ  s] t	 |  j d  ƒ n  d  S(   N(   R5   R*   R4   RJ   R+   R–   R(   R3   RZ   R   R   (   R   R   (    (    s6   lib/python2.7/site-packages/tornado/http1connection.pyR—     s    

c         C` s`   t  | j d ƒ ƒ j d ƒ } | j d ƒ } | |  j d ƒ } t j j | | ƒ } | | f S(   NRy   s   
s   
s   (   R   t   decodet   lstript   findt   rstripR	   t   HTTPHeaderst   parse(   R   R‘   t   eolRb   Rc   (    (    s6   lib/python2.7/site-packages/tornado/http1connection.pyRL     s
    c         ` s¤  d | k rú d | k r* t  j d ƒ ‚ n  d | d k r— t j d | d ƒ ‰  t ‡  f d †  ˆ  Dƒ ƒ r† t  j d | d ƒ ‚ n  ˆ  d | d <n  y t | d ƒ } Wn( t k
 rÕ t  j d	 | d ƒ ‚ n X| |  j k r t  j d
 ƒ ‚ q n d  } | d k rCd | k s$| d k r:t  j d | ƒ ‚ n  d } n  | d  k	 r_|  j	 | | ƒ S| j
 d d ƒ j ƒ  d k rŠ|  j | ƒ S|  j r |  j | ƒ Sd  S(   Ns   Content-Lengths   Transfer-Encodings7   Response with both Transfer-Encoding and Content-Lengtht   ,s   ,\s*c         3` s   |  ] } | ˆ  d  k Vq d S(   i    N(    (   Rv   t   i(   t   pieces(    s6   lib/python2.7/site-packages/tornado/http1connection.pys	   <genexpr>%  s    s$   Multiple unequal Content-Lengths: %ri    s*   Only integer Content-Length is allowed: %ss   Content-Length too longiÌ   s*   Response with code %d should not have bodyRt   Ru   (   Ni    (   R	   RT   t   ret   splitt   anyR   R‚   R/   R   t   _read_fixed_bodyRU   R~   t   _read_chunked_bodyR*   t   _read_body_until_close(   R   RS   Rc   R>   t   content_length(    (   R¨   s6   lib/python2.7/site-packages/tornado/http1connection.pyRW     s@    		c         c` s›   x” | d k r– |  j  j t |  j j | ƒ d t ƒV} | t | ƒ 8} |  j sZ |  j r t	 t
 ƒ ( | j | ƒ } | d  k	 rŠ | Vn  Wd  QXq q Wd  S(   Ni    t   partial(   R+   t
   read_bytest   minR,   R"   RP   R“   R1   R*   R   R   t   data_receivedR   (   R   R¯   R>   t   bodyt   ret(    (    s6   lib/python2.7/site-packages/tornado/http1connection.pyR¬   I  s    	c         c` sm  d } x`t  rh|  j j d d d ƒV} t | j ƒ  d ƒ } | d k r~ |  j j d ƒ V} | d k rz t j d ƒ ‚ n  d  S| | 7} | |  j k r© t j d ƒ ‚ n  | } xŽ | r?|  j j t	 | |  j
 j ƒ d	 t  ƒV} | t | ƒ 8} |  j s|  j r² t t ƒ ( | j | ƒ } | d  k	 r3| Vn  Wd  QXq² q² W|  j j d ƒ V} | d k s	 t ‚ q	 Wd  S(
   Ni    s   
R@   i@   i   i   s%   improperly terminated chunked requests   chunked body too largeR°   (   RP   R+   t
   read_untilR   t   stripR±   R	   RT   R/   R²   R,   R"   R“   R1   R*   R   R   R³   R   t   AssertionError(   R   R>   t
   total_sizet	   chunk_lent   crlft   bytes_to_readRŒ   Rµ   (    (    s6   lib/python2.7/site-packages/tornado/http1connection.pyR­   U  s0    	
		c         c` sJ   |  j  j ƒ  V} |  j s# |  j rF t t ƒ  | j | ƒ Wd  QXn  d  S(   N(   R+   t   read_until_closeR1   R*   R   R   R³   (   R   R>   R´   (    (    s6   lib/python2.7/site-packages/tornado/http1connection.pyR®   r  s    N(   R   R   R   R   R   R?   R   t	   coroutineR=   R5   R\   R]   RJ   Rl   Rn   Ro   R’   RŠ   RV   RY   R‹   RO   R—   RL   RW   R¬   R­   R®   (    (    (    s6   lib/python2.7/site-packages/tornado/http1connection.pyR)   U   s.   0	p							M							1R<   c           B` sD   e  Z d  Z d „  Z d „  Z e j d „  ƒ Z d „  Z d „  Z	 RS(   sI   Wraps an `HTTPMessageDelegate` to decode ``Content-Encoding: gzip``.
    c         C` s   | |  _  | |  _ d  |  _ d  S(   N(   t	   _delegatet   _chunk_sizeR   t   _decompressor(   R   R>   R"   (    (    s6   lib/python2.7/site-packages/tornado/http1connection.pyR   }  s    		c         C` sR   | j  d ƒ d k r? t ƒ  |  _ | j d | d ƒ | d =n  |  j j | | ƒ S(   Ns   Content-Encodingt   gzips   X-Consumed-Content-Encoding(   RU   R   RÁ   t   addR¿   RQ   (   R   Rb   Rc   (    (    s6   lib/python2.7/site-packages/tornado/http1connection.pyRQ   ‚  s    	
c         c` sœ   |  j  rr | } x† | rn |  j  j | |  j ƒ } | r_ |  j j | ƒ } | d  k	 r_ | Vq_ n  |  j  j } q Wn& |  j j | ƒ } | d  k	 r˜ | Vn  d  S(   N(   RÁ   R'   RÀ   R¿   R³   R   t   unconsumed_tail(   R   RŒ   t   compressed_datat   decompressedRµ   (    (    s6   lib/python2.7/site-packages/tornado/http1connection.pyR³     s    			c         C` sG   |  j  d  k	 r: |  j  j ƒ  } | r: |  j j | ƒ q: n  |  j j ƒ  S(   N(   RÁ   R   t   flushR¿   R³   RY   (   R   t   tail(    (    s6   lib/python2.7/site-packages/tornado/http1connection.pyRY   ž  s
    c         C` s   |  j  j ƒ  S(   N(   R¿   R^   (   R   (    (    s6   lib/python2.7/site-packages/tornado/http1connection.pyR^   ª  s    (
   R   R   R   R   RQ   R   R¾   R³   RY   R^   (    (    (    s6   lib/python2.7/site-packages/tornado/http1connection.pyR<   z  s   			t   HTTP1ServerConnectionc           B` sJ   e  Z d  Z d d d „ Z e j d „  ƒ Z d „  Z e j d „  ƒ Z	 RS(   s   An HTTP/1.x server.c         C` s@   | |  _  | d k r! t ƒ  } n  | |  _ | |  _ d |  _ d S(   sÝ   
        :arg stream: an `.IOStream`
        :arg params: a `.HTTP1ConnectionParameters` or None
        :arg context: an opaque application-defined object that is accessible
            as ``connection.context``
        N(   R+   R   R    R,   R-   t   _serving_future(   R   R+   R,   R-   (    (    s6   lib/python2.7/site-packages/tornado/http1connection.pyR   °  s    			c         c` s1   |  j  j ƒ  y |  j VWn t k
 r, n Xd S(   sm   Closes the connection.

        Returns a `.Future` that resolves after the serving loop has exited.
        N(   R+   RJ   RÊ   t	   Exception(   R   (    (    s6   lib/python2.7/site-packages/tornado/http1connection.pyRJ   ¾  s
    c         C` sJ   t  | t j ƒ s t ‚ |  j | ƒ |  _ |  j j j |  j d „  ƒ d S(   sn   Starts serving requests on this connection.

        :arg delegate: a `.HTTPServerConnectionDelegate`
        c         S` s
   |  j  ƒ  S(   N(   R™   (   t   f(    (    s6   lib/python2.7/site-packages/tornado/http1connection.pyt   <lambda>Õ  s    N(	   R˜   R	   t   HTTPServerConnectionDelegateR¸   t   _server_request_loopRÊ   R+   RF   t
   add_future(   R   R>   (    (    s6   lib/python2.7/site-packages/tornado/http1connection.pyt   start_servingÌ  s    c         c` sæ   zÑ xÊ t  rÏ t |  j t |  j |  j ƒ } | j |  | ƒ } y | j | ƒ V} Wng t j	 t j
 f k
 rp d  St k
 r‹ | j ƒ  d  St k
 r¹ t j d d t  ƒ| j ƒ  d  SX| sÄ d  St j Vq WWd  | j |  ƒ Xd  S(   Ns   Uncaught exceptionR   (   RP   R)   R+   R(   R,   R-   t   start_requestR?   R
   RH   t   UnsatisfiableReadErrorR   RJ   RË   R   R   R   t   momentt   on_close(   R   R>   t   connt   request_delegateRµ   (    (    s6   lib/python2.7/site-packages/tornado/http1connection.pyRÏ   ×  s*    	

N(
   R   R   R   R   R   R   R¾   RJ   RÑ   RÏ   (    (    (    s6   lib/python2.7/site-packages/tornado/http1connection.pyRÉ   ®  s
   	(#   R   t
   __future__R    R   R   R©   R†   t   tornado.concurrentR   R   R   t   tornado.escapeR   R   t   tornadoR   R	   R
   t   tornado.logR   R   R   t   tornado.utilR   R   RË   R   t   objectR   R    t   HTTPConnectionR)   t   HTTPMessageDelegateR<   RÉ   (    (    (    s6   lib/python2.7/site-packages/tornado/http1connection.pyt   <module>   s&   ÿ ÿ '4