ó
#[Qc           @   s‚  d  Z  d d l m Z d d l Z d d l Z d d l Z d d l Z e j d, k  r^ e Z	 n e
 Z	 d „  Z d „  Z y e j Wn e k
 r d e _ n Xy e j e j d	 ƒ Wn/ e e e j f k
 ræ e e _ e e _ n Xe Z e	 rÿ [ [ [ n  e Z e Z y d d
 l m Z Wn e k
 r8e Z n Xd d „ Z y
 e Z Wn e k
 rkd „  Z n Xd „  Z e	 r„e Z n e Z d „  Z e	 r¥d „  Z n d d Ud e _  e	 rÏd d l  m! Z" n d d l  m# Z" e	 rd „  Z$ d „  Z% d d d „ Z& d „  Z' n! d „  Z$ d „  Z% e( Z& d „  Z' d e$ _  d e% _  d e' _  d d d  d! d" d# d$ d% d& d' d( d) d* d+ g Z) d S(-   sË  
Compatibility module to provide backwards compatibility for useful Python
features.

This is mainly for use of internal Twisted code. We encourage you to use
the latest version of Python directly from your code, if possible.

@var unicode: The type of Unicode strings, C{unicode} on Python 2 and C{str}
    on Python 3.

@var NativeStringIO: An in-memory file-like object that operates on the native
    string type (bytes in Python 2, unicode in Python 3).
iÿÿÿÿ(   t   divisionNi   i    c   
      C   s}  |  t  j k r t  j | ƒ S|  t t  d d ƒ k rgg  | D] } | t j d k r; | ^ q; r t d d j | ƒ f ƒ ‚ n  | j d ƒ } | j	 d ƒ } d | d k } t
 | ƒ d | k sÏ | d	 k rÞ t d
 ƒ ‚ n  | d	 k rî d S| r“d g d t
 | ƒ | | } | j d ƒ r/| | d *n< | j d ƒ rK| | d )n  | j d ƒ } | | | | d +t
 | ƒ d | k r¸t d
 ƒ ‚ q¸n% t
 | ƒ d | k r¸t d
 ƒ ‚ n  | r5| d j	 d ƒ d	 k ræt d
 ƒ ‚ n  t  j | d ƒ } t j d | ƒ }	 g  |	 D] } t | ƒ d ^ q| d )n  g  | D] } t | d ƒ ^ q<} t j d | Œ St  j d d ƒ ‚ d  S(   Nt   AF_INET6s   :.s   Illegal characters: %rt    t   :t   .iÿÿÿÿi   i   s   Syntactically invalid addresst    i   t   0s   ::i   iþÿÿÿi   s   !HHs   !8Hia   s(   Address family not supported by protocolt                   (   t   sockett   AF_INETt	   inet_atont   getattrt   stringt	   hexdigitst
   ValueErrort   joint   splitt   countt   lent
   startswitht   endswitht   indext   structt   unpackt   hext   intt   packt   error(
   t   aft   addrt   xt   partst   elidedt   ipv4Componentt   zerost   idxt   rawipv4t   unpackedipv4(    (    sG   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/python/compat.pyt	   inet_pton!   sB    ,"*"c   	      C   sÙ  |  t  j k r t  j | ƒ S|  t  j k rÃt | ƒ d k rL t d ƒ ‚ n  t j d | ƒ } d  } } x‚ t	 d ƒ D]t } | | s­ | d  k r  | } d } n  | d 7} qu | d  k	 ru | d  k sÑ | | k rà | } | } n  d  } qu qu W| d  k	 r | d  k s| | k r | } | } n  g  | D] } t
 | ƒ d ^ q'} | d  k	 rfd g | | | | +n  | d d k r‰| j d d ƒ n  | d	 d k r¶| j t | ƒ d d ƒ n  d
 j | ƒ St  j d d ƒ ‚ d  S(   Ni   s   address length incorrects   !8Hi   i    i   i   R   iÿÿÿÿR   ia   s(   Address family not supported by protocol(   R   R	   t	   inet_ntoaR   R   R   R   R   t   Nonet   rangeR   t   insertR   R   (	   R   R   R   t   curBaset   bestBaset   it   curLent   bestLenR   (    (    sG   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/python/compat.pyt	   inet_ntopO   s<    

		$	#R   s   ::(   t   reducec         B   si   | d k r | } n  e |  d ƒ } z | j ƒ  } Wd | j ƒ  Xe | |  d ƒ } | | | f d Ud S(   sz  
    Execute a Python script in the given namespaces.

    Similar to the execfile builtin, but a namespace is mandatory, partly
    because that's a sensible thing to require, and because otherwise we'd
    have to do some frame hacking.

    This is a compatibility implementation for Python 3 porting, to avoid the
    use of the deprecated builtin C{execfile} function.
    t   rbUNt   exec(   R(   t   opent   readt   closet   compile(   t   filenamet   globalst   localst   fint   sourcet   code(    (    sG   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/python/compat.pyt   execfile’   s    	c         C   s(   |  | k  r d S|  | k r  d Sd Sd S(   s™   
        Compare two objects.

        Returns a negative number if C{a < b}, zero if they are equal, and a
        positive number if C{a > b}.
        iÿÿÿÿi    i   N(    (   t   at   b(    (    sG   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/python/compat.pyt   cmp«   s
    c         C   sz   t  s
 |  Sd „  } d „  } d „  } d „  } d „  } d „  } | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ |  S(   sü   
    Class decorator that ensures support for the special C{__cmp__} method.

    On Python 2 this does nothing.

    On Python 3, C{__eq__}, C{__lt__}, etc. methods are added to the class,
    relying on C{__cmp__} to implement their comparisons.
    c         S   s)   |  j  | ƒ } | t k r | S| d k S(   Ni    (   t   __cmp__t   NotImplemented(   t   selft   othert   c(    (    sG   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/python/compat.pyt   __eq__È   s    c         S   s)   |  j  | ƒ } | t k r | S| d k S(   Ni    (   RB   RC   (   RD   RE   RF   (    (    sG   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/python/compat.pyt   __ne__Ï   s    c         S   s)   |  j  | ƒ } | t k r | S| d k  S(   Ni    (   RB   RC   (   RD   RE   RF   (    (    sG   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/python/compat.pyt   __lt__Ö   s    c         S   s)   |  j  | ƒ } | t k r | S| d k S(   Ni    (   RB   RC   (   RD   RE   RF   (    (    sG   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/python/compat.pyt   __le__Ý   s    c         S   s)   |  j  | ƒ } | t k r | S| d k S(   Ni    (   RB   RC   (   RD   RE   RF   (    (    sG   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/python/compat.pyt   __gt__ä   s    c         S   s)   |  j  | ƒ } | t k r | S| d k S(   Ni    (   RB   RC   (   RD   RE   RF   (    (    sG   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/python/compat.pyt   __ge__ë   s    (   t   _PY3RI   RK   RJ   RL   RG   RH   (   t   klassRG   RH   RI   RJ   RK   RL   (    (    sG   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/python/compat.pyt
   comparable»   s    
												c         C   s‡   t  |  t t f ƒ s( t d |  ƒ ‚ n  t rZ t  |  t ƒ rJ |  j d ƒ S|  j d ƒ n) t  |  t ƒ rv |  j d ƒ S|  j d ƒ |  S(   s	  
    Convert C{bytes} or C{unicode} to the native C{str} type, using ASCII
    encoding if conversion is necessary.

    @raise UnicodeError: The input string is not ASCII encodable/decodable.
    @raise TypeError: The input is neither C{bytes} nor C{unicode}.
    s   %r is neither bytes nor unicodet   ascii(   t
   isinstancet   bytest   unicodet	   TypeErrorRM   t   decodet   encode(   t   s(    (    sG   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/python/compat.pyt   nativeString  s    c         C   s   |  j  | ƒ ‚ d  S(   N(   t   with_traceback(   t	   exceptiont	   traceback(    (    sG   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/python/compat.pyt   reraise  s    sZ   def reraise(exception, traceback):
        raise exception.__class__, exception, tracebacksZ  
Re-raise an exception, with an optional traceback, in a way that is compatible
with both Python 2 and Python 3.

Note that on Python 3, re-raised exceptions will be mutated, with their
C{__traceback__} attribute being set.

@param exception: The exception instance.
@param traceback: The traceback to use, or C{None} indicating a new traceback.
(   t   StringIO(   t   BytesIOc         c   s1   x* t  t |  ƒ ƒ D] } |  | | d !Vq Wd  S(   Ni   (   R)   R   (   t   originalBytesR-   (    (    sG   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/python/compat.pyt	   iterbytes:  s    c         C   s   d |  j  d ƒ S(   Ns   %dRP   (   RV   (   R-   (    (    sG   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/python/compat.pyt
   intToBytes?  s    c         C   s'   | d k r |  | S|  | | | !Sd S(   s‘  
        Return a copy of the given bytes-like object.

        If an offset is given, the copy starts at that offset. If a size is
        given, the copy will only be of that length.

        @param object: C{bytes} to be copied.

        @param offset: C{int}, starting index of copy.

        @param size: Optional, if an C{int} is given limit the length of copy
            to this size.
        N(   R(   (   t   objectt   offsett   size(    (    sG   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/python/compat.pyt   lazyByteSliceG  s    c         C   s+   t  |  t ƒ s t d ƒ ‚ n  |  j d ƒ S(   Ns*   Can only convert text to bytes on Python 3RP   (   RQ   RS   RT   RV   (   RW   (    (    sG   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/python/compat.pyt   networkString[  s    c         C   s   |  S(   N(    (   R_   (    (    sG   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/python/compat.pyR`   `  s    c         C   s   d |  S(   Ns   %d(    (   R-   (    (    sG   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/python/compat.pyRa   d  s    c         C   s/   t  |  t ƒ s t d ƒ ‚ n  |  j d ƒ |  S(   Ns'   Can only pass-through bytes on Python 2RP   (   RQ   t   strRT   RU   (   RW   (    (    sG   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/python/compat.pyRf   j  s    s  
Return an iterable wrapper for a C{bytes} object that provides the behavior of
iterating over C{bytes} on Python 2.

In particular, the results of iteration are the individual bytes (rather than
integers as on Python 3).

@param originalBytes: A C{bytes} object that will be wrapped.
sÛ   
Convert the given integer into C{bytes}, as ASCII-encoded Arab numeral.

In other words, this is equivalent to calling C{bytes} in Python 2 on an
integer.

@param i: The C{int} to convert to C{bytes}.
@rtype: C{bytes}
s  
Convert the native string type to C{bytes} if it is not already C{bytes} using
ASCII encoding if conversion is necessary.

This is useful for sending text-like bytes that are constructed using string
interpolation.  For example, this is safe on Python 2 and Python 3:

    networkString("Hello %d" % (n,))

@param s: A native string to convert to bytes if necessary.
@type s: C{str}

@raise UnicodeError: The input string is not ASCII encodable/decodable.
@raise TypeError: The input is neither C{bytes} nor C{unicode}.

@rtype: C{bytes}
R\   R>   t	   frozensetR1   t   setRA   RO   RX   t   NativeStringIORf   RS   R`   Ra   Re   (   i   i    (*   t   __doc__t
   __future__R    t   sysR   R   R   t   version_infot   FalseRM   t   TrueR&   R0   R   t   AttributeErrort	   NameErrorR   t   dictt   adictRi   Rh   t	   functoolsR1   t   ImportErrorR(   R>   RA   RO   Rg   RS   RX   R\   t   ioR]   Rj   R^   R`   Ra   Re   Rf   t   buffert   __all__(    (    (    sG   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/python/compat.pyt   <module>   sˆ   0		.	"	

	@									
		