ó
O'—^c           @@  sÍ  d  d l  m 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 d d l m Z d d l m Z m Z d d l 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 m Z m Z m  Z  y
 e! Z! Wn e" k
 rId Z! n Xd d d g Z$ d a% e& e d d ƒ Z' e& e d d ƒ Z( d Z) d Z* e
 j+ ƒ  Z, d Z- d g Z. e/ e d ƒ rÏd Z- e. d g 7Z. n  e j0 d k rôd Z- e. d g 7Z. n  e* d „ Z1 d „  Z2 d „  Z3 d „  Z4 d e5 f d „  ƒ  YZ6 d d d „ Z7 e j0 d k rde8 e9 e9 d „ Z: n e8 e9 e9 d „ Z: d e5 f d  „  ƒ  YZ; d! „  Z< e j0 d k rÆd" e5 f d# „  ƒ  YZ= d$ „  Z> n  d% Z? e d& d' ƒ Z@ e d( d' ƒ ZA e d) d' ƒ ZB d* „  ZC d+ „  ZD d, e5 f d- „  ƒ  YZE d. „  ZF d/ „  ZG d0 e6 f d1 „  ƒ  YZH d2 „  ZI e j0 d k r e jJ e j e jK ƒ e jJ e' e jL ƒ e jJ e( e jM ƒ n) e jJ e j e jK ƒ e jJ e' e jL ƒ d S(3   i    (   t   absolute_importNi   (   t   AuthenticationError(   t	   reduction(   t	   _billiardt   win32(   t	   get_errnot   setblockingt   bytes(   t	   monotonic(   t	   duplicatet   close(   t   ForkingPickler(   t   get_temp_dirt   Finalizet	   sub_debugt   debugt   Clientt   Listenert   Pipet
   Connectiont   PipeConnectioni    g      4@t   AF_INETt   AF_UNIXR   t   AF_PIPEc         C@  s   t  ƒ  |  S(   N(   R   (   t   timeout(    (    s9   /tmp/pip-unpacked-wheel-40MfcW/billiard/py2/connection.pyt   _init_timeoutC   s    c         C@  s   t  ƒ  |  k S(   N(   R   (   t   t(    (    s9   /tmp/pip-unpacked-wheel-40MfcW/billiard/py2/connection.pyt   _check_timeoutG   s    c         C@  s   |  d k r d S|  d k r5 t  j d d d t ƒ  ƒ S|  d k r} d	 j d
 „  t d ƒ Dƒ ƒ } d t j ƒ  t t ƒ | f St	 d ƒ ‚ d S(   s?   
    Return an arbitrary free address for the given family
    R   t	   localhosti    R   t   prefixs	   listener-t   dirR   t    c         s@  s(   |  ] } t  j t j t j ƒ Vq d  S(   N(   t   randomt   choicet   stringt   ascii_lowercaset   digits(   t   .0t   i(    (    s9   /tmp/pip-unpacked-wheel-40MfcW/billiard/py2/connection.pys	   <genexpr>Y   s   i   s   \\.\pipe\pyc-%d-%d-%ss   unrecognized familyN(   R   i    (
   t   tempfilet   mktempR   t   joint   ranget   ost   getpidt   nextt   _mmap_countert
   ValueError(   t   familyt   randomchars(    (    s9   /tmp/pip-unpacked-wheel-40MfcW/billiard/py2/connection.pyt   arbitrary_addressO   s    c         C@  se   t  |  ƒ t k r d St  |  ƒ t k r; |  j d ƒ r; d St  |  ƒ t k rQ d St d |  ƒ ‚ d S(   s]   
    Return the types of the address

    This can be 'AF_INET', 'AF_UNIX', or 'AF_PIPE'
    R   s   \\R   R   s   address type of %r unrecognizedN(   t   typet   tuplet   strt
   startswithR/   (   t   address(    (    s9   /tmp/pip-unpacked-wheel-40MfcW/billiard/py2/connection.pyt   address_typec   s    !c           B@  se   e  Z d  Z d	 d	 d d	 d „ Z d „  Z d „  Z e d „  ƒ Z e d „  ƒ Z	 d „  Z
 d „  Z RS(
   s•   
    Returns a listener object.

    This is a wrapper for a bound socket which is 'listening' for
    connections, or for a Windows named pipe.
    i   c         C@  sž   | p | r t  | ƒ p t } | p- t | ƒ } | d k rQ t | | ƒ |  _ n t | | | ƒ |  _ | d  k	 r‘ t | t ƒ r‘ t	 d ƒ ‚ n  | |  _
 d  S(   NR   s   authkey should be a byte string(   R8   t   default_familyR2   t   PipeListenert	   _listenert   SocketListenert   Nonet
   isinstanceR   t	   TypeErrort   _authkey(   t   selfR7   R0   t   backlogt   authkey(    (    s9   /tmp/pip-unpacked-wheel-40MfcW/billiard/py2/connection.pyt   __init__~   s    c         C@  s]   |  j  d k r t d ƒ ‚ n  |  j  j ƒ  } |  j rY t | |  j ƒ t | |  j ƒ n  | S(   sz   
        Accept a connection on the bound socket or named pipe of `self`.

        Returns a `Connection` object.
        s   listener is closedN(   R;   R=   t   IOErrort   acceptR@   t   deliver_challenget   answer_challenge(   RA   t   c(    (    s9   /tmp/pip-unpacked-wheel-40MfcW/billiard/py2/connection.pyRF   Ž   s    	c         C@  s,   |  j  d k	 r( |  j  j ƒ  d |  _  n  d S(   sA   
        Close the bound socket or named pipe of `self`.
        N(   R;   R=   R
   (   RA   (    (    s9   /tmp/pip-unpacked-wheel-40MfcW/billiard/py2/connection.pyR
   œ   s    c         C@  s
   |  j  j S(   N(   R;   t   _address(   RA   (    (    s9   /tmp/pip-unpacked-wheel-40MfcW/billiard/py2/connection.pyt   <lambda>¤   R   c         C@  s
   |  j  j S(   N(   R;   t   _last_accepted(   RA   (    (    s9   /tmp/pip-unpacked-wheel-40MfcW/billiard/py2/connection.pyRK   ¥   R   c         C@  s   |  S(   N(    (   RA   (    (    s9   /tmp/pip-unpacked-wheel-40MfcW/billiard/py2/connection.pyt	   __enter__§   s    c         G@  s   |  j  ƒ  d  S(   N(   R
   (   RA   t   exc_args(    (    s9   /tmp/pip-unpacked-wheel-40MfcW/billiard/py2/connection.pyt   __exit__ª   s    N(   t   __name__t
   __module__t   __doc__R=   RD   RF   R
   t   propertyR7   t   last_acceptedRM   RO   (    (    (    s9   /tmp/pip-unpacked-wheel-40MfcW/billiard/py2/connection.pyR   w   s   			c         C@  s‘   | p t  |  ƒ } | d k r- t |  ƒ } n t |  ƒ } | d k	 rd t | t ƒ rd t d ƒ ‚ n  | d k	 r t | | ƒ t | | ƒ n  | S(   s=   
    Returns a connection to the address of a `Listener`
    R   s   authkey should be a byte stringN(	   R8   t
   PipeClientt   SocketClientR=   R>   R   R?   RH   RG   (   R7   R0   RC   RI   (    (    s9   /tmp/pip-unpacked-wheel-40MfcW/billiard/py2/connection.pyR   ®   s    c   	      C@  sí   |  r t  j ƒ  \ } } | j | ƒ | j | ƒ t t j | j ƒ  ƒ ƒ } t t j | j ƒ  ƒ ƒ } | j ƒ  | j ƒ  nb t j ƒ  \ } } | r© t | d ƒ n  | r¿ t | d ƒ n  t | d t	 ƒ} t | d t	 ƒ} | | f S(   sL   
        Returns pair of connection objects at either end of a pipe
        i    t   writablet   readable(
   t   sockett
   socketpairR   R   R+   t   dupt   filenoR
   t   pipet   False(	   t   duplext	   rnonblockt	   wnonblockt   s1t   s2t   c1t   c2t   fd1t   fd2(    (    s9   /tmp/pip-unpacked-wheel-40MfcW/billiard/py2/connection.pyR   Ä   s     
c      	   C@  sO  t  d ƒ } |  r; t j } t j t j B} t t } } n t j } t j } d t } } t j | | t j t j	 Bt j
 Bd | | t j t j ƒ } t j | | d t j t j d t j ƒ }	 t j |	 t j	 d d ƒ y t j | t j ƒ Wn/ t k
 r }
 |
 j d t j k r!‚  q!n Xt | d |  ƒ} t |	 d |  ƒ} | | f S(   sL   
        Returns pair of connection objects at either end of a pipe
        R   i    i   RW   RX   N(   R2   R   t   PIPE_ACCESS_DUPLEXt   GENERIC_READt   GENERIC_WRITEt   BUFSIZEt   PIPE_ACCESS_INBOUNDt   CreateNamedPipet   PIPE_TYPE_MESSAGEt   PIPE_READMODE_MESSAGEt	   PIPE_WAITt   NMPWAIT_WAIT_FOREVERt   NULLt
   CreateFilet   OPEN_EXISTINGt   SetNamedPipeHandleStateR=   t   ConnectNamedPipet   WindowsErrort   argst   ERROR_PIPE_CONNECTEDR   (   R_   R`   Ra   R7   t   openmodet   accesst   obsizet   ibsizet   h1t   h2t   excRd   Re   (    (    s9   /tmp/pip-unpacked-wheel-40MfcW/billiard/py2/connection.pyR   Ý   s2    			$
R<   c           B@  s,   e  Z d  Z d d „ Z d „  Z d „  Z RS(   sO   
    Representation of a socket which is bound to an address and listening
    i   c         C@  sõ   t  j  t t  | ƒ ƒ |  _ yd t j d k rL |  j j t  j t  j d ƒ n  |  j j | ƒ |  j j	 | ƒ |  j j
 ƒ  |  _ Wn! t k
 r¢ |  j j ƒ  ‚  n X| |  _ d  |  _ | d k rè t |  t j d | f d d ƒ|  _ n	 d  |  _ d  S(   Nt   posixi   R   Rx   t   exitpriorityi    (   RY   t   getattrt   _socketR+   t   namet
   setsockoptt
   SOL_SOCKETt   SO_REUSEADDRt   bindt   listent   getsocknameRJ   t   OSErrorR
   t   _familyR=   RL   R   t   unlinkt   _unlink(   RA   R7   R0   RB   (    (    s9   /tmp/pip-unpacked-wheel-40MfcW/billiard/py2/connection.pyRD     s"    		$c         C@  sD   |  j  j ƒ  \ } |  _ t | j ƒ  ƒ } t | ƒ } | j ƒ  | S(   N(   R„   RF   RL   R	   R\   R   R
   (   RA   t   st   fdt   conn(    (    s9   /tmp/pip-unpacked-wheel-40MfcW/billiard/py2/connection.pyRF   #  s
    
c         C@  s-   |  j  j ƒ  |  j d  k	 r) |  j ƒ  n  d  S(   N(   R„   R
   R   R=   (   RA   (    (    s9   /tmp/pip-unpacked-wheel-40MfcW/billiard/py2/connection.pyR
   *  s    (   RP   RQ   RR   RD   RF   R
   (    (    (    s9   /tmp/pip-unpacked-wheel-40MfcW/billiard/py2/connection.pyR<     s   	c         C@  sÏ   t  |  ƒ } t j t t | ƒ ƒ } t ƒ  } xs y | j |  ƒ WnW t j k
 rš } t | ƒ t j k sw t	 | ƒ rŠ t
 d |  ƒ ‚  n  t j d ƒ q0 XPq0 W‚  t | j ƒ  ƒ } t | ƒ } | j ƒ  | S(   sO   
    Return a connection object connected to the socket given by `address`
    s   failed to connect to address %sg{®Gáz„?(   R8   RY   Rƒ   R   t   connectt   errorR   t   errnot   ECONNREFUSEDR   R   t   timet   sleepR	   R\   R   R
   (   R7   R0   R   R   R€   R‘   R’   (    (    s9   /tmp/pip-unpacked-wheel-40MfcW/billiard/py2/connection.pyRV   0  s"    	!
R:   c           B@  s2   e  Z d  Z d d „ Z d „  Z e d „  ƒ Z RS(   s0   
        Representation of a named pipe
        c      	   C@  s    | |  _  t j | t j t j t j Bt j Bt j t t t j	 t j
 ƒ } | g |  _ d  |  _ t d |  j  ƒ t |  t j d |  j |  j  f d d ƒ|  _ d  S(   Ns    listener created with address=%rRx   R‚   i    (   RJ   R   Rm   Rh   Rn   Ro   Rp   t   PIPE_UNLIMITED_INSTANCESRk   Rq   Rr   t   _handle_queueR=   RL   R   R   R:   t   _finalize_pipe_listenerR
   (   RA   R7   RB   t   handle(    (    s9   /tmp/pip-unpacked-wheel-40MfcW/billiard/py2/connection.pyRD   T  s    			c      	   C@  s¹   t  j |  j t  j t  j t  j Bt  j Bt  j t t t  j	 t  j
 ƒ } |  j j | ƒ |  j j d ƒ } y t  j | t  j
 ƒ Wn/ t k
 r® } | j d t  j k r¯ ‚  q¯ n Xt | ƒ S(   Ni    (   R   Rm   RJ   Rh   Rn   Ro   Rp   R™   Rk   Rq   Rr   Rš   t   appendt   popRv   Rw   Rx   Ry   R   (   RA   t	   newhandleRœ   R€   (    (    s9   /tmp/pip-unpacked-wheel-40MfcW/billiard/py2/connection.pyRF   g  s    
c         C@  s,   t  d | ƒ x |  D] } t | ƒ q Wd  S(   Ns    closing listener with address=%r(   R   R
   (   t   queueR7   Rœ   (    (    s9   /tmp/pip-unpacked-wheel-40MfcW/billiard/py2/connection.pyR›   x  s    N(   RP   RQ   RR   R=   RD   RF   t   staticmethodR›   (    (    (    s9   /tmp/pip-unpacked-wheel-40MfcW/billiard/py2/connection.pyR:   P  s   	c         C@  sÆ   t  ƒ  } x— yH t j |  d ƒ t j |  t j t j Bd t j t j d t j ƒ } WnD t k
 rš } | j	 d t j
 t j f k s‘ t | ƒ rœ ‚  qœ q XPq W‚  t j | t j d d ƒ t | ƒ S(   sU   
        Return a connection object connected to the pipe given by `address`
        iè  i    N(   R   R   t   WaitNamedPipeRs   Ri   Rj   Rr   Rt   Rw   Rx   t   ERROR_SEM_TIMEOUTt   ERROR_PIPE_BUSYR   Ru   Ro   R=   R   (   R7   R   t   hR€   (    (    s9   /tmp/pip-unpacked-wheel-40MfcW/billiard/py2/connection.pyRU   ~  s"    	"

i   s   #CHALLENGE#t   asciis	   #WELCOME#s	   #FAILURE#c         C@  s¡   d d  l  } t | t ƒ s! t ‚ t j t ƒ } |  j t | ƒ | j	 | | ƒ j
 ƒ  } |  j d ƒ } | | k r„ |  j t ƒ n |  j t ƒ t d ƒ ‚ d  S(   Ni    i   s   digest received was wrong(   t   hmacR>   R   t   AssertionErrorR+   t   urandomt   MESSAGE_LENGTHt
   send_bytest	   CHALLENGEt   newt   digestt
   recv_bytest   WELCOMEt   FAILURER   (   t
   connectionRC   R§   t   messageR®   t   response(    (    s9   /tmp/pip-unpacked-wheel-40MfcW/billiard/py2/connection.pyRG   ¤  s    c         C@  s¹   d d  l  } t | t ƒ s! t ‚ |  j d ƒ } | t t ƒ  t k sV t d | ƒ ‚ | t t ƒ } | j | | ƒ j ƒ  } |  j	 | ƒ |  j d ƒ } | t
 k rµ t d ƒ ‚ n  d  S(   Ni    i   s   message = %rs   digest sent was rejected(   R§   R>   R   R¨   R¯   t   lenR¬   R­   R®   R«   R°   R   (   R²   RC   R§   R³   R®   R´   (    (    s9   /tmp/pip-unpacked-wheel-40MfcW/billiard/py2/connection.pyRH   ²  s    &t   ConnectionWrapperc           B@  s#   e  Z d  „  Z d „  Z d „  Z RS(   c         C@  sO   | |  _  | |  _ | |  _ x- d D]% } t | | ƒ } t |  | | ƒ q" Wd  S(   NR\   R
   t   pollR¯   R«   (   R\   R
   R·   R¯   R«   (   t   _connt   _dumpst   _loadsRƒ   t   setattr(   RA   R’   t   dumpst   loadst   attrt   obj(    (    s9   /tmp/pip-unpacked-wheel-40MfcW/billiard/py2/connection.pyRD   Ä  s    			c         C@  s#   |  j  | ƒ } |  j j | ƒ d  S(   N(   R¹   R¸   R«   (   RA   R¿   R   (    (    s9   /tmp/pip-unpacked-wheel-40MfcW/billiard/py2/connection.pyt   sendÌ  s    c         C@  s   |  j  j ƒ  } |  j | ƒ S(   N(   R¸   R¯   Rº   (   RA   R   (    (    s9   /tmp/pip-unpacked-wheel-40MfcW/billiard/py2/connection.pyt   recvÐ  s    (   RP   RQ   RD   RÀ   RÁ   (    (    (    s9   /tmp/pip-unpacked-wheel-40MfcW/billiard/py2/connection.pyR¶   Ã  s   		c         C@  s%   t  j |  f d  d  d  d ƒ j d ƒ S(   Ni   t   utf8(   t	   xmlrpclibR¼   R=   t   encode(   R¿   (    (    s9   /tmp/pip-unpacked-wheel-40MfcW/billiard/py2/connection.pyt
   _xml_dumpsÕ  s    c         C@  s%   t  j |  j d ƒ ƒ \ \ } } | S(   NRÂ   (   RÃ   R½   t   decode(   R   R¿   t   method(    (    s9   /tmp/pip-unpacked-wheel-40MfcW/billiard/py2/connection.pyt
   _xml_loadsÙ  s    !t   XmlListenerc           B@  s   e  Z d  „  Z RS(   c         C@  s+   d d  l  a  t j |  ƒ } t | t t ƒ S(   Ni    (   RÃ   R   RF   R¶   RÅ   RÈ   (   RA   R¿   (    (    s9   /tmp/pip-unpacked-wheel-40MfcW/billiard/py2/connection.pyRF   ß  s    (   RP   RQ   RF   (    (    (    s9   /tmp/pip-unpacked-wheel-40MfcW/billiard/py2/connection.pyRÉ   Þ  s   c          O@  s%   d d  l  a  t t |  | Ž  t t ƒ S(   Ni    (   RÃ   R¶   R   RÅ   RÈ   (   Rx   t   kwds(    (    s9   /tmp/pip-unpacked-wheel-40MfcW/billiard/py2/connection.pyt	   XmlClientæ  s    (N   t
   __future__R    R+   R    t   sysRY   R"   R•   R—   R'   t	   itertoolsR   R   R   t   _extR   R   t   compatR   R   R   t   cbytest   fiveR   t   forkingR	   R
   R   t   utilR   R   R   R   Rw   t	   NameErrorR=   t   __all__RÃ   Rƒ   R   R   Rk   t   CONNECTION_TIMEOUTt   countR.   R9   t   familiest   hasattrt   platformR   R   R2   R8   t   objectR   R   t   TrueR^   R   R<   RV   R:   RU   Rª   R¬   R°   R±   RG   RH   R¶   RÅ   RÈ   RÉ   RË   t   registert   reduce_sockett   reduce_connectiont   reduce_pipe_connection(    (    (    s9   /tmp/pip-unpacked-wheel-40MfcW/billiard/py2/connection.pyt   <module>
   s†   "

				7+(	.					