
0Rc        <   @`  s  d  Z  d d l m Z m Z d d d d d d d	 d
 d d d d d d d d d d d d d d d d d d d d d d  d! d" d# d$ d% d& d' d( d) d* d+ d, d- d. d/ d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 d: d; d< d= d> g< 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 Z d d? l Z d d? l Z d d@ l m Z y: d dA l m Z m Z d dB l m Z d dC l m Z WnO e k
 rd dD l m Z m Z m Z d dE l m Z dF   Z dG   Z n Xd dH l m Z d dI l  m! Z! m" Z" m# Z# m$ Z$ m% Z% d dJ l& m' Z' m( Z( m) Z) m* Z* d dK l+ m, Z, d dL l- m. Z. m/ Z/ d dM l0 m1 Z1 d dN l2 m3 Z3 m4 Z4 d dO l5 m6 Z6 m7 Z7 m8 Z8 m9 Z9 m: Z: m; Z; m< Z< m= Z= m> Z> m? Z? m@ Z@ mA ZA mB ZB mC ZC mD ZD mE ZE mF ZF mG ZG mH ZH mI ZI mJ ZJ mK ZK mL ZL mM ZM mN ZN mO ZO mP ZP mQ ZQ mR ZR mS ZS mT ZT mU ZU mV ZV mW ZW mX ZX mY ZY mZ ZZ m[ Z[ m\ Z\ m] Z] m^ Z^ m_ Z_ m` Z` e! rea Zb n ea ec f Zb dP Zd dQ Ze e` Zf dR dS dT dU dV dW dX g Zg eh dY dZ d[ d\ d] d^ d_ d` da db dc dd g Zi g  eg D] Zj ej jk   ^ qZl g  ei D] Zj ej oLej jk   ^ q7Zm de   Z d d df  Zn eh dg  Zo eh dh  Zp di   Zq dj   Zr dk   Zs dl   Zt dm   Zu d8 f  dn     YZv d9 e/ jw f do     YZx dp dq f Zy e e' jz  d; f  dr     Y Z{ ds e| f dt     YZ} d< e| f du     YZ~ dv e| f dw     YZ dx e f dy     YZ dz e f d{     YZ d= e/ jw e. j f d|     YZ d> e) j f d}     YZ d? S(~   sJ  
HyperText Transfer Protocol implementation.

This is the basic server-side protocol implementation used by the Twisted
Web server.  It can parse HTTP 1.0 requests and supports many HTTP 1.1
features as well.  Additionally, some functionality implemented here is
also useful for HTTP clients (such as the chunked encoding parser).

@var CACHED: A marker value to be returned from cache-related request methods to
    indicate to the caller that a cached response will be usable and no response
    body should be generated.

@var NOT_MODIFIED: An HTTP response code indicating that a requested
    pre-condition (for example, the condition represented by an
    I{If-Modified-Since} header is present in the request) has succeeded.  This
    indicates a response body cached by the client can be used.

@var PRECONDITION_FAILED: An HTTP response code indicating that a requested
    pre-condition (for example, the condition represented by an I{If-None-Match}
    header is present in the request) has failed.  This should typically
    indicate that the server has not taken the requested action.
i    (   t   divisiont   absolute_importt	   SWITCHINGt   OKt   CREATEDt   ACCEPTEDt   NON_AUTHORITATIVE_INFORMATIONt
   NO_CONTENTt   RESET_CONTENTt   PARTIAL_CONTENTt   MULTI_STATUSt   MULTIPLE_CHOICEt   MOVED_PERMANENTLYt   FOUNDt	   SEE_OTHERt   NOT_MODIFIEDt	   USE_PROXYt   TEMPORARY_REDIRECTt   BAD_REQUESTt   UNAUTHORIZEDt   PAYMENT_REQUIREDt	   FORBIDDENt	   NOT_FOUNDt   NOT_ALLOWEDt   NOT_ACCEPTABLEt   PROXY_AUTH_REQUIREDt   REQUEST_TIMEOUTt   CONFLICTt   GONEt   LENGTH_REQUIREDt   PRECONDITION_FAILEDt   REQUEST_ENTITY_TOO_LARGEt   REQUEST_URI_TOO_LONGt   UNSUPPORTED_MEDIA_TYPEt   REQUESTED_RANGE_NOT_SATISFIABLEt   EXPECTATION_FAILEDt   INTERNAL_SERVER_ERRORt   NOT_IMPLEMENTEDt   BAD_GATEWAYt   SERVICE_UNAVAILABLEt   GATEWAY_TIMEOUTt   HTTP_VERSION_NOT_SUPPORTEDt   INSUFFICIENT_STORAGE_SPACEt   NOT_EXTENDEDt	   RESPONSESt   CACHEDt   urlparset   parse_qst   datetimeToStringt   datetimeToLogStringt   timegmt   stringToDatetimet   toChunkt	   fromChunkt   parseContentRanget   StringTransportt
   HTTPClientt   NO_BODY_CODESt   Requestt   PotentialDataLosst   HTTPChannelt   HTTPFactoryN(   t   BytesIO(   t   ParseResultR.   (   t   unquote(   t   parse_header(   t   ParseResultBytesR.   R@   (   t   TextIOWrapperc         O`  s"   t  |  j d  | |  j d  S(   Nt   charmap(   t   _unquotet   decodet   encode(   t   stringt   argst   kwargs(    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyR@   P   s    c         C`  s1   t  j |  j d   \ } } | j d  | f S(   NRD   (   t   cgiRA   RF   RG   (   t   linet   keyt   pdict(    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyt   _parseHeaderS   s    (   t   implementer(   t   _PY3t   unicodet
   intToBytest   networkStringt   nativeString(   t
   interfacest   reactort   protocolt   address(   t   Deferred(   t   policiest   basic(   t   log(   t   _DictHeaderst   Headers(+   R   R   R   R   R   R   R   R	   R
   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R    R!   R"   R#   R$   R%   R&   R'   R(   R)   R*   R+   R,   s   HTTP/1.1s   Magic constant returned by http.Request methods to set cache
validation headers when the request is conditional and the value fails
the condition.t   Mont   Tuet   Wedt   Thut   Frit   Satt   Sunt   Jant   Febt   Mart   Aprt   Mayt   Junt   Jult   Augt   Sept   Octt   Novt   Decc         C`  s   t  |  t  r t d   n  t |   \ } } } } } } t  | t  r | j d  } | j d  } | j d  } | j d  } | j d  } n  t | | | | | |  S(   s  
    Parse an URL into six components.

    This is similar to C{urlparse.urlparse}, but rejects C{unicode} input
    and always produces C{bytes} output.

    @type url: C{bytes}

    @raise TypeError: The given url was a C{unicode} string instead of a
        C{bytes}.

    @return: The scheme, net location, path, params, query string, and fragment
        of the URL - all as C{bytes}.
    @rtype: C{ParseResultBytes}
    s   url must be bytes, not unicodet   ascii(   t
   isinstanceRR   t	   TypeErrort	   _urlparseRG   RB   (   t   urlt   schemet   netloct   patht   paramst   queryt   fragment(    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyR.      s    c   
      C`  s   i  } g  |  j  d  D]" } | j  d  D] } | ^ q) q } x | D] } y | j  d d  \ } }	 Wn  t k
 r | rE   qE qE n X|	 s | rE t | j d d   } t |	 j d d   }	 | | k r | | j |	  q |	 g | | <qE qE W| S(   sn   
    Like C{cgi.parse_qs}, but with support for parsing byte strings on Python 3.

    @type qs: C{bytes}
    t   &t   ;t   =i   t   +t    (   t   splitt
   ValueErrorR@   t   replacet   append(
   t   qst   keep_blank_valuest   strict_parsingt   dt   s1t   s2t   itemst   itemt   kt   v(    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyR/      s     8c      	   C`  sv   |  d k r t j   }  n  t j |   \	 } } } } } } } } }	 t d t | | t | | | | | f  }
 |
 S(   sT   
    Convert seconds since epoch to HTTP datetime string.

    @rtype: C{bytes}
    s#   %s, %02d %3s %4d %02d:%02d:%02d GMTN(   t   Nonet   timet   gmtimeRT   t   weekdaynamet	   monthname(   t   msSinceEpocht   yeart   montht   dayt   hht   mmt   sst   wdt   yt   zt   s(    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyR0      s    *c      	   C`  si   |  d k r t j   }  n  t j |   \	 } } } } } } } } }	 d | t | | | | | f }
 |
 S(   sQ   
    Convert seconds since epoch to log datetime string.

    @rtype: C{str}
    s#   [%02d/%3s/%4d:%02d:%02d:%02d +0000]N(   R   R   R   R   (   R   R   R   R   R   R   R   R   R   R   R   (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyR1      s    *c         C`  s   d } |  | k  r( t  d | f   n  d | k o? d k n sJ t  d |  | t j | |   } x( t d |  D] } | t j | } qx W| d k r t j |   r | d } n  | | d } | d | }	 |	 d | }
 |
 d | } | S(	   s?   
    Convert time tuple in GMT to seconds since epoch, GMT
    i  s   Years prior to %d not supportedi   i   im  i   i   i<   (   R   t   AssertionErrort   calendart   leapdayst   ranget   mdayst   isleap(   R   R   R   t   hourt   minutet   secondt   EPOCHt   dayst   it   hourst   minutest   seconds(    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyR2      s    "c   
      C`  s  t  |   j   } | d d d !j   t k rX y t d |   SWqX t k
 rT qX Xn  t |  } | d k s| | d k r | d j   r | d } | d } | d } | d } n | d k s | d k rO| d j d	  d
 k rO| d j d	  \ } } } | d } t	 |  } | d k  r3| d } q| d k  r| d } qnM t |  d k r| d } | d } | d } | d } n t d |    t	 |  } t	 t
 j | j     } t	 |  } t t	 | j d   \ } } }	 t	 t | | | | | |	   S(   st   
    Convert an HTTP date string (one of three formats) to seconds since epoch.

    @type dateString: C{bytes}
    i    i   s   Sun, i   i   i   i   i   t   -iiE   i  id   il  s   Unknown datetime format %rt   :(   RU   R   t   lowert   weekdayname_lowerR3   R   t   lent   isdigitt   findt   intt   monthname_lowert   indext   mapR2   (
   t
   dateStringt   partst   partlenR   R   R   R   R   t   mint   sec(    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyR3      s>    (


1



!c         C`  s#   t  d t |   f  d |  d f S(   s   
    Convert string to a chunk.

    @type data: C{bytes}

    @returns: a tuple of C{bytes} representing the chunked encoding of data
    s   %xs   
(   RT   R   (   t   data(    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyR4   5  s    c         C`  s   |  j  d d  \ } } t | d  } | d k  rI t d | f   n  | | | d !d k ro t d   n  | |  | | d f S(   s   
    Convert chunk to string.

    @type data: C{bytes}

    @return: tuple of (result, remaining) - both C{bytes}.

    @raise ValueError: If the given data is not a correctly formatted chunked
        byte string.
    s   
i   i   i    s!   Chunk length must be >= 0, not %di   s   chunk must end with CRLF(   R   R   R   (   R   t   prefixt   restt   length(    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyR5   A  s    c         C`  s   |  j    j   \ } } | j   d k r9 t d   n  | j d  \ } } t t | j d   \ } } | d k r d } n t |  } | | | f S(   s   
    Parse a content-range header into (start, end, realLength).

    realLength might be None if real length is not known ('*').
    t   bytess#   a range of type %r is not supportedt   /R   t   *N(   t   stripR   R   R   R   R   R   (   t   headert   kindt   othert   startendt
   realLengtht   startt   end(    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyR6   V  s    	c           B`  s)   e  Z d  Z d   Z d   Z d   Z RS(   sp   
    I am a StringIO wrapper that conforms for the transport API. I support
    the `writeSequence' method.
    c         C`  s   t    |  _ d  S(   N(   t   StringIOR   (   t   self(    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyt   __init__n  s    c         C`  s   |  j  j d j |   d  S(   Nt    (   R   t   writet   join(   R   t   seq(    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyt   writeSequencep  s    c         C`  s   t  |  j d |  S(   NR   (   t   getattrt   __dict__(   R   t   attr(    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyt   __getattr__r  s    (   t   __name__t
   __module__t   __doc__R   R   R   (    (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyR7   i  s   		c           B`  s   e  Z d  Z d Z e Z d Z d Z d   Z	 d   Z
 d   Z d   Z d   Z d   Z d   Z d	   Z d
   Z d   Z d   Z d   Z d   Z RS(   sA  
    A client for HTTP 1.0.

    Notes:
    You probably want to send a 'Host' header with the name of the site you're
    connecting to, in order to not break name based virtual hosting.

    @ivar length: The length of the request body in bytes.
    @type length: C{int}

    @ivar firstLine: Are we waiting for the first header line?
    @type firstLine: C{bool}

    @ivar __buffer: The buffer that stores the response to the HTTP request.
    @type __buffer: A C{StringIO} object.

    @ivar _header: Part or all of an HTTP request header.
    @type _header: C{bytes}
    R   c         C`  s    |  j  j | d | d g  d  S(   NR   s    HTTP/1.0
(   t	   transportR   (   R   t   commandRz   (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyt   sendCommand  s    c         C`  sD   t  | t  s$ t t |   } n  |  j j | d | d g  d  S(   Ns   : s   
(   Rt   R   RT   t   strR   R   (   R   t   namet   value(    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyt
   sendHeader  s    c         C`  s   |  j  j d  d  S(   Ns   
(   R   R   (   R   (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyt
   endHeaders  s    c         C`  s\   | j  d d  \ } } | j   } |  j | |  | j   d k rX t |  |  _ n  d S(   s   
        Given a complete HTTP header, extract the field name and value and
        process the header.

        @param header: a complete HTTP request header of the form
            'field-name: value'.
        @type header: C{bytes}
        R   i   s   content-lengthN(   R   t   lstript   handleHeaderR   R   R   (   R   R   RM   t   val(    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyt   extractHeader  s
    	c         C`  s&  |  j  rw t |  _  | j d d  } | d } | d } y | d } Wn t k
 r_ d } n X|  j | | |  d S| s |  j d k r |  j |  j  n  t   |  _	 |  j
   |  j   d S| j d  s | j d  r |  j | |  _ n. |  j r|  j |  j  | |  _ n	 | |  _ d S(   s   
        Parse the status line and headers for an HTTP request.

        @param line: Part of an HTTP request header. Request bodies are parsed
            in L{rawDataReceived}.
        @type line: C{bytes}
        i   i    i   R   Ns   	R   (   t	   firstLinet   FalseR   R   t
   IndexErrort   handleStatust   _headerR   R   t   _HTTPClient__buffert   handleEndHeaderst
   setRawModet
   startswith(   R   RL   t   lt   versiont   statust   message(    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyt   lineReceived  s0    		




	c         C`  s   |  j    d  S(   N(   t   handleResponseEnd(   R   t   reason(    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyt   connectionLost  s    c         C`  s;   |  j  d k	 r7 |  j  j   } d |  _  |  j |  n  d S(   s~   
        The response has been completely received.

        This callback may be invoked more than once per request.
        N(   R   R   t   getvaluet   handleResponse(   R   t   b(    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyR     s    	c         C`  s   |  j  j |  d  S(   N(   R   R   (   R   R   (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyt   handleResponsePart  s    c         C`  s   d  S(   N(    (   R   (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyt   connectionMade  s    c         C`  s   d S(   s   
        Called when the status-line is received.

        @param version: e.g. 'HTTP/1.0'
        @param status: e.g. '200'
        @type status: C{bytes}
        @param message: e.g. 'OK'
        N(    (   R   R   R   R   (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyR     s    c         C`  s   d S(   s9   
        Called every time a header is received.
        N(    (   R   RM   R   (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyR     s    c         C`  s   d S(   s=   
        Called when all headers have been received.
        N(    (   R   (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyR     s    c         C`  s   |  j  d  k	 rB | |  j   | |  j  } } |  j  t |  8_  n d } |  j |  |  j  d k r~ |  j   |  j |  n  d  S(   NR   i    (   R   R   R   R   R   t   setLineMode(   R   R   R   (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyt   rawDataReceived   s    
N(   R   R   R   R   R   t   TrueR   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R  (    (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyR8   w  s$   					*					
		i   i0  c           B`  s  e  Z d  Z d* Z d Z e Z e e Z	 d Z
 d Z d Z d Z d Z d Z d* Z d* Z d* Z d* Z d* Z d Z e Z d   Z d   Z e d    Z e d    Z d	   Z d
   Z d   Z d   Z  d   Z! d   Z" d   Z# d   Z$ d   Z% d   Z& d   Z' d   Z( d   Z) d   Z* d   Z+ d   Z, d* d* d* d* d* d* d  Z- d* d  Z. d   Z/ d   Z0 d   Z1 d   Z2 d   Z3 d    Z4 d!   Z5 d d"  Z6 d#   Z7 d$   Z8 d%   Z9 d&   Z: d'   Z; d(   Z< d)   Z= RS(+   s  
    A HTTP request.

    Subclasses should override the process() method to determine how
    the request will be processed.

    @ivar method: The HTTP method that was used.
    @ivar uri: The full URI that was requested (includes arguments).
    @ivar path: The path only (arguments not included).
    @ivar args: All of the arguments, including URL and POST arguments.
    @type args: A mapping of strings (the argument names) to lists of values.
                i.e., ?foo=bar&foo=baz&quux=spam results in
                {'foo': ['bar', 'baz'], 'quux': ['spam']}.

    @type requestHeaders: L{http_headers.Headers}
    @ivar requestHeaders: All received HTTP request headers.

    @ivar received_headers: Backwards-compatibility access to
        C{requestHeaders}.  Use C{requestHeaders} instead.  C{received_headers}
        behaves mostly like a C{dict} and does not provide access to all header
        values.

    @type responseHeaders: L{http_headers.Headers}
    @ivar responseHeaders: All HTTP response headers to be sent.

    @ivar headers: Backwards-compatibility access to C{responseHeaders}.  Use
        C{responseHeaders} instead.  C{headers} behaves mostly like a C{dict}
        and does not provide access to all header values nor does it allow
        multiple values for one header to be set.

    @ivar notifications: A C{list} of L{Deferred}s which are waiting for
        notification that the response to this request has been finished
        (successfully or with an error).  Don't use this attribute directly,
        instead use the L{Request.notifyFinish} method.

    @ivar _disconnected: A flag which is C{False} until the connection over
        which this request was received is closed and which is C{True} after
        that.
    @type _disconnected: C{bool}
    i    s   (no method yet)s   (no clientproto yet)s   (no uri yet)c         C`  sm   g  |  _  | |  _ | |  _ t   |  _ i  |  _ t   |  _ g  |  _ | rZ t   |  _	 n |  j j	 |  _	 d S(   s   
        @param channel: the channel we're connected to.
        @param queued: are we in the request queue, or can we start writing to
            the transport?
        N(
   t   notificationst   channelt   queuedR_   t   requestHeaderst   received_cookiest   responseHeaderst   cookiesR7   R   (   R   R  R  (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyR   M  s    					c      
   C`  s3   t  j d t d d t d | d |  d d  d S(	   sJ  
        Emit a warning related to use of one of the deprecated C{headers} or
        C{received_headers} attributes.

        @param old: The name of the deprecated attribute to which the warning
            pertains.

        @param new: The name of the preferred attribute which replaces the old
            attribute.
        t   categoryR   sw   twisted.web.http.Request.%(old)s was deprecated in Twisted 13.2.0: Please use twisted.web.http.Request.%(new)s instead.t   oldt   newt
   stackleveli   N(   t   warningst   warnt   DeprecationWarningt   dict(   R   R  R  (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyt   _warnHeadersa  s
    	c         C`  s   |  j  d d  t |  j  S(   s   
        Transform the L{Headers}-style C{responseHeaders} attribute into a
        deprecated C{dict}-style C{headers} attribute.
        t   headersR  (   R  R^   R  (   R   (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyR  u  s    c         C`  s   |  j  d d  t |  j  S(   s   
        Transform the L{Headers}-style C{requestHeaders} attribute into a
        deprecated C{dict}-style C{received_headers} attribute.
        t   received_headersR  (   R  R^   R  (   R   (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyR    s    c         C`  s   | d k r_ t    |  _ } x- | j   D] \ } } | j | | g  q) W|  j d d  nl | d k r t    |  _ } x- | j   D] \ } } | j | | g  q W|  j d d  n | |  j | <d S(   su   
        Support assignment of C{dict} instances to C{received_headers} for
        backwards-compatibility.
        R  R  R  R  N(   R_   R  R   t   setRawHeadersR  R  R   (   R   R   R   R  R   R   (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyt   __setattr__  s    c         C`  s   |  j  r0 t j t d |  j   |  j   n  |  j j |   |  ` y |  j j	   Wn t
 k
 rj n X|  ` x |  j D] } | j d  q{ Wg  |  _ d S(   sP   
        Called when have finished responding and are no longer queued.
        s$   Producer was not unregistered for %sN(   t   producerR]   t   errt   RuntimeErrort   urit   unregisterProducerR  t   requestDonet   contentt   closet   OSErrorR  t   callbackR   (   R   R   (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyt   _cleanup  s    	c         C`  s   |  j  s t d   n  d |  _  |  j j   } |  j j |  _ | rX |  j j |  n  |  j d k	 r |  j r |  j j	 |  j |  j
  n  |  j r |  j   n  d S(   s   
        Notify the object that it is no longer queued.

        We start writing whatever data we have to the transport, etc.

        This method is not intended for users.
        s*   noLongerQueued() got called unnecessarily.i    N(   R  R  R   R   R  R   R  R   t   finishedt   registerProducert   streamingProducerR!  (   R   R   (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyt   noLongerQueued  s    			c         C`  s:   | d k	 r' | d k  r' t   |  _ n t j   |  _ d S(   s0  
        Called when HTTP channel got length of content in this request.

        This method is not intended for users.

        @param length: The length of the request body, as indicated by the
            request headers.  C{None} if the request headers do not indicate a
            length.
        i N(   R   R   R  t   tempfilet   TemporaryFile(   R   R   (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyt	   gotLength  s    
c         C`  s   |  j  j d  } | d k r" d Sxz | D]r } | r) xc | j d  D]O } | j   } y) | j d d  \ } } | |  j | <WqE t k
 r qE XqE Wq) q) Wd S(   sW   
        Parse cookie headers.

        This method is not intended for users.
        t   cookieNR   R   i   (   R  t   getRawHeadersR   R   R   R  R   (   R   t   cookieheaderst	   cookietxtt   cookR   R   (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyt   parseCookies  s    c         C`  s   |  j  j |  d S(   sX   
        Write a chunk of data.

        This method is not intended for users.
        N(   R  R   (   R   R   (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyt   handleContentChunk  s    c         C`  s  |  j  j d d  i  |  _ g  |  _ | | |  _ |  _ | |  _ |  j j d d  } t |  d k rw |  j |  _	 n! | \ |  _	 } t
 | d  |  _ |  j j j   |  _ |  j j j   |  _ |  j } |  j j d  } | d
 k	 r | d } n  |  j d k r| rd } t |  \ }	 }
 |	 d k rQ| j t
 |  j  j   d   n |	 | k ry  | j t j |  j  |
   Wqt k
 r} | j d d k r|  j j j d	  |  j j j   d
 S  qXn  |  j  j d d  n  |  j   d
 S(   s  
        Called by channel when all data has been received.

        This method is not intended for users.

        @type command: C{bytes}
        @param command: The HTTP verb of this request.  This has the case
            supplied by the client (eg, it maybe "get" rather than "GET").

        @type path: C{bytes}
        @param path: The URI of this request.

        @type version: C{bytes}
        @param version: The HTTP version of this request.
        i    t   ?i   s   content-typet   POSTs   multipart/form-datas!   application/x-www-form-urlencodeds   content-dispositions   HTTP/1.1 400 Bad Request

N(   R  t   seekRI   t   stackt   methodR  t   clientprotoR   R   Rz   R/   R  R   t   getPeert   clientt   getHostt   hostR  R*  R   RO   t   updatet   readRK   t   parse_multipartt   KeyErrorR   t   loseConnectiont   process(   R   R   Rz   R   t   xt	   argstringRI   t   ctypet   mfdRM   RN   t   e(    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyt   requestReceived  sB    				" 
c         C`  s>   d |  j  j t |   t |  j  t |  j  t |  j  f S(   s   
        Return a string description of the request including such information
        as the request method and request URI.

        @return: A string loosely describing this L{Request} object.
        @rtype: L{str}
        s,   <%s at 0x%x method=%s uri=%s clientproto=%s>(   t	   __class__R   t   idRU   R4  R  R5  (   R   (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyt   __repr__=  s    		c         C`  s   d S(   sY   
        Override in subclasses.

        This method is not intended for users.
        N(    (   R   (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyR?  M  s    c         C`  sm   |  j  r% t d | |  j  f   n  | |  _ | |  _  |  j rV | ri | j   qi n |  j j | |  d S(   s&   
        Register a producer.
        sA   registering producer %s before previous one (%s) was unregisteredN(   R  R   R$  R  t   pauseProducingR   R#  (   R   R  t	   streaming(    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyR#  X  s    				c         C`  s&   |  j  s |  j j   n  d |  _ d S(   s*   
        Unregister the producer.
        N(   R  R   R  R   R  (   R   (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyR  j  s    	c         C`  s*   |  j  j |  } | d k	 r& | d Sd S(   s-  
        Get an HTTP request header.

        @type key: C{bytes}
        @param key: The name of the header to get the value of.

        @rtype: C{bytes} or C{NoneType}
        @return: The value of the specified header, or C{None} if that header
            was not present in the request.
        iN(   R  R*  R   (   R   RM   R   (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyt	   getHeaderu  s    c         C`  s   |  j  j |  S(   s>   
        Get a cookie that was sent from the network.
        (   R  t   get(   R   RM   (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyt	   getCookie  s    c         C`  s   |  j  j t    |  j  d S(   s  
        Notify when the response to this request has finished.

        @rtype: L{Deferred}

        @return: A L{Deferred} which will be triggered when the request is
            finished -- with a C{None} value if the request finishes
            successfully or with an error if the request is interrupted by an
            error (for example, the client closing the connection prematurely).
        i(   R  R   RZ   (   R   (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyt   notifyFinish  s    c         C`  s   |  j  r t d   n  |  j r8 t j d d d d S|  j sQ |  j d  n  |  j rm |  j j d  n  t	 |  j
 d  r |  j
 j j |   n  d	 |  _ |  j s |  j   n  d S(
   sV   
        Indicate that all response data has been written to this L{Request}.
        sq   Request.finish called on a request after its connection was lost; use Request.notifyFinish to keep track of this.s%   Warning! request.finish called twice.R  i   NR   s   0

t   factoryi   (   t   _disconnectedR  R"  R  R  t   startedWritingR   t   chunkedR   t   hasattrR  RO  R]   R  R!  (   R   (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyt   finish  s    						c         C`  s  |  j  r t d   n  |  j sYd |  _ |  j } g  } | j | d t |  j  d t |  j  d  | d k r |  j	 j
 d  d k r |  j d k r |  j t k r | j d  d |  _ n  |  j d k	 r|  j	 j d	  r t j d
  q|  j	 j d	 t |  j  g  n  |  j d k	 rE|  j	 j d |  j g  n  x |  j	 j   D]t \ } } xe | D]] } t | t  st j d d t d d t d | f  } n  | j | d | d g  qhWqUWx+ |  j D]  } | j t d | f   qW| j d  |  j j |  |  j d k r7d   |  _  d S|  j t k rYd   |  _  d Sn  |  j! t" |  |  _! | r|  j r|  j j t# |   q|  j j  |  n  d S(   s   
        Write some data as a result of an HTTP request.  The first
        time this is called, it writes out response data.

        @type data: C{bytes}
        @param data: Some bytes to be sent as part of the response body.
        sB   Request.write called on a request after Request.finish was called.i   R   s   
s   HTTP/1.1s   content-lengtht   HEADs   Transfer-Encoding: chunked
s   last-modifiedsP   Warning: last-modified specified both in header list and lastModified attribute.t   ETagsZ   Passing non-bytes header values is deprecated since Twisted 12.3. Pass only bytes instead.R
  R  i   s   %ss   : s   Set-Cookie: %s
c         S`  s   d  S(   N(   R   (   R   (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyt   <lambda>  s    Nc         S`  s   d  S(   N(   R   (   R   (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyRW    s    ($   R"  R  RQ  R5  R   RS   t   codeRT   t   code_messageR  R*  R   R4  R9   RR  t   lastModifiedt	   hasHeaderR]   t   msgR  R0   t   etagt   getAllRawHeadersRt   R   R  R  R  t   extendR	  R   R   R   t
   sentLengthR   R4   (   R   R   R   R   R   t   valuesR   R)  (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyR     sX    				-	!	c	   
      C`  s   d | | f }	 | d k	 r- |	 d | }	 n  | d k	 rJ |	 d | }	 n  | d k	 rg |	 d | }	 n  | d k	 r |	 d | }	 n  | d k	 r |	 d | }	 n  | r |	 d }	 n  |  j j |	  d S(	   s   
        Set an outgoing HTTP cookie.

        In general, you should consider using sessions instead of cookies, see
        L{twisted.web.server.Request.getSession} and the
        L{twisted.web.server.Session} class for details.
        s   %s=%ss   ; Expires=%ss   ; Domain=%ss	   ; Path=%ss   ; Max-Age=%ss   ; Comment=%ss   ; SecureN(   R   R	  R   (
   R   R   R   t   expirest   domainRz   t   max_aget   commentt   secureR)  (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyt	   addCookie  s    c         C`  sR   t  | t  s t d   n  | |  _ | r9 | |  _ n t j | d  |  _ d S(   si   
        Set the HTTP response code.

        @type code: C{int}
        @type message: C{bytes}
        s&   HTTP response code must be int or longs   Unknown StatusN(   Rt   t	   _intTypesRu   RX  RY  R,   RL  (   R   RX  R   (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyt   setResponseCode  s    	c         C`  s   |  j  j | | g  d S(   s.  
        Set an HTTP response header.  Overrides any previously set values for
        this header.

        @type name: C{bytes}
        @param name: The name of the header for which to set the value.

        @type value: C{bytes}
        @param value: The value to set for the named header.
        N(   R  R  (   R   R   R   (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyt	   setHeader+  s    c         C`  s!   |  j  t  |  j d |  d S(   su   
        Utility function that does a redirect.

        The request should have finish() called after this.
        t   locationN(   Ri  R   Rj  (   R   Rw   (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyt   redirect9  s    c         C`  s   t  t j |   } |  j s. |  j | k  r: | |  _ n  |  j d  } | r | j d d  d } y t |  } Wn t k
 r d SX| | k r |  j	 t
  t Sn  d S(   s  
        Set the C{Last-Modified} time for the response to this request.

        If I am called more than once, I ignore attempts to set
        Last-Modified earlier, only replacing the Last-Modified time
        if it is to a later value.

        If I am a conditional request, I may modify my response code
        to L{NOT_MODIFIED} if appropriate for the time given.

        @param when: The last time the resource being returned was
            modified, in seconds since the epoch.
        @type when: number
        @return: If I am a C{If-Modified-Since} conditional request and
            the time given is not newer than the condition, I return
            L{http.CACHED<CACHED>} to indicate that you should write no
            body.  Otherwise, I return a false value.
        s   if-modified-sinceR   i   i    N(   R   t   matht   ceilRZ  RK  R   R3   R   R   Ri  R   R-   (   R   t   whent   modifiedSincet	   firstPart(    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyt   setLastModifiedC  s    c         C`  sx   | r | |  _  n  |  j d  } | rt | j   } | | k sK d | k rt |  j |  j d k rf t pi t  t Sn  d S(   s  
        Set an C{entity tag} for the outgoing response.

        That's "entity tag" as in the HTTP/1.1 C{ETag} header, "used
        for comparing two or more entities from the same requested
        resource."

        If I am a conditional request, I may modify my response code
        to L{NOT_MODIFIED} or L{PRECONDITION_FAILED}, if appropriate
        for the tag given.

        @param etag: The entity tag for the resource being returned.
        @type etag: string
        @return: If I am a C{If-None-Match} conditional request and
            the tag matches one in the request, I return
            L{http.CACHED<CACHED>} to indicate that you should write
            no body.  Otherwise, I return a false value.
        s   if-none-matchR   RU  t   GET(   s   HEADs   GETN(	   R]  RK  R   Ri  R4  R   R   R-   R   (   R   R]  t   tags(    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyt   setETagh  s    c         C`  s>   i  } x1 |  j  j   D]  \ } } | d | | j   <q W| S(   s  
        Return dictionary mapping the names of all received headers to the last
        value received for each.

        Since this method does not return all header information,
        C{self.requestHeaders.getAllRawHeaders()} may be preferred.
        i(   R  R^  R   (   R   R  R   R   (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyt   getAllHeaders  s    c         C`  s<   |  j  d  } | r) | j d d  d St |  j   j  S(   s  
        Get the hostname that the user passed in to the request.

        This will either use the Host: header (if it is available) or the
        host we are listening on if the header is unavailable.

        @returns: the requested hostname
        @rtype: C{bytes}
        R9  R   i   i    (   RK  R   RT   R8  R9  (   R   R9  (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyt   getRequestHostname  s    c         C`  s   |  j  S(   s   
        Get my originally requesting transport's host.

        Don't rely on the 'transport' attribute, since Request objects may be
        copied remotely.  For information on this method's return value, see
        twisted.internet.tcp.Port.
        (   R9  (   R   (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyR8    s    c         C`  s   | |  _  |  j   r d } n d } | | k r9 | } n | d t |  } |  j j d | g  t j d | |  |  _ d S(   s  
        Change the host and port the request thinks it's using.

        This method is useful for working with reverse HTTP proxies (e.g.
        both Squid and Apache's mod_proxy can do this), when the address
        the HTTP client is using is different than the one we're listening on.

        For example, Apache may be listening on https://www.example.com/, and
        then forwarding requests to http://localhost:8080/, but we don't want
        HTML produced by Twisted to say b'http://localhost:8080/', they should
        say b'https://www.example.com/', so we do::

           request.setHost(b'www.example.com', 443, ssl=1)

        @type host: C{bytes}
        @param host: The value to which to change the host header.

        @type ssl: C{bool}
        @param ssl: A flag which, if C{True}, indicates that the request is
            considered secure (if C{True}, L{isSecure} will return C{True}).
        i  iP   R   R9  t   TCPN(   t	   _forceSSLt   isSecureRS   R  R  RY   t   IPv4AddressR9  (   R   R9  t   portt   sslt   defaultt
   hostHeader(    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyt   setHost  s    			c         C`  s'   t  |  j t j  r |  j j Sd Sd S(   s   
        Return the IP address of the client who submitted this request.

        @returns: the client IP address
        @rtype: C{str}
        N(   Rt   R7  RY   R{  R9  R   (   R   (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyt   getClientIP  s    
c         C`  sK   |  j  r t St t |  d d  d d  } t j | d  d k	 rG t St S(   sz  
        Return True if this request is using a secure transport.

        Normally this method returns True if this request's HTTPChannel
        instance is using a transport that implements ISSLTransport.

        This will also return True if setHost() has been called
        with ssl=True.

        @returns: True if this request is secure
        @rtype: C{bool}
        R  R   N(   Ry  R  R   R   RV   t   ISSLTransportR   (   R   R   (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyRz    s    	c         C`  s   y |  j  d  } | s, d |  _ |  _ d  S| j   \ } } | j   d k r\ t    n  t j |  } | j d d  \ |  _ |  _ WnJ t j	 t f k
 r d |  _ |  _ n! t
 j   d |  _ |  _ n Xd  S(   Nt   AuthorizationR   R\   R   i   (   RK  t   usert   passwordR   R   R   t   base64t   decodestringt   binasciit   ErrorR]   R  (   R   t   authht   bast   upw(    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyt
   _authorize  s    "
c         C`  s&   y |  j  SWn n X|  j   |  j  S(   s   
        Return the HTTP user sent with this request, if any.

        If no user was supplied, return the empty string.

        @returns: the HTTP user, if any
        @rtype: C{bytes}
        (   R  R  (   R   (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyt   getUser	  s    	
c         C`  s&   y |  j  SWn n X|  j   |  j  S(   s   
        Return the HTTP password sent with this request, if any.

        If no password was supplied, return the empty string.

        @returns: the HTTP password, if any
        @rtype: C{bytes}
        (   R  R  (   R   (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyt   getPassword  s    	
c         C`  s   |  j  j d k r d  S|  j  j } y t j |  \ } } } Wn t j k
 rU | SX| j d |  x | D] } d | k rm | Sqm W| d S(   NRx  i    t   .(   R7  t   typeR   R9  t   sockett   gethostbyaddrt   errort   insert(   R   R9  R   t   namest	   addresses(    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyt	   getClient+  s    c         C`  s_   t  |  _ d |  _ |  j d k	 r1 |  j j   n  x |  j D] } | j |  q; Wg  |  _ d S(   s   
        There is no longer a connection for this request to respond over.
        Clean up anything which can't be useful anymore.
        N(   R  RP  R   R  R  R  R  t   errback(   R   R   R   (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyR   :  s    		N(>   R   R   R   R   R  R"  R   RX  R,   RY  R4  R5  R  RQ  RR  R`  R]  RZ  RI   Rz   R  Ry  R   RP  R   R  t   propertyR  R  R  R!  R%  R(  R.  R/  RE  RH  R?  R#  R  RK  RM  RN  RT  R   Rg  Ri  Rj  Rl  Rr  Ru  Rv  Rw  R8  R  R  Rz  R  R  R  R  R   (    (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyR:     sn   )
		

								A									L		
	%	!			
#						t	   _DataLossc           B`  s   e  Z d  Z RS(   s;  
    L{_DataLoss} indicates that not all of a message body was received. This
    is only one of several possible exceptions which may indicate that data
    was lost.  Because of this, it should not be checked for by
    specifically; any unexpected exception should be treated as having
    caused data loss.
    (   R   R   R   (    (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyR  I  s   c           B`  s   e  Z d  Z RS(   s  
    L{PotentialDataLoss} may be raised by a transfer encoding decoder's
    C{noMoreData} method to indicate that it cannot be determined if the
    entire response body has been delivered.  This only occurs when making
    requests to HTTP servers which do not set I{Content-Length} or a
    I{Transfer-Encoding} in the response because in this case the end of the
    response is indicated by the connection being closed, an event which may
    also be due to a transient network problem or other error.
    (   R   R   R   (    (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyR;   T  s   	t   _MalformedChunkedDataErrorc           B`  s   e  Z d  Z RS(   s  
    C{_ChunkedTranferDecoder} raises L{_MalformedChunkedDataError} from its
    C{dataReceived} method when it encounters malformed data. This exception
    indicates a client-side error. If this exception is raised, the connection
    should be dropped with a 400 error.
    (   R   R   R   (    (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyR  a  s   t   _IdentityTransferDecoderc           B`  s)   e  Z d  Z d   Z d   Z d   Z RS(   sZ  
    Protocol for accumulating bytes up to a specified length.  This handles the
    case where no I{Transfer-Encoding} is specified.

    @ivar contentLength: Counter keeping track of how many more bytes there are
        to receive.

    @ivar dataCallback: A one-argument callable which will be invoked each
        time application data is received.

    @ivar finishCallback: A one-argument callable which will be invoked when
        the terminal chunk is received.  It will be invoked with all bytes
        which were delivered to this protocol which came after the terminal
        chunk.
    c         C`  s   | |  _  | |  _ | |  _ d  S(   N(   t   contentLengtht   dataCallbackt   finishCallback(   R   R  R  R  (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyR   {  s    		c         C`  s   |  j  d k r t d   n  |  j d k r= |  j  |  n t |  |  j k  rw |  j t |  8_ |  j  |  nP |  j } |  j  } |  j } d |  _  |  _ d |  _ | | |   | | |  d S(   s;  
        Interpret the next chunk of bytes received.  Either deliver them to the
        data callback or invoke the finish callback if enough bytes have been
        received.

        @raise RuntimeError: If the finish callback has already been invoked
            during a previous call to this methood.
        s;   _IdentityTransferDecoder cannot decode data after finishingi    N(   R  R   R  R  R   R  (   R   R   R  R  R  (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyt   dataReceived  s    					c         C`  s]   |  j  } d |  _ |  _  |  j d k r> | d  t    n |  j d k rY t    n  d S(   sp  
        All data which will be delivered to this decoder has been.  Check to
        make sure as much data as was expected has been received.

        @raise PotentialDataLoss: If the content length is unknown.
        @raise _DataLoss: If the content length is known and fewer than that
            many bytes have been delivered.

        @return: C{None}
        R   i    N(   R  R   R  R  R;   R  (   R   R  (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyt
   noMoreData  s    	
(   R   R   R   R   R  R  (    (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyR  k  s   		 t   _ChunkedTransferDecoderc           B`  s\   e  Z d  Z d Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d	   Z RS(
   s  
    Protocol for decoding I{chunked} Transfer-Encoding, as defined by RFC 2616,
    section 3.6.1.  This protocol can interpret the contents of a request or
    response body which uses the I{chunked} Transfer-Encoding.  It cannot
    interpret any of the rest of the HTTP protocol.

    It may make sense for _ChunkedTransferDecoder to be an actual IProtocol
    implementation.  Currently, the only user of this class will only ever
    call dataReceived on it.  However, it might be an improvement if the
    user could connect this to a transport and deliver connection lost
    notification.  This way, `dataCallback` becomes `self.transport.write`
    and perhaps `finishCallback` becomes `self.transport.loseConnection()`
    (although I'm not sure where the extra data goes in that case).  This
    could also allow this object to indicate to the receiver of data that
    the stream was not completely received, an error case which should be
    noticed. -exarkun

    @ivar dataCallback: A one-argument callable which will be invoked each
        time application data is received.

    @ivar finishCallback: A one-argument callable which will be invoked when
        the terminal chunk is received.  It will be invoked with all bytes
        which were delivered to this protocol which came after the terminal
        chunk.

    @ivar length: Counter keeping track of how many more bytes in a chunk there
        are to receive.

    @ivar state: One of C{'CHUNK_LENGTH'}, C{'CRLF'}, C{'TRAILER'},
        C{'BODY'}, or C{'FINISHED'}.  For C{'CHUNK_LENGTH'}, data for the
        chunk length line is currently being read.  For C{'CRLF'}, the CR LF
        pair which follows each chunk is being read. For C{'TRAILER'}, the CR
        LF pair which follows the terminal 0-length chunk is currently being
        read. For C{'BODY'}, the contents of a chunk are being read. For
        C{'FINISHED'}, the last chunk has been completely read and no more
        input is valid.
    t   CHUNK_LENGTHc         C`  s   | |  _  | |  _ d |  _ d  S(   NR   (   R  R  t   _buffer(   R   R  R  (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyR     s    		c         C`  s   d | k r | j  d d  \ } } | j  d  } y t | d d  |  _ Wn t k
 rl t d   n X|  j d k r d |  _ n	 d |  _ | S| |  _ d	 Sd  S(
   Ns   
i   R   i    i   s   Chunk-size must be an integer.t   TRAILERt   BODYR   (   R   R   R   R   R  t   stateR  (   R   R   RL   R   R   (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyt   _dataReceived_CHUNK_LENGTH  s    		c         C`  s1   | j  d  r  d |  _ | d S| |  _ d Sd  S(   Ns   
R  i   R   (   R   R  R  (   R   R   (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyt   _dataReceived_CRLF  s
    		c         C`  s?   | j  d  r2 | d } d |  _ |  j |  n	 | |  _ d S(   Ns   
i   t   FINISHEDR   (   R   R  R  R  (   R   R   (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyt   _dataReceived_TRAILER   s    
		c         C`  s   t  |  |  j k rJ | |  j  | |  j } } |  j |  d |  _ | St  |  |  j k  r |  j t  |  8_ |  j |  d Sd  S(   Nt   CRLFR   (   R   R   R  R  (   R   R   t   chunk(    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyt   _dataReceived_BODY
  s    	c         C`  s   t  d   d  S(   NsJ   _ChunkedTransferDecoder.dataReceived called after last chunk was processed(   R  (   R   R   (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyt   _dataReceived_FINISHED  s    c         C`  sF   |  j  | } d |  _  x) | rA t |  d |  j f  |  } q Wd S(   su   
        Interpret data from a request or response body which uses the
        I{chunked} Transfer-Encoding.
        R   s   _dataReceived_%sN(   R  R   R  (   R   R   (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyR    s    		c         C`  s,   |  j  d k r( t d |  j  f   n  d S(   sj   
        Verify that all data has been received.  If it has not been, raise
        L{_DataLoss}.
        R  sR   Chunked decoder in %r state, still expecting more data to get to 'FINISHED' state.N(   R  R  (   R   (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyR  '  s    (   R   R   R   R  R   R  R  R  R  R  R  R  (    (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyR    s   %					
			c           B`  s   e  Z d  Z d Z d Z d Z d Z d Z d Z	 e
 Z d Z d Z d   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   
    A receiver for HTTP requests.

    @ivar _transferDecoder: C{None} or an instance of
        L{_ChunkedTransferDecoder} if the request body uses the I{chunked}
        Transfer-Encoding.
    i  i    i   R   c         C`  s   g  |  _  d  |  _ d  S(   N(   t   requestsR   t   _transferDecoder(   R   (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyR   J  s    	c         C`  s   |  j  |  j  d  S(   N(   t
   setTimeoutt   timeOut(   R   (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyR   P  s    c         C`  s  |  j    |  j r |  j s3 d   |  _ |  _ d  S| rV |  j d k rV d |  _ d  S|  j |  t |  j   } |  j j |  d |  _ | j	   } t |  d k r |  j
 j d  |  j
 j   d  S| \ } } } | |  _ | |  _ | |  _ n | d k rZ|  j r|  j |  j  n  d |  _ |  j   |  j d k rM|  j   q|  j   nL | d d k r|  j d	 | |  _ n% |  j r|  j |  j  n  | |  _ d  S(
   Nc          W`  s   d  S(   N(   R   (   RI   (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyRW  Z  s    i   i   i    i   s   HTTP/1.1 400 Bad Request

R   s    	s   
(   t   resetTimeoutt   _HTTPChannel__first_linet
   persistentR  R   t   requestFactoryR   R  R   R   R   R   R>  t   _commandt   _patht   _versiont   _HTTPChannel__headert   headerReceivedt   allHeadersReceivedR   t   allContentReceivedR   (   R   RL   t   requestR   R   R   (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyR   S  sB    
								
	c         C`  s   |  j    |  j |  d  S(   N(   R  R   (   R   R   (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyt   _finishRequestBody  s    
c         C`  s  | j  d d  \ } } | j   } | j   } | d k r y t |  |  _ Wn8 t k
 r |  j j d  d |  _ |  j j	   d SXt
 |  j |  j d j |  j  |  _ nI | d k r | j   d k r d |  _ t |  j d j |  j  |  _ n  |  j d j } | j |  } | d k	 r6| j |  n | j | | g  |  j d 7_ |  j |  j k r|  j j d  |  j j	   n  d S(	   s  
        Do pre-processing (for content-length) and store this header away.
        Enforce the per-request header limit.

        @type line: C{bytes}
        @param line: A line from the header section of a request, excluding the
            line delimiter.
        R   i   s   content-lengths   HTTP/1.1 400 Bad Request

Nis   transfer-encodingRR  (   R   R   R   R   R   R   R   R   R   R>  R  R  R/  R  R  R  R  R*  R   R  t   _receivedHeaderCountt
   maxHeaders(   R   RL   R   R   t
   reqHeadersRa  (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyR    s4    		%	c         C`  s   |  j  } |  j } |  j } d |  _ d |  _ d |  _ d  |  _ |  `  |  ` |  ` |  j ro |  j	 d   |  _
 n  |  j d } | j | | |  d  S(   Ni    i   i(   R  R  R  R   R  R  R   R  R  R  t   _savedTimeOutR  RE  (   R   R   Rz   R   t   req(    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyR    s    								c         C`  sS   |  j    y |  j j |  Wn. t k
 rN |  j j d  |  j j   n Xd  S(   Ns   HTTP/1.1 400 Bad Request

(   R  R  R  R  R   R   R>  (   R   R   (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyR    s    
c         C`  s   |  j  d } | j   |  j | |  j  |  _ | j |  j  | j j d  } | r | d j	   d k r |  j d k r | j
 j d  n  d  S(   Nit   expecti    s   100-continues   HTTP/1.1s   HTTP/1.1 100 Continue

(   R  R.  t   checkPersistenceR  R  R(  R   R  R*  R   R   R   (   R   R  t   expectContinue(    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyR    s    
c         C`  s   | j  j d  } | rG g  | d j d  D] } | j   ^ q, } n g  } | d k r d | k r | j j d d g  t St Sn t Sd S(   s  
        Check if the channel should close or not.

        @param request: The request most recently received over this channel
            against which checks will be made to determine if this connection
            can remain open after a matching response is returned.

        @type version: C{bytes}
        @param version: The version of the request.

        @rtype: C{bool}
        @return: A flag which, if C{True}, indicates that this connection may
            remain open to receive another request; if C{False}, the connection
            must be closed in order to indicate the completion of the response
            to C{request}.
        t
   connectioni    R   s   HTTP/1.1R  N(   R  R*  R   R   R  R  R   R  (   R   R  R   R  t   tt   tokens(    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyR    s    /c         C`  s|   | |  j  d k r t  n  |  j  d =|  j rk |  j  rL |  j  d j   qx |  j rx |  j |  j  qx n |  j j   d S(   sC   
        Called by first request in queue when it is done.
        i    N(   R  Ru   R  R%  R  R  R   R>  (   R   R  (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyR    s     	
			c         C`  s4   t  j d t |  j j     t j j |   d  S(   Ns   Timing out client: %s(   R]   R\  R   R   R6  R[   t   TimeoutMixint   timeoutConnection(   R   (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyR    s     c         C`  s2   |  j  d   x |  j D] } | j |  q Wd  S(   N(   R  R   R  R   (   R   R   R  (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyR     s    N(   R   R   R   R  R   R  R  R  R   t   _HTTPChannel__contentR:   R  R  R  R   R   R   R  R  R  R  R  R  R  R  R   (    (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyR<   3  s,   			/		)					,		c           B`  sn   e  Z d  Z e Z d Z d Z d d d  Z d   Z	 d   Z
 d   Z d   Z d   Z d	   Z d
   Z RS(   sM  
    Factory for HTTP server.

    @ivar _logDateTime: A cached datetime string for log messages, updated by
        C{_logDateTimeCall}.
    @type _logDateTime: C{str}

    @ivar _logDateTimeCall: A delayed call for the next update to the cached
        log datetime string.
    @type _logDateTimeCall: L{IDelayedCall} provided
    i<   i   c         C`  sI   | d  k	 r! t j j |  } n  | |  _ | |  _ d  |  _ d  |  _ d  S(   N(   R   t   osRz   t   abspatht   logPathR  t   _logDateTimet   _logDateTimeCall(   R   R  t   timeout(    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyR   5  s    			c         C`  s(   t    |  _ t j d |  j  |  _ d S(   sY   
        Update log datetime periodically, so we aren't always recalculating it.
        i   N(   R1   R  RW   t	   callLatert   _updateLogDateTimeR  (   R   (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyR  @  s    c         C`  s%   t  j j |  |  } |  j | _ | S(   N(   RX   t   ServerFactoryt   buildProtocolR  (   R   t   addrt   p(    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyR  H  s    c         C`  sM   |  j  d k r |  j   n  |  j r= |  j |  j  |  _ n t j |  _ d S(   s6   
        Set up request logging if necessary.
        N(   R  R   R  R  t   _openLogFilet   logFileR]   t   logfile(   R   (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyt   startFactoryP  s
    	c         C`  su   t  |  d  r: |  j t j k r1 |  j j   n  |  ` n  |  j d  k	 rq |  j j   rq |  j j   d  |  _ n  d  S(   NR  (	   RS  R  R]   R  R  R  R   t   activet   cancel(   R   (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyt   stopFactory]  s    	c         C`  s   t  | d d  } | S(   sM   
        Override in subclasses, e.g. to use twisted.python.logfile.
        t   ai   (   t   open(   R   Rz   t   f(    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyR  h  s    c         C`  sn   y t  |  } Wn t k
 r# n Xt |  } | d d k rc | d d !j d d  j d d  S| d d !S(   Ni    t   'i   it   "s   \"s   \'(   RU   t   UnicodeErrort   reprR   (   R   R   t   r(    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyt   _escapeo  s    #c         C`  s   t  |  d  r d | j   |  j d |  j | j  |  j | j  |  j | j  f | j | j pg d |  j | j	 d  p d  |  j | j	 d  p d  f } |  j
 j |  n  d S(   s[   
        Log a request's result to the logfile, by default in combined log format.
        R  s   %s - - %s "%s" %d %s "%s" "%s"
s   %s %s %sR   t   referers
   user-agentN(   RS  R  R  R  R4  R  R5  RX  R`  RK  R  R   (   R   R  RL   (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyR]   {  s    	"Ni  i  i  i  (   R   R   R   R<   RX   R   R  R  R   R  R  R  R  R  R  R]   (    (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyR=   "  s   						(   R   t
   __future__R    R   t   __all__R&  R  R  RK   R  Rm  R   R   R  R  t   ioR>   R   R.   R?   RB   Rv   t   urllibR@   RA   RO   t   ImportErrort   urllib.parseRE   RC   t   zope.interfaceRP   t   twisted.python.compatRQ   RR   RS   RT   RU   t   twisted.internetRV   RW   RX   RY   t   twisted.internet.deferRZ   t   twisted.protocolsR[   R\   t   twisted.pythonR]   t   twisted.web.http_headersR^   R_   t   twisted.web._responsesR   R   R   R   R   R   R   R	   R
   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R    R!   R"   R#   R$   R%   R&   R'   R(   R)   R*   R+   R,   R   Rh  t   longt   protocol_versionR-   t	   responsesR   R   R   R   R   R   R   R/   R0   R1   R2   R3   R4   R5   R6   R7   t   LineReceiverR8   R9   t	   IConsumerR:   t	   ExceptionR  R;   R  t   objectR  R  R  R<   R  R=   (    (    (    sB   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/http.pyt   <module>   s   				(" 	%			8			"   ;
K}