
4!Rc           @`  s  d  Z  d d l m Z m Z d d l Z d d l Z y6 d d l m Z m Z m	 Z	 d d l
 m Z m Z WnL e k
 r d d l m Z m Z m Z m	 Z	 d d l m Z d   Z n Xd d l Z d d	 l m Z d d
 l 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  m! Z! d d l" 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, d d l- m. Z. m/ Z/ m0 Z0 m1 Z1 d d l2 m3 Z3 d e, j4 f d     YZ5 d e j6 f d     YZ7 d e7 f d     YZ8 d e j9 f d     YZ: d e: f d      YZ; d! e< f d"     YZ= d#   Z> d d$  Z@ d d%  ZA d d&  ZB d d' lC mD ZD e sd d( lE mF ZF mG ZG mH ZH d d) lE mI ZI mJ ZJ d d* lE mK ZK mL ZL d d+ lE mM ZM mN ZN mO ZO n  y d d, lP mQ ZQ Wn' e k
 rOd- e< f d.     YZR n Xd- eQ f d/     YZR d0 e< f d1     YZS e e0  d2 e< f d3     Y ZT d4 e jU f d5     YZV d6 e< f d7     YZW d8 e< f d9     YZX d: e< f d;     YZY e e/  d< eY f d=     Y ZZ e e/  d> eY f d?     Y Z[ d@ e< f dA     YZ\ dB e< f dC     YZ] e e/  dD e< f dE     Y Z^ dF e+ e1  f dG     YZ_ dH e+ e#  f dI     YZ` e e/  dJ e< f dK     Y Za e e/  dL e< f dM     Y Zb dN eb f dO     YZc dP e jd f dQ     YZe dR   Zf d d d d d dS dT dU dV dW d< dD d> dJ dF dL d8 dX dN g Zg d S(Y   s   
HTTP client.
i    (   t   divisiont   absolute_importN(   t
   urlunparset   urljoint	   urldefrag(   t	   splithostt	   splittype(   R   R   R   R   (   R   c         C`  s;   t  t g  |  D] } | j d  ^ q   } | j d  S(   Nt   charmap(   t   _urlunparset   tuplet   decodet   encode(   t   partst   pt   result(    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR      s    .(   t   implementer(   t   _PY3t   nativeStringt
   intToBytes(   t   log(   t   Failure(   t   http(   t   defert   protocolt   taskt   reactor(   t	   IProtocol(   t   TCP4ClientEndpointt   SSL4ClientEndpoint(   t   failure(   t   InsensitiveDict(   t   proxyForInterface(   t   error(   t   UNKNOWN_LENGTHt   IAgentt   IBodyProducert	   IResponse(   t   Headerst   PartialDownloadErrorc           B`  s   e  Z d  Z RS(   s   
    Page was only partially downloaded, we got disconnected in middle.

    @ivar response: All of the response body which was downloaded.
    (   t   __name__t
   __module__t   __doc__(    (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR&   *   s   t   HTTPPageGetterc           B`  s   e  Z d  Z d Z e Z d Z e 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 RS(   s  
    Gets a resource via HTTP, then quits.

    Typically used with L{HTTPClientFactory}.  Note that this class does not, by
    itself, do anything with the response.  If you want to download a resource
    into a file, use L{HTTPPageDownloader} instead.

    @ivar _completelyDone: A boolean indicating whether any further requests are
        necessary after this one completes in order to provide a result to
        C{self.factory.deferred}.  If it is C{False}, then a redirect is going
        to be followed.  Otherwise, this protocol's connection is the last one
        before firing the result Deferred.  This is used to make sure the result
        Deferred is only fired after the connection is cleaned up.
    i    t   hosts
   user-agentt   cookies   content-lengthc   	      C`  s@  t  |  j d d  } |  j | |  j j  |  j j d k rr |  j j d k rr |  j j d t |  j j  } nS |  j j d k r |  j j d k r |  j j d t |  j j  } n |  j j } |  j d |  j j	 j
 d	 |   |  j d
 |  j j  t  |  j d d   } | d  k	 r=|  j d t t |    n  g  } xj |  j j	 j   D]V \ } } | j   |  j k r|  j | |  n  | j   d k rV| j |  qVqVWx5 |  j j j   D]! \ } } | j | d |  qW| r
|  j d d j |   n  |  j   i  |  _	 | d  k	 r<|  j j |  n  d  S(   Nt   methodt   GETR   iP   t   :t   httpsi  t   HostR+   s
   User-Agentt   postdatas   Content-LengthR,   t   =t   Cookies   ; (   t   getattrt   factoryt   sendCommandt   patht   schemet   portR+   R   t
   sendHeadert   headerst   gett   agentt   Nonet   lent   itemst   lowert   _specialHeaderst   appendt   cookiest   joint
   endHeaderst	   transportt   write(	   t   selfR-   R+   t   datat
   cookieDatat   keyt   valueR,   t   cookval(    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyt   connectionMadeJ   s4    $#$#"
	c         C`  s2   | j    } |  j j | g   } | j |  d S(   s(  
        Called every time a header is received. Stores the header information
        as key-value pairs in the C{headers} attribute.

        @type key: C{str}
        @param key: An HTTP header field name.

        @type value: C{str}
        @param value: An HTTP header field value.
        N(   RB   R<   t
   setdefaultRD   (   RJ   RM   RN   t   l(    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyt   handleHeaderj   s    c         C`  s7   | | | |  _  |  _ |  _ |  j j | | |  d  S(   N(   t   versiont   statust   messageR6   t	   gotStatus(   RJ   RT   RU   RV   (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyt   handleStatusy   s    c         C`  s@   |  j  j |  j  t |  d t |  j  |  j  } |   d  S(   Nt   handleStatus_(   R6   t
   gotHeadersR<   R5   R   RU   t   handleStatusDefault(   RJ   t   m(    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyt   handleEndHeaders}   s    c         C`  s   d  S(   N(    (   RJ   (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyt   handleStatus_200   s    c         C`  s
   |  j    S(   N(   R^   (   RJ   (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyt   <lambda>   s    c         C`  s
   |  j    S(   N(   R^   (   RJ   (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR_      s    c         C`  s   d |  _  d  S(   Ni   (   t   failed(   RJ   (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR[      s    c         C`  s  |  j  j d  } | s& |  j   d  S| d } |  j rQ|  j j d 7_ |  j j |  j j k r t j |  j	 d d | } |  j j
 t j |   t |  _ |  j j   d  St |  _ |  j j |  |  j j d k r&d d l m } | j   } t j t |  j j  |  j j |  j |  qt j t |  j j  |  j j |  j  n; |  j   |  j j
 t j t j |  j	 |  j d |   t |  _ |  j j   d  S(   Nt   locationi    i   s   Infinite redirection detectedR0   (   t   ssl(    R<   R=   R[   t   followRedirectR6   t   _redirectCountt   redirectLimitR    t   InfiniteRedirectionRU   t   noPageR   R   t   Truet	   quietLossRH   t   loseConnectiont   Falset   _completelyDonet   setURLR9   t   twisted.internetRb   t   ClientContextFactoryR   t
   connectSSLR   R+   R:   t
   connectTCPt   PageRedirectRV   (   RJ   RR   t   urlt   errRb   t   contextFactory(    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyt   handleStatus_301   sD    

						
		c         C`  s$   |  j  r |  j   n
 |  j   d  S(   N(   t   afterFoundGett   handleStatus_303Rv   (   RJ   (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyt   handleStatus_302   s    	c         C`  s   d |  j  _ |  j   d  S(   NR.   (   R6   R-   Rv   (   RJ   (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyRx      s    c         C`  sR   |  j  s/ t j j |  |  |  j j |  n  |  j rN |  j j j d  n  d S(   s   
        When the connection used to issue the HTTP request is closed, notify the
        factory if we have not already, so it can produce a result.
        N(
   Ri   R   t
   HTTPClientt   connectionLostR6   Rg   Rl   t   _disconnectedDeferredt   callbackR?   (   RJ   t   reason(    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR{      s
    		c         C`  s   |  j  r d  S|  j rG |  j j t j t j |  j |  j	 |    n  |  j j
 d k rl |  j j d  n\ |  j d  k r |  j d k r |  j j t j t |  j |  j	 |    n |  j j |  |  j j   d  S(   Nt   HEADt    i    (   Ri   R`   R6   Rg   R   R   R    t   ErrorRU   RV   R-   t   paget   lengthR?   R&   RH   Rj   (   RJ   t   response(    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyt   handleResponse   s    			c         C`  sI   t  |  _ |  j j   |  j j t j d |  j j |  j j	 f   d  S(   Ns'   Getting %s took longer than %s seconds.(
   Rh   Ri   RH   Rj   R6   Rg   R   t   TimeoutErrorRs   t   timeout(   RJ   (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR      s    	(   s   hosts
   user-agents   cookies   content-length(   R'   R(   R)   Ri   Rh   Rc   R`   Rl   t   setRC   RP   RS   RX   R]   R^   t   handleStatus_201t   handleStatus_202R[   Rv   Ry   Rx   R{   R   R   (    (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR*   2   s(   	 								(				t   HTTPPageDownloaderc           B`  s5   e  Z d  Z d  d  Z d   Z d   Z d   Z RS(   i    c         C`  s*   t  j |   d |  _ |  j j |  d  S(   Ni   (   R*   R^   t   transmittingPageR6   t	   pageStart(   RJ   t   partialContent(    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR^      s    	c         C`  s   |  j  d d  d  S(   NR   i   (   R^   (   RJ   (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyt   handleStatus_206   s    c         C`  s    |  j  r |  j j |  n  d  S(   N(   R   R6   t   pagePart(   RJ   RK   (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyt   handleResponsePart   s    	c         C`  s   |  j  r7 d |  _ |  j j t j t |  j    n  |  j rY |  j j   d |  _ n  |  j	 r |  j j t j t
 j |  j |  j d     |  j j   n  d  S(   Ni    (   R   R   R6   Rg   R   R   R&   RU   t   pageEndR`   R    R   RV   R?   RH   Rj   (   RJ   (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyt   handleResponseEnd   s    						(   R'   R(   R   R^   R   R   R   (    (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR      s
   		t   HTTPClientFactoryc        
   B`  s   e  Z d  Z e Z d Z d Z d Z d Z	 d Z
 d d d d d d e d e d 	 Z d   Z d   Z d	   Z d
   Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   s  Download a given URL.

    @type deferred: Deferred
    @ivar deferred: A Deferred that will fire when the content has
          been retrieved. Once this is fired, the ivars `status', `version',
          and `message' will be set.

    @type status: bytes
    @ivar status: The status of the response.

    @type version: bytes
    @ivar version: The version of the response.

    @type message: bytes
    @ivar message: The text message returned with the status.

    @type response_headers: dict
    @ivar response_headers: The headers that were specified in the
          response from the server.

    @type method: bytes
    @ivar method: The HTTP method to use in the request.  This should be one of
        OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, or CONNECT (case
        matters).  Other values may be specified if the server being contacted
        supports them.

    @type redirectLimit: int
    @ivar redirectLimit: The maximum number of HTTP redirects that can occur
          before it is assumed that the redirection is endless.

    @type afterFoundGet: C{bool}
    @ivar afterFoundGet: Deviate from the HTTP 1.1 RFC by handling redirects
        the same way as most web browsers; if the request method is POST and a
        302 status is encountered, the redirect is followed with a GET method

    @type _redirectCount: int
    @ivar _redirectCount: The current number of HTTP redirects encountered.

    @ivar _disconnectedDeferred: A L{Deferred} which only fires after the last
        connection associated with the request (redirects may cause multiple
        connections to be required) has closed.  The result Deferred will only
        fire after this Deferred, so that callers can be assured that there are
        no more event sources in the reactor once they get the result.
    R   R.   s   Twisted PageGetteri    i   c         C`  s%  | |  _  |	 |  _ d |  _ | |  _ | |  _ |
 |  _ | d  k rK i  } n  | |  _ | d  k	 rr t |  |  _	 n t   |  _	 | d  k	 r |  j	 j
 d t t |    |  j	 j
 d d  n  | |  _ | |  _ |  j |  d |  _ t j   |  _ t j   |  _ |  j j |  j  d  |  _ d  S(   Ni    s   Content-Lengtht
   connectiont   closei   (   Rc   Re   Rd   R   R>   Rw   R?   RE   R   R<   RQ   R   R@   R2   R-   Rm   t   waitingR   t   DeferredR|   t   deferredt   addBotht   _waitForDisconnectt   response_headers(   RJ   Rs   R-   R2   R<   R>   R   RE   Rc   Re   Rw   (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyt   __init__B  s0    											c         `  s    |  j  j   f d    |  j  S(   s   
        Chain onto the _disconnectedDeferred, preserving C{passthrough}, so that
        the result is only available after the associated connection has been
        closed.
        c         `  s     S(   N(    (   t   ignored(   t   passthrough(    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR_   l  s    (   R|   t   addCallback(   RJ   R   (    (   R   sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR   f  s    c         C`  s   d |  j  j |  j f S(   Ns   <%s: %s>(   t	   __class__R'   Rs   (   RJ   (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyt   __repr__p  s    c         C`  sa   | |  _  t j |  } | j rQ | j rQ | j |  _ | j |  _ | j |  _ n  | j |  _ d  S(   N(   Rs   t   _URIt	   fromBytesR9   R+   R:   t
   originFormR8   (   RJ   Rs   t   uri(    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyRm   s  s    	c         C`  sk   t  j j |  |  } |  j | _ |  j | _ |  j rg t j |  j | j  } |  j j	 |  j
 |  n  | S(   N(   R   t   ClientFactoryt   buildProtocolRc   Rw   R   R   t	   callLaterR   R   t   _cancelTimeout(   RJ   t   addrR   t   timeoutCall(    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR   |  s    	c         C`  s   | j    r | j   n  | S(   N(   t   activet   cancel(   RJ   R   R   (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR     s    c         C`  s   | |  _  d | k r xi | d D]Z } | j d  } | d } | j   | j d d  \ } } | j   |  j | j   <q  Wn  d  S(   Ns
   set-cookiet   ;i    R3   i   (   R   t   splitt   lstripRE   (   RJ   R<   R,   t	   cookpartst   cookt   kt   v(    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyRZ     s    	

c         C`  s!   | | | |  _  |  _ |  _ d  S(   N(   RT   RU   RV   (   RJ   RT   RU   RV   (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyRW     s    c         C`  s)   |  j  r% d |  _  |  j j |  n  d  S(   Ni    (   R   R   R}   (   RJ   R   (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR     s    		c         C`  s)   |  j  r% d |  _  |  j j |  n  d  S(   Ni    (   R   R   t   errback(   RJ   R~   (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyRg     s    		c         C`  s9   |  j  r5 d |  _  |  j j d  |  j j |  n  d S(   s   
        When a connection attempt fails, the request cannot be issued.  If no
        result has yet been provided to the result Deferred, provide the
        connection failure reason as an error result.
        i    N(   R   R|   R}   R?   R   R   (   RJ   t   _R~   (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyt   clientConnectionFailed  s    		N(   R'   R(   R)   R*   R   R?   Rs   R9   R+   R:   R8   Rh   Rk   R   R   R   Rm   R   R   RZ   RW   R   Rg   R   (    (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR     s*   ,		!	
							
			t   HTTPDownloaderc           B`  sw   e  Z d  Z e Z d Z d d d d d d d d d e d 
 Z d   Z	 d   Z
 d	   Z d
   Z d   Z d   Z RS(   s   Download to a file.R.   s   Twisted clienti    i   i   c         C`  s   d |  _  t | t j  r | |  _ d  |  _ | r t j j	 |  j  r t j j
 |  j  } | r | |  _  | d  k r i  } n  d | | d <q q n	 | |  _ t j |  | d | d | d | d | d | d	 |	 d
 |
 d | d | 	d  S(   Ni    s	   bytes=%d-t   rangeR-   R2   R<   R>   R   RE   Rc   Re   Rw   (   t   requestedPartialt
   isinstancet   typest   StringTypest   fileNameR?   t   filet   osR8   t   existst   getsizeR   R   (   RJ   Rs   t
   fileOrNameR-   R2   R<   R>   t   supportPartialR   RE   Rc   Re   Rw   t
   fileLength(    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR     s"    						c         C`  s|   t  j |  |  |  j rx | j d d   } | s> d |  _ d  St j | d  \ } } } | |  j k rx d |  _ qx n  d  S(   Ns   content-rangei    (   R   RZ   R   R=   R?   R   t   parseContentRange(   RJ   R<   t   contentRanget   startt   endt
   realLength(    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyRZ     s    		c         C`  sA   | r+ t  |  j d  } | j d d  n t  |  j d  } | S(   Ns   rb+i    i   t   wb(   t   openR   t   seek(   RJ   R   R   (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyt   openFile  s
    c         C`  s{   | r |  j  r t d   n  |  j rw y" |  j sI |  j |  |  _ n  Wqw t k
 rs |  j j t j	    qw Xn  d S(   s   Called on page download start.

        @param partialContent: tells us if the download is partial download we requested.
        s?   we shouldn't get partial content response if we didn't want it!N(
   R   t
   ValueErrorR   R   R   t   IOErrorR   R   R   R   (   RJ   R   (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR     s    		c         C`  sX   |  j  s d  Sy |  j  j |  Wn0 t k
 rS d  |  _  |  j j t j    n Xd  S(   N(   R   RI   R   R?   R   R   R   R   (   RJ   RK   (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR     s    		c         C`  s`   |  j  r\ d |  _  |  j rI y |  j j   WqI t j d d  qI Xn  |  j j |  n  d S(   sk   
        Close the storage file and errback the waiting L{Deferred} with the
        given reason.
        i    s!   Error closing HTTPDownloader fileN(   R   R   R   R   Rt   R?   R   R   (   RJ   R~   (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyRg     s    			c         C`  si   d |  _  |  j s d  Sy |  j j   Wn( t k
 rQ |  j j t j    d  SX|  j j |  j	  d  S(   Ni    (
   R   R   R   R   R   R   R   R   R}   RN   (   RJ   (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR     s    		N(   R'   R(   R)   R   R   R?   RN   Rk   R   RZ   R   R   R   Rg   R   (    (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR     s   							R   c           B`  sA   e  Z d  Z d   Z e d d   Z d   Z e d    Z	 RS(   sd   
    A URI object.

    @see: U{https://tools.ietf.org/html/draft-ietf-httpbis-p1-messaging-21}
    c	   	      C`  sL   | |  _  | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ d S(   sV  
        @type scheme: L{bytes}
        @param scheme: URI scheme specifier.

        @type netloc: L{bytes}
        @param netloc: Network location component.

        @type host: L{bytes}
        @param host: Host name.

        @type port: L{int}
        @param port: Port number.

        @type path: L{bytes}
        @param path: Hierarchical path.

        @type params: L{bytes}
        @param params: Parameters for last path segment.

        @type query: L{bytes}
        @param query: Query string.

        @type fragment: L{bytes}
        @param fragment: Fragment identifier.
        N(   R9   t   netlocR+   R:   R8   t   paramst   queryt   fragment(	   RJ   R9   R   R+   R:   R8   R   R   R   (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR   !  s    							c      	   C`  s   | j    } t j |  \ } } } } } } | d k rW | d k rN d } qW d } n  | | }	 }
 d |	 k r |	 j d  \ }	 }
 y t |
  }
 Wq t k
 r | }
 q Xn  |  | | |	 |
 | | | |  S(   sP  
        Parse the given URI into a L{_URI}.

        @type uri: C{bytes}
        @param uri: URI to parse.

        @type defaultPort: C{int} or C{None}
        @param defaultPort: An alternate value to use as the port if the URI
            does not include one.

        @rtype: L{_URI}
        @return: Parsed URI instance.
        R0   i  iP   R/   N(   t   stripR   t   urlparseR?   R   t   intR   (   t   clsR   t   defaultPortR9   R   R8   R   R   R   R+   R:   (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR   F  s    !		c         C`  s.   t  |  j |  j |  j |  j |  j |  j f  S(   s   
        Assemble the individual parts of the I{URI} into a fully formed I{URI}.

        @rtype: C{bytes}
        @return: A fully formed I{URI}.
        (   R   R9   R   R8   R   R   R   (   RJ   (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyt   toBytesi  s    c         C`  s@   t  d d |  j |  j |  j d f  } | d k r< d } n  | S(   s   
        The absolute I{URI} path including I{URI} parameters, query string and
        fragment identifier.

        @see: U{https://tools.ietf.org/html/draft-ietf-httpbis-p1-messaging-21#section-5.3}
        R   t   /(   R   R8   R   R   (   RJ   R8   (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR   u  s
    
$	N(
   R'   R(   R)   R   t   classmethodR?   R   R   t   propertyR   (    (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR     s   	%"	c         C`  sD   t  |   \ }  } t  t |  |   \ } } t | d | p? |  S(   s  
    Construct a full ("absolute") URL by combining a "base URL" with another
    URL. Informally, this uses components of the base URL, in particular the
    addressing scheme, the network location and (part of) the path, to provide
    missing components in the relative URL.

    Additionally, the fragment identifier is preserved according to the HTTP
    1.1 bis draft.

    @type base: C{bytes}
    @param base: Base URL.

    @type url: C{bytes}
    @param url: URL to combine with C{base}.

    @return: An absolute URL resulting from the combination of C{base} and
        C{url}.

    @see: L{urlparse.urljoin}

    @see: U{https://tools.ietf.org/html/draft-ietf-httpbis-p2-semantics-22#section-7.1.2}
    t   #(   R   R   (   t   baseRs   t   baseFragt   urlFrag(    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyt   _urljoin  s    c         O`  s   t  j |   } | |  | |  } | j d k r d d l m } | d k r[ | j   } n  t j t	 | j
  | j | |  n t j t	 | j
  | j |  | S(   s  
    Create and connect an HTTP page getting factory.

    Any additional positional or keyword arguments are used when calling
    C{factoryFactory}.

    @param factoryFactory: Factory factory that is called with C{url}, C{args}
        and C{kwargs} to produce the getter

    @param contextFactory: Context factory to use when creating a secure
        connection, defaulting to C{None}

    @return: The factory created by C{factoryFactory}
    R0   i    (   Rb   N(   R   R   R9   Rn   Rb   R?   Ro   R   Rp   R   R+   R:   Rq   (   Rs   t   factoryFactoryRu   t   argst   kwargsR   R6   Rb   (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyt   _makeGetterFactory  s    c         O`  s   t  |  t d | | | j S(   s   
    Download a web page as a string.

    Download a page. Return a deferred, which will callback with a
    page (as a string) or errback with a description of the error.

    See L{HTTPClientFactory} to see what extra arguments can be passed.
    Ru   (   R   R   R   (   Rs   Ru   R   R   (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyt   getPage  s
    	c         `  s+     f d   } t  |  | d | | | j S(   s   
    Download a web page to a file.

    @param file: path to file on filesystem, or file-like object.

    See HTTPDownloader to see what extra args can be passed.
    c         `  s   t  |    | |  S(   N(   R   (   Rs   t   at   kw(   R   (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR_     s    Ru   (   R   R   (   Rs   R   Ru   R   R   R   (    (   R   sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyt   downloadPage  s    (   t   SchemeNotSupported(   t   Requestt   Responset   HTTP11ClientProtocol(   t   ResponseDonet   ResponseFailed(   t   RequestNotSentt   RequestTransmissionFailed(   t   ResponseNeverReceivedt   PotentialDataLosst   _WrapperException(   Ro   t   WebClientContextFactoryc           B`  s   e  Z d  Z d   Z RS(   sp   
        A web context factory which doesn't work because the necessary SSL
        support is missing.
        c         C`  s   t  d   d  S(   Ns   SSL support unavailable(   t   NotImplementedError(   RJ   t   hostnameR:   (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyt
   getContext  s    (   R'   R(   R)   R   (    (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR     s   c           B`  s   e  Z d  Z d   Z RS(   sy   
        A web context factory which ignores the hostname and port and does no
        certificate verification.
        c         C`  s   t  j |   S(   N(   Ro   R   (   RJ   R   R:   (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR     s    (   R'   R(   R)   R   (    (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR     s   t   _WebToNormalContextFactoryc           B`  s    e  Z d  Z d   Z d   Z RS(   sy  
    Adapt a web context factory to a normal context factory.

    @ivar _webContext: A web context factory which accepts a hostname and port
        number to its C{getContext} method.

    @ivar _hostname: The hostname which will be passed to
        C{_webContext.getContext}.

    @ivar _port: The port number which will be passed to
        C{_webContext.getContext}.
    c         C`  s   | |  _  | |  _ | |  _ d  S(   N(   t   _webContextt	   _hostnamet   _port(   RJ   t
   webContextR   R:   (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR     s    		c         C`  s   |  j  j |  j |  j  S(   s   
        Called the wrapped web context factory's C{getContext} method with a
        hostname and port number and return the resulting context object.
        (   R   R   R   R   (   RJ   (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR     s    (   R'   R(   R)   R   R   (    (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR     s   	t   FileBodyProducerc           B`  sS   e  Z d  Z e d
 d  Z d   Z d   Z d   Z d   Z d   Z	 d	   Z
 RS(   s  
    L{FileBodyProducer} produces bytes from an input file object incrementally
    and writes them to a consumer.

    Since file-like objects cannot be read from in an event-driven manner,
    L{FileBodyProducer} uses a L{Cooperator} instance to schedule reads from
    the file.  This process is also paused and resumed based on notifications
    from the L{IConsumer} provider being written to.

    The file is closed after it has been read, or if the producer is stopped
    early.

    @ivar _inputFile: Any file-like object, bytes read from which will be
        written to a consumer.

    @ivar _cooperate: A method like L{Cooperator.cooperate} which is used to
        schedule all reads.

    @ivar _readSize: The number of bytes to read from C{_inputFile} at a time.
    i   i   c         C`  s4   | |  _  | j |  _ | |  _ |  j |  |  _ d  S(   N(   t
   _inputFilet	   cooperatet
   _cooperatet	   _readSizet   _determineLengthR   (   RJ   t	   inputFilet
   cooperatort   readSize(    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR   5  s    		c         C`  se   y | j  } | j } Wn t k
 r* t SX|   } | d t j  |   } | | t j  | | S(   s   
        Determine how many bytes can be read out of C{fObj} (assuming it is not
        modified from this point on).  If the determination cannot be made,
        return C{UNKNOWN_LENGTH}.
        i    (   R   t   tellt   AttributeErrorR!   R   t   SEEK_ENDt   SEEK_SET(   RJ   t   fObjR   R	  t   originalPositionR   (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR  <  s    			c         C`  s   |  j  j   |  j j   d S(   s   
        Permanently stop writing bytes from the file to the consumer by
        stopping the underlying L{CooperativeTask}.
        N(   R  R   t   _taskt   stop(   RJ   (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyt   stopProducingN  s    c         C`  sJ   |  j  |  j |   |  _ |  j j   } d   } | j d   |  | S(   s   
        Start a cooperative task which will read bytes from the input file and
        write them to C{consumer}.  Return a L{Deferred} which fires after all
        bytes have been written.

        @param consumer: Any L{IConsumer} provider
        c         S`  s   |  j  t j  t j   S(   N(   t   trapR   t   TaskStoppedR   R   (   R~   (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyt   maybeStoppeda  s    c         S`  s   d  S(   N(   R?   (   R   (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR_   f  s    (   R  t
   _writeloopR  t   whenDonet   addCallbacks(   RJ   t   consumert   dR  (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyt   startProducingW  s
    	c         c`  sO   xH t  rJ |  j j |  j  } | s5 |  j j   Pn  | j |  d Vq Wd S(   s   
        Return an iterator which reads one chunk of bytes from the input file
        and writes them to the consumer for each time it is iterated.
        N(   Rh   R  t   readR  R   RI   R?   (   RJ   R  t   bytes(    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR  j  s    	c         C`  s   |  j  j   d S(   s   
        Temporarily suspend copying bytes from the input file to the consumer
        by pausing the L{CooperativeTask} which drives that activity.
        N(   R  t   pause(   RJ   (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyt   pauseProducingx  s    c         C`  s   |  j  j   d S(   s   
        Undo the effects of a previous C{pauseProducing} and resume copying
        bytes to the consumer by resuming the L{CooperativeTask} which drives
        the write activity.
        N(   R  t   resume(   RJ   (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyt   resumeProducing  s    i   (   R'   R(   R)   R   R   R  R  R  R  R  R   (    (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR     s   						t   _HTTP11ClientFactoryc           B`  s    e  Z d  Z d   Z d   Z RS(   s   
    A factory for L{HTTP11ClientProtocol}, used by L{HTTPConnectionPool}.

    @ivar _quiescentCallback: The quiescent callback to be passed to protocol
        instances, used to return them to the connection pool.

    @since: 11.1
    c         C`  s   | |  _  d  S(   N(   t   _quiescentCallback(   RJ   t   quiescentCallback(    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR     s    c         C`  s   t  |  j  S(   N(   R   R"  (   RJ   R   (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR     s    (   R'   R(   R)   R   R   (    (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR!    s   	t   _RetryingHTTP11ClientProtocolc           B`  s)   e  Z d  Z d   Z d   Z d   Z RS(   s   
    A wrapper for L{HTTP11ClientProtocol} that automatically retries requests.

    @ivar _clientProtocol: The underlying L{HTTP11ClientProtocol}.

    @ivar _newConnection: A callable that creates a new connection for a
        retry.
    c         C`  s   | |  _  | |  _ d  S(   N(   t   _clientProtocolt   _newConnection(   RJ   t   clientProtocolt   newConnection(    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR     s    	c         C`  s|   | d k r t  St | t t t f  s, t  St | t  rh x* | j D] } | j t j	  rE t  SqE Wn  | d k	 rx t  St S(   sn  
        Indicate whether request should be retried.

        Only returns C{True} if method is idempotent, no response was
        received, the reason for the failed request was not due to
        user-requested cancellation, and no body was sent. The latter
        requirement may be relaxed in the future, and PUT added to approved
        method list.
        R.   R   t   OPTIONSt   DELETEt   TRACE(   s   GETs   HEADR)  R*  R+  N(   Rk   R   R   R   R   R   t   reasonst   checkR   t   CancelledErrorR?   Rh   (   RJ   R-   t	   exceptiont   bodyProducerR   (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyt   _shouldRetry  s    
c         `  s5    j  j    }    f d   } | j |  | S(   s   
        Do a request, and retry once (with a new connection) it it fails in
        a retryable manner.

        @param request: A L{Request} instance that will be requested using the
            wrapped protocol.
        c         `  sB    j    j |  j   j  r:  j   j   f d    S|  Sd  S(   Nc         `  s   |  j     S(   N(   t   request(   R   (   R2  (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR_     s    (   R1  R-   RN   R0  R&  R   (   R~   (   R2  RJ   (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR`     s
    (   R%  R2  t
   addErrback(   RJ   R2  R  R`   (    (   R2  RJ   sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR2    s    (   R'   R(   R)   R   R1  R2  (    (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR$    s   		t   HTTPConnectionPoolc           B`  s_   e  Z d  Z e Z d Z d Z e Z e d  Z	 d   Z
 d   Z d   Z d   Z d   Z RS(	   sU  
    A pool of persistent HTTP connections.

    Features:
     - Cached connections will eventually time out.
     - Limits on maximum number of persistent connections.

    Connections are stored using keys, which should be chosen such that any
    connections stored under a given key can be used interchangeably.

    Failed requests done using previously cached connections will be retried
    once if they use an idempotent method (e.g. GET), in case the HTTP server
    timed them out.

    @ivar persistent: Boolean indicating whether connections should be
        persistent. Connections are persistent by default.

    @ivar maxPersistentPerHost: The maximum number of cached persistent
        connections for a C{host:port} destination.
    @type maxPersistentPerHost: C{int}

    @ivar cachedConnectionTimeout: Number of seconds a cached persistent
        connection will stay open before disconnecting.

    @ivar retryAutomatically: C{boolean} indicating whether idempotent
        requests should be retried once if no response was received.

    @ivar _factory: The factory used to connect to the proxy.

    @ivar _connections: Map (scheme, host, port) to lists of
        L{HTTP11ClientProtocol} instances.

    @ivar _timeouts: Map L{HTTP11ClientProtocol} instances to a
        C{IDelayedCall} instance of their timeout.

    @since: 12.1
    i   i   c         C`  s(   | |  _  | |  _ i  |  _ i  |  _ d  S(   N(   t   _reactort
   persistentt   _connectionst	   _timeouts(   RJ   R   R6  (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR     s    			c         `  s    j  j   } x | r | j d  }  j | j    j | =| j d k r  j r     f d   } t | |  } n  t j	 |  Sq W j
     S(   s  
        Supply a connection, newly created or retrieved from the pool, to be
        used for one HTTP request.

        The connection will remain out of the pool (not available to be
        returned from future calls to this method) until one HTTP request has
        been completed over it.

        Afterwards, if the connection is still open, it will automatically be
        added to the pool.

        @param key: A unique key identifying connections that can be used
            interchangeably.

        @param endpoint: An endpoint that can be used to open a new connection
            if no cached connection is available.

        @return: A C{Deferred} that will fire with a L{HTTP11ClientProtocol}
           (or a wrapper) that can be used to send a single HTTP request.
        i    t	   QUIESCENTc           `  s    j      S(   N(   R&  (    (   t   endpointRM   RJ   (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR_   *  s    (   R7  R=   t   popR8  R   t   statet   retryAutomaticallyR$  R   t   succeedR&  (   RJ   RM   R:  t   connectionsR   R(  (    (   R:  RM   RJ   sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyt   getConnection  s    	
	c         `  s.      f d   }  j  |  } | j |  S(   sv   
        Create a new connection.

        This implements the new connection code path for L{getConnection}.
        c         `  s    j    |   d  S(   N(   t   _putConnection(   R   (   RM   RJ   (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR#  8  s    (   t   _factoryt   connect(   RJ   RM   R:  R#  R6   (    (   RM   RJ   sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR&  2  s    c         C`  s/   | j  j   |  j | j |  |  j | =d S(   sG   
        Remove a connection from the cache and disconnect it.
        N(   RH   Rj   R7  t   removeR8  (   RJ   RM   R   (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyt   _removeConnection>  s    c         C`  s   | j  d k r7 y t d   Wn t j   n Xd S|  j j | g   } t |  |  j k r | j d  } | j	 j
   |  j | j   |  j | =n  | j |  |  j j |  j |  j | |  } | |  j | <d S(   s   
        Return a persistent connection to the pool. This will be called by
        L{HTTP11ClientProtocol} when the connection becomes quiescent.
        R9  s5   BUG: Non-quiescent protocol added to connection pool.Ni    (   R<  t   RuntimeErrorR   Rt   R7  RQ   R@   t   maxPersistentPerHostR;  RH   Rj   R8  R   RD   R5  R   t   cachedConnectionTimeoutRE  (   RJ   RM   R   R?  t   droppedt   cid(    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyRA  G  s$    c         C`  s   g  } x; |  j  j   D]* } x! | D] } | j | j    q# Wq Wi  |  _  x! |  j j   D] } | j   q] Wi  |  _ t j |  j	 d    S(   s   
        Close all persistent connections and remove them from the pool.

        @return: L{defer.Deferred} that fires when all connections have been
            closed.
        c         S`  s   d  S(   N(   R?   (   t   ign(    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR_   p  s    (
   R7  t
   itervaluesRD   t   abortR8  t   valuesR   R   t   gatherResultsR   (   RJ   t   resultst	   protocolsR   t   dc(    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyt   closeCachedConnectionsa  s    		(   R'   R(   R)   R!  RB  RG  RH  Rh   R=  R   R@  R&  RE  RA  RS  (    (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR4    s   %	&				t
   _AgentBasec           B`  s)   e  Z d  Z d   Z d   Z d   Z RS(   s  
    Base class offering common facilities for L{Agent}-type classes.

    @ivar _reactor: The C{IReactorTime} implementation which will be used by
        the pool, and perhaps by subclasses as well.

    @ivar _pool: The L{HTTPConnectionPool} used to manage HTTP connections.
    c         C`  s4   | d  k r t | t  } n  | |  _ | |  _ d  S(   N(   R?   R4  Rk   R5  t   _pool(   RJ   R   t   pool(    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR   ~  s    	c         C`  s*   | | f d d f k r | Sd | | f S(   s   
        Compute the string to use for the value of the I{Host} header, based on
        the given scheme, host name, and port number.
        R   iP   R0   i  s   %s:%d(   s   httpiP   (   s   httpsi  (    (   RJ   R9   R+   R:   (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyt   _computeHostValue  s    c   
      `  s    d k r t    n   j d  s^  j     j d  j  j  j  j   n   j	 j
 | |  }        f d   }	 | j |	  | S(   sk   
        Issue a new request, given the endpoint and the path sent as part of
        the request.
        R+   c      
   `  s1   |  j  t j      d  j j d   S(   NR6  t	   parsedURI(   R2  R   t
   _constructRU  R6  (   t   proto(   R0  R<   R-   RX  t   requestPathRJ   (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyt   cbConnected  s    N(   R?   R%   t	   hasHeadert   copyt   addRawHeaderRW  R9   R+   R:   RU  R@  R   (
   RJ   RM   R:  R-   RX  R<   R0  R[  R  R\  (    (   R0  R<   R-   RX  R[  RJ   sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyt   _requestWithEndpoint  s    (   R'   R(   R)   R   RW  R`  (    (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyRT  t  s   		
t   Agentc           B`  sG   e  Z d  Z e   d d d d  Z d   Z d   Z d d d  Z RS(   s  
    L{Agent} is a very basic HTTP client.  It supports I{HTTP} and I{HTTPS}
    scheme URIs (but performs no certificate checking by default).

    @param pool: A L{HTTPConnectionPool} instance, or C{None}, in which case a
        non-persistent L{HTTPConnectionPool} instance will be created.

    @ivar _contextFactory: A web context factory which will be used to create
        SSL context objects for any SSL connections the agent needs to make.

    @ivar _connectTimeout: If not C{None}, the timeout passed to C{connectTCP}
        or C{connectSSL} for specifying the connection timeout.

    @ivar _bindAddress: If not C{None}, the address passed to C{connectTCP} or
        C{connectSSL} for specifying the local address to bind to.

    @since: 9.0
    c         C`  s2   t  j |  | |  | |  _ | |  _ | |  _ d  S(   N(   RT  R   t   _contextFactoryt   _connectTimeoutt   _bindAddress(   RJ   R   Ru   t   connectTimeoutt   bindAddressRV  (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR     s    		c         C`  s   t  |  j | |  S(   s	  
        Create and return a normal context factory wrapped around
        C{self._contextFactory} in such a way that C{self._contextFactory} will
        have the host and port information passed to it.

        @param host: A C{str} giving the hostname which will be connected to in
            order to issue a request.

        @param port: An C{int} giving the port number the connection will be
            on.

        @return: A context factory suitable to be passed to
            C{reactor.connectSSL}.
        (   R   Rb  (   RJ   R+   R:   (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyt   _wrapContextFactory  s    c         C`  s   i  } |  j  d k	 r% |  j  | d <n  |  j | d <| d k rT t |  j | | |  S| d k r t |  j | | |  j | |  |  St d | f   d S(   s?  
        Get an endpoint for the given host and port, using a transport
        selected based on scheme.

        @param scheme: A string like C{'http'} or C{'https'} (the only two
            supported values) to use to determine how to establish the
            connection.

        @param host: A C{str} giving the hostname which will be connected to in
            order to issue a request.

        @param port: An C{int} giving the port number the connection will be
            on.

        @return: An endpoint which can be used to connect to given address.
        R   Rf  R   R0   s   Unsupported scheme: %rN(   Rc  R?   Rd  R   R5  R   Rg  R   (   RJ   R9   R+   R:   R   (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyt   _getEndpoint  s    c         C`  s   t  j |  } y" |  j | j | j | j  } Wn t k
 rQ t j t	    SX| j | j | j f } |  j
 | | | | | | | j  S(   s!  
        Issue a request to the server indicated by the given C{uri}.

        An existing connection from the connection pool may be used or a new one may be created.

        I{HTTP} and I{HTTPS} schemes are supported in C{uri}.

        @see: L{twisted.web.iweb.IAgent.request}
        (   R   R   Rh  R9   R+   R:   R   R   t   failR   R`  R   (   RJ   R-   R   R<   R0  RX  R:  RM   (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR2    s    
N(	   R'   R(   R)   R   R?   R   Rg  Rh  R2  (    (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyRa    s   		t
   ProxyAgentc           B`  s,   e  Z d  Z d d d  Z d d d  Z RS(   s   
    An HTTP agent able to cross HTTP proxies.

    @ivar _proxyEndpoint: The endpoint used to connect to the proxy.

    @since: 11.1
    c         C`  s?   | d  k r d d l m } n  t j |  | |  | |  _ d  S(   Ni    (   R   (   R?   Rn   R   RT  R   t   _proxyEndpoint(   RJ   R:  R   RV  (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR     s    c         C`  s:   d |  j  f } |  j | |  j  | t j |  | | |  S(   s?   
        Issue a new request via the configured proxy.
        s
   http-proxy(   Rk  R`  R   R   (   RJ   R-   R   R<   R0  RM   (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR2     s    N(   R'   R(   R)   R?   R   R2  (    (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyRj    s   t   _FakeUrllib2Requestc           B`  sY   e  Z d  Z d   Z d   Z d   Z d   Z d	 d  Z d   Z	 d   Z
 d   Z RS(
   s  
    A fake C{urllib2.Request} object for C{cookielib} to work with.

    @see: U{http://docs.python.org/library/urllib2.html#request-objects}

    @type uri: C{str}
    @ivar uri: Request URI.

    @type headers: L{twisted.web.http_headers.Headers}
    @ivar headers: Request headers.

    @type type: C{str}
    @ivar type: The scheme of the URI.

    @type host: C{str}
    @ivar host: The host[:port] of the URI.

    @since: 11.1
    c         C`  sF   | |  _  t   |  _ t |  j   \ |  _ } t |  \ |  _ } d  S(   N(   R   R%   R<   R   t   typeR   R+   (   RJ   R   t   rest(    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR   E  s    	c         C`  s   |  j  j |  S(   N(   R<   R]  (   RJ   t   header(    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyt
   has_headerL  s    c         C`  s   |  j  j | |  d  S(   N(   R<   R_  (   RJ   t   nameRN   (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyt   add_unredirected_headerP  s    c         C`  s   |  j  S(   N(   R   (   RJ   (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyt   get_full_urlT  s    c         C`  s-   |  j  j | |  } | d  k	 r) | d Sd  S(   Ni    (   R<   t   getRawHeadersR?   (   RJ   Rq  t   defaultR<   (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyt
   get_headerX  s    c         C`  s   |  j  S(   N(   R+   (   RJ   (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyt   get_host_  s    c         C`  s   |  j  S(   N(   Rm  (   RJ   (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyt   get_typec  s    c         C`  s   t  S(   N(   Rk   (   RJ   (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyt   is_unverifiableg  s    N(   R'   R(   R)   R   Rp  Rr  Rs  R?   Rv  Rw  Rx  Ry  (    (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyRl  1  s   						t   _FakeUrllib2Responsec           B`  s    e  Z d  Z d   Z d   Z RS(   s   
    A fake C{urllib2.Response} object for C{cookielib} to work with.

    @type response: C{twisted.web.iweb.IResponse}
    @ivar response: Underlying Twisted Web response.

    @since: 11.1
    c         C`  s   | |  _  d  S(   N(   R   (   RJ   R   (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR   v  s    c         `  s#   d t  f   f d     Y} |   S(   Nt   _Metac           `  s   e  Z   f d    Z RS(   c         `  s     j  j j | g   S(   N(   R   R<   Rt  (   t   zelfRq  (   RJ   (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyt
   getheaders|  s    (   R'   R(   R}  (    (   RJ   (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR{  {  s   (   t   object(   RJ   R{  (    (   RJ   sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyt   infoz  s    (   R'   R(   R)   R   R  (    (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyRz  m  s   	t   CookieAgentc           B`  s/   e  Z d  Z d   Z d d d  Z d   Z RS(   sj  
    L{CookieAgent} extends the basic L{Agent} to add RFC-compliant
    handling of HTTP cookies.  Cookies are written to and extracted
    from a C{cookielib.CookieJar} instance.

    The same cookie jar instance will be used for any requests through this
    agent, mutating it whenever a I{Set-Cookie} header appears in a response.

    @type _agent: L{twisted.web.client.Agent}
    @ivar _agent: Underlying Twisted Web agent to issue requests through.

    @type cookieJar: C{cookielib.CookieJar}
    @ivar cookieJar: Initialized cookie jar to read cookies from and store
        cookies to.

    @since: 11.1
    c         C`  s   | |  _  | |  _ d  S(   N(   t   _agentt	   cookieJar(   RJ   R>   R  (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR     s    	c         C`  s   | d k r t   } n  t |  } | j d  s |  j j |  | j d d  } | d k	 r | j   } | j d |  q n  |  j	 j
 | | | |  } | j |  j |  | S(   s  
        Issue a new request to the wrapped L{Agent}.

        Send a I{Cookie} header if a cookie for C{uri} is stored in
        L{CookieAgent.cookieJar}. Cookies are automatically extracted and
        stored from requests.

        If a C{'cookie'} header appears in C{headers} it will override the
        automatic cookie header obtained from the cookie jar.

        @see: L{Agent.request}
        R,   R4   N(   R?   R%   Rl  R]  R  t   add_cookie_headerRv  R^  R_  R  R2  R   t   _extractCookies(   RJ   R-   R   R<   R0  t   lastRequestt   cookieHeaderR  (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR2    s    c         C`  s#   t  |  } |  j j | |  | S(   s   
        Extract response cookies and store them in the cookie jar.

        @type response: L{twisted.web.iweb.IResponse}
        @param response: Twisted Web response.

        @param request: A urllib2 compatible request object.
        (   Rz  R  t   extract_cookies(   RJ   R   R2  t   resp(    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR    s    	N(   R'   R(   R)   R   R?   R2  R  (    (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR    s   	t   GzipDecoderc           B`  s    e  Z d  Z d   Z d   Z RS(   s   
    A wrapper for a L{Response} instance which handles gzip'ed body.

    @ivar original: The original L{Response} object.

    @since: 11.1
    c         C`  s   | |  _  t |  _ d  S(   N(   t   originalR!   R   (   RJ   R   (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR     s    	c         C`  s    |  j  j t | |  j    d S(   sf   
        Override C{deliverBody} to wrap the given C{protocol} with
        L{_GzipProtocol}.
        N(   R  t   deliverBodyt   _GzipProtocol(   RJ   R   (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR    s    (   R'   R(   R)   R   R  (    (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR    s   	R  c           B`  s)   e  Z d  Z d   Z d   Z d   Z RS(   s0  
    A L{Protocol} implementation which wraps another one, transparently
    decompressing received data.

    @ivar _zlibDecompress: A zlib decompress object used to decompress the data
        stream.

    @ivar _response: A reference to the original response, in case of errors.

    @since: 11.1
    c         C`  s/   | |  _  | |  _ t j d t j  |  _ d  S(   Ni   (   R  t	   _responset   zlibt   decompressobjt	   MAX_WBITSt   _zlibDecompress(   RJ   R   R   (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR     s    		c         C`  se   y |  j  j |  } Wn/ t j k
 rG t t j   g |  j   n X| ra |  j j	 |  n  d S(   sz   
        Decompress C{data} with the zlib decompressor, forwarding the raw data
        to the original protocol.
        N(
   R  t
   decompressR  R    R   R   R   R  R  t   dataReceived(   RJ   RK   t   rawData(    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR    s    c         C`  su   y |  j  j   } Wn2 t j k
 rG t | t j   g |  j   n X| ra |  j j	 |  n  |  j j
 |  d S(   sr   
        Forward the connection lost event, flushing remaining data from the
        decompressor if any.
        N(   R  t   flushR  R    R   R   R   R  R  R  R{   (   RJ   R~   R  (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR{     s    "(   R'   R(   R)   R   R  R{   (    (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR    s   		t   ContentDecoderAgentc           B`  s/   e  Z d  Z d   Z d d d  Z d   Z RS(   s^  
    An L{Agent} wrapper to handle encoded content.

    It takes care of declaring the support for content in the
    I{Accept-Encoding} header, and automatically decompresses the received data
    if it's effectively using compression.

    @param decoders: A list or tuple of (name, decoder) objects. The name
        declares which decoding the decoder supports, and the decoder must
        return a response object when called/instantiated. For example,
        C{(('gzip', GzipDecoder))}. The order determines how the decoders are
        going to be advertized to the server.

    @since: 11.1
    c         C`  sE   | |  _  t |  |  _ d j g  | D] } | d ^ q%  |  _ d  S(   Nt   ,i    (   R  t   dictt	   _decodersRF   t
   _supported(   RJ   R>   t   decoderst   decoder(    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR     s    	c         C`  sb   | d k r t   } n | j   } | j d |  j  |  j j | | | |  } | j |  j  S(   sv   
        Send a client request which declares supporting compressed content.

        @see: L{Agent.request}.
        s   accept-encodingN(	   R?   R%   R^  R_  R  R  R2  R   t   _handleResponse(   RJ   R-   R   R<   R0  R   (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR2  %  s    c         C`  s   | j  j d g   } d j |  j d  } xW | r | j   j   } |  j j |  } | d k	 ru | |  } q0 | j	 |  Pq0 W| r | j  j
 d d j |  g  n | j  j d  | S(   sX   
        Check if the response is encoded, and wrap it to handle decompression.
        s   content-encodingR  N(   R<   Rt  RF   R   R;  R   R  R=   R?   RD   t   setRawHeaderst   removeHeader(   RJ   R   t   contentEncodingHeadersRq  R  (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR  4  s    			N(   R'   R(   R)   R   R?   R2  R  (    (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR    s   	t   RedirectAgentc           B`  sh   e  Z d  Z e j e j e j g Z e j g Z	 d d  Z
 d d d  Z d   Z d   Z d   Z RS(   s  
    An L{Agent} wrapper which handles HTTP redirects.

    The implementation is rather strict: 301 and 302 behaves like 307, not
    redirecting automatically on methods different from I{GET} and I{HEAD}.

    See L{BrowserLikeRedirectAgent} for a redirecting Agent that behaves more
    like a web browser.

    @param redirectLimit: The maximum number of times the agent is allowed to
        follow redirects before failing with a L{error.InfiniteRedirection}.

    @cvar _redirectResponses: A L{list} of HTTP status codes to be redirected
        for I{GET} and I{HEAD} methods.

    @cvar _seeOtherResponses: A L{list} of HTTP status codes to be redirected
        for any method and the method altered to I{GET}.

    @since: 11.1
    i   c         C`  s   | |  _  | |  _ d  S(   N(   R  t   _redirectLimit(   RJ   R>   Re   (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR   i  s    	c         C`  s7   |  j  j | | | |  } | j |  j | | | d  S(   sb   
        Send a client request following HTTP redirects.

        @see: L{Agent.request}.
        i    (   R  R2  R   R  (   RJ   R-   R   R<   R0  R   (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR2  n  s    c         C`  s   t  | |  S(   s2  
        Resolve the redirect location against the request I{URI}.

        @type requestURI: C{bytes}
        @param requestURI: The request I{URI}.

        @type location: C{bytes}
        @param location: The redirect location.

        @rtype: C{bytes}
        @return: Final resolved I{URI}.
        (   R   (   RJ   t
   requestURIRa   (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyt   _resolveLocationy  s    c         `  s  | |  j  k rH t j   j d d | } t t j |  g     n    j j d g   } | s t j	   j d |  } t t j |  g     n  |  j
 | | d  } |  j j | | |  }	   f d   }
 |	 j |
  |	 j |  j | | | | d  S(   s   
        Handle a redirect response, checking the number of redirects already
        followed, and extracting the location header fields.
        s   Infinite redirection detectedRa   s   No location header fieldi    c         `  s   |  j     |  S(   N(   t   setPreviousResponse(   t   newResponse(   R   (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyt   _chainResponse  s    i   (   R  R    Rf   t   codeR   R   R   R<   Rt  t   RedirectWithNoLocationR  R  R2  R   R  (   RJ   R   R-   R   R<   t   redirectCountRt   t   locationHeadersRa   R   R  (    (   R   sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyt   _handleRedirect  s"    	c         C`  s   | j  |  j k rm | d k rT t j | j  d | } t t j |  g |   n  |  j | | | | |  S| j  |  j k r |  j | d | | |  S| S(   sY   
        Handle the response, making another request if it indicates a redirect.
        R.   R   Ra   (   s   GETs   HEAD(	   R  t   _redirectResponsesR    Rr   R   R   R   R  t   _seeOtherResponses(   RJ   R   R-   R   R<   R  Rt   (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR    s    N(   R'   R(   R)   R   t   MOVED_PERMANENTLYt   FOUNDt   TEMPORARY_REDIRECTR  t	   SEE_OTHERR  R   R?   R2  R  R  R  (    (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR  M  s   		t   BrowserLikeRedirectAgentc           B`  s2   e  Z d  Z e j g Z e j e j e j g Z	 RS(   sO  
    An L{Agent} wrapper which handles HTTP redirects in the same fashion as web
    browsers.

    Unlike L{RedirectAgent}, the implementation is more relaxed: 301 and 302
    behave like 303, redirecting automatically on any method and altering the
    redirect request to a I{GET}.

    @see: L{RedirectAgent}

    @since: 13.1
    (
   R'   R(   R)   R   R  R  R  R  R  R  (    (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR    s   t   _ReadBodyProtocolc           B`  s)   e  Z d  Z d   Z d   Z d   Z RS(   sk  
    Protocol that collects data sent to it.

    This is a helper for L{IResponse.deliverBody}, which collects the body and
    fires a deferred with it.

    @ivar deferred: See L{__init__}.
    @ivar status: See L{__init__}.
    @ivar message: See L{__init__}.

    @ivar dataBuffer: list of byte-strings received
    @type dataBuffer: L{list} of L{bytes}
    c         C`  s(   | |  _  | |  _ | |  _ g  |  _ d S(   s#  
        @param status: Status of L{IResponse}
        @ivar status: L{int}

        @param message: Message of L{IResponse}
        @type message: L{bytes}

        @param deferred: deferred to fire when response is complete
        @type deferred: L{Deferred} firing with L{bytes}
        N(   R   RU   RV   t
   dataBuffer(   RJ   RU   RV   R   (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR     s    			c         C`  s   |  j  j |  d S(   s?   
        Accumulate some more bytes from the response.
        N(   R  RD   (   RJ   RK   (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR    s    c         C`  s   | j  t  r. |  j j d j |  j   nP | j  t  rn |  j j t |  j	 |  j
 d j |  j    n |  j j |  d S(   s   
        Deliver the accumulated response bytes to the waiting L{Deferred}, if
        the response body has been completely received without error.
        R   N(   R-  R   R   R}   RF   R  R   R   R&   RU   RV   (   RJ   R~   (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR{     s    	(   R'   R(   R)   R   R  R{   (    (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyR    s   		c         C`  s/   t  j   } |  j t |  j |  j |   | S(   s}  
    Get the body of an L{IResponse} and return it as a byte string.

    This is a helper function for clients that don't want to incrementally
    receive the body of an HTTP response.

    @param response: The HTTP response for which the body will be read.
    @type response: L{IResponse} provider

    @return: A L{Deferred} which will fire with the body of the response.
    (   R   R   R  R  R  t   phrase(   R   R  (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyt   readBody  s    R   R   R   R   R   R  (h   R)   t
   __future__R    R   R   R   R   R   R   R   t   urllibR   R   t   ImportErrort   urllib.parseR   R  t   zope.interfaceR   t   twisted.python.compatR   R   R   t   twisted.pythonR   t   twisted.python.failureR   t   twisted.webR   Rn   R   R   R   R   t   twisted.internet.interfacesR   t   twisted.internet.endpointsR   R   R   t   twisted.python.utilR   t   twisted.python.componentsR   R    t   twisted.web.iwebR!   R"   R#   R$   t   twisted.web.http_headersR%   R   R&   Rz   R*   R   R   R   R   R~  R   R   R?   R   R   R   t   twisted.web.errorR   t   twisted.web._newclientR   R   R   R   R   R   R   R   R   R   t   twisted.internet.sslRo   R   R   R   t   FactoryR!  R$  R4  RT  Ra  Rj  Rl  Rz  R  R  R  R  R  R  t   ProtocolR  R  t   __all__(    (    (    sD   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/web/client.pyt   <module>   s   """!kl	
k=5e!<D/?f7		