ó
[łXMc           @   s  d  Z  d d l Z d d l Z d d l Z d d l Z d   Z d   Z y e j e j d  Wn8 e e	 e j
 f k
 r e e _ e e _ d e _ n Xe Z d e f d     YZ e e j d	 <d d l Z y e j Wn0 e k
 rd
 e f d     YZ e e _ n Xy
 e Z Wn! e	 k
 r:d d l m Z n Xy
 e Z Wn! e	 k
 rhd d l m Z n Xy d d l m Z Wn e k
 re Z n Xd 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.
i˙˙˙˙Nc   
      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(    (    s9   /usr/lib/python2.7/dist-packages/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   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/python/compat.pyt	   inet_ntop?   s<    

		$	#s   ::R    t   tsafec           B   s   e  Z d  d d     YZ RS(   t
   Connectionc            B   s@   e  Z d  Z d Z d   Z x  d% D] Z d# e e f d$ Uq" WRS(&   sQ   
        OpenSSL.tsafe.Connection, defined in such a way as to not blow.
        s   OpenSSL.tsafec         G   sE   d d l  m } t | j |  |  _ d d l m } |   |  _ d  S(   Ni˙˙˙˙(   t   SSL(   t   _RLock(   t   OpenSSLR2   t   applyR1   t	   _ssl_connt	   threadingR3   t   _lock(   t   selft   argst   _sslR3   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/python/compat.pyt   __init__y   s    t   get_contextt   pendingt   sendt   writet   recvt   readt   renegotiatet   bindt   listent   connectt   acceptt   setblockingt   filenot   shutdownt   closet   get_cipher_listt   getpeernamet   getsocknamet
   getsockoptt
   setsockoptt   makefilet   get_app_datat   set_app_datat   state_stringt   sock_shutdownt   get_peer_certificatet	   want_readt
   want_writet   set_connect_statet   set_accept_statet
   connect_ext   sendallsË   def %s(self, *args):
                self._lock.acquire()
                try:
                    return apply(self._ssl_conn.%s, args)
                finally:
                    self._lock.release()
N(    R=   R>   s   sends   writeRA   s   readRC   RD   RE   RF   RG   RH   s   filenoRJ   s   closeRL   RM   RN   RO   RP   s   makefileRR   RS   RT   RU   RV   RW   RX   RY   RZ   R[   R\   (   t   __name__t
   __module__t   __doc__R<   t   f(    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/python/compat.pyR1   s   s   	        
(    (   R]   R^   R1   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/python/compat.pyR0   r   s   s   OpenSSL.tsafet
   attrgetterc           B   s   e  Z d    Z d   Z RS(   c         C   s   | |  _  d  S(   N(   t   name(   R9   Rb   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/python/compat.pyR<      s    c         C   s   t  | |  j  S(   N(   R
   Rb   (   R9   t   obj(    (    s9   /usr/lib/python2.7/dist-packages/twisted/python/compat.pyt   __call__   s    (   R]   R^   R<   Rd   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/python/compat.pyRa      s   	(   t   Set(   t   ImmutableSet(   t   reduce(   R_   t   sysR   R   R   R%   R/   R    t   AttributeErrort	   NameErrorR   t   dictt   adictt   objectR0   t   modulest   operatorRa   t   sett   setsRe   t	   frozensetRf   t	   functoolsRg   t   ImportError(    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/python/compat.pyt   <module>   s<   0	.	"		


