ó
è¾bc           @   sy  d  d d g Z  d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l	 m
 Z
 m Z d d l m Z m Z m Z m Z d d l m Z m 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 j d k r.d Z e d g 7Z n  e d „ Z d „  Z d „  Z d „  Z d e  f d „  ƒ  YZ! d d d „ Z# e j d k r˜e$ d „ Z% n d d l m& Z& e$ d „ Z% d e  f d „  ƒ  YZ' d „  Z( e j d k rd e  f d „  ƒ  YZ) d „  Z* n  d Z+ d Z, d Z- d  Z. d! „  Z/ d" „  Z0 d# e  f d$ „  ƒ  YZ1 d% „  Z2 d& „  Z3 d' e! f d( „  ƒ  YZ4 d) „  Z5 d S(*   t   Clientt   Listenert   PipeiÿÿÿÿN(   t   current_processt   AuthenticationError(   t   get_temp_dirt   Finalizet	   sub_debugt   debug(   t	   duplicatet   closei    g      4@t   AF_INETt   AF_UNIXt   win32t   AF_PIPEc         C   s   t  j  ƒ  |  S(   N(   t   time(   t   timeout(    (    s0   /usr/lib/python2.7/multiprocessing/connection.pyt   _init_timeoutI   s    c         C   s   t  j  ƒ  |  k S(   N(   R   (   t   t(    (    s0   /usr/lib/python2.7/multiprocessing/connection.pyt   _check_timeoutL   s    c         C   s}   |  d k r d S|  d k r5 t  j d d d t ƒ  ƒ S|  d k rm t  j d d	 t j ƒ  t j ƒ  f d d
 ƒ St d ƒ ‚ d S(   s?   
    Return an arbitrary free address for the given family
    R   t	   localhosti    R   t   prefixs	   listener-t   dirR   s   \\.\pipe\pyc-%d-%d-t    s   unrecognized familyN(   R   i    (   t   tempfilet   mktempR   t   ost   getpidt   _mmap_countert   nextt
   ValueError(   t   family(    (    s0   /usr/lib/python2.7/multiprocessing/connection.pyt   arbitrary_addressS   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(    (    s0   /usr/lib/python2.7/multiprocessing/connection.pyt   address_typeb   s    !c           B   sS   e  Z d  Z d d d d d „ Z d „  Z d „  Z e d „  ƒ Z e 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(   R&   t   default_familyR    t   PipeListenert	   _listenert   SocketListenert   Nonet
   isinstancet   bytest	   TypeErrort   _authkey(   t   selfR%   R   t   backlogt   authkey(    (    s0   /usr/lib/python2.7/multiprocessing/connection.pyt   __init__|   s    c         C   s?   |  j  j ƒ  } |  j r; t | |  j ƒ t | |  j ƒ n  | S(   sz   
        Accept a connection on the bound socket or named pipe of `self`.

        Returns a `Connection` object.
        (   R)   t   acceptR/   t   deliver_challenget   answer_challenge(   R0   t   c(    (    s0   /usr/lib/python2.7/multiprocessing/connection.pyR4   ‹   s
    	c         C   s   |  j  j ƒ  S(   sA   
        Close the bound socket or named pipe of `self`.
        (   R)   R
   (   R0   (    (    s0   /usr/lib/python2.7/multiprocessing/connection.pyR
   —   s    c         C   s
   |  j  j S(   N(   R)   t   _address(   R0   (    (    s0   /usr/lib/python2.7/multiprocessing/connection.pyt   <lambda>   R   c         C   s
   |  j  j S(   N(   R)   t   _last_accepted(   R0   (    (    s0   /usr/lib/python2.7/multiprocessing/connection.pyR9   ž   R   N(
   t   __name__t
   __module__t   __doc__R+   R3   R4   R
   t   propertyR%   t   last_accepted(    (    (    s0   /usr/lib/python2.7/multiprocessing/connection.pyR   u   s   		c         C   sŽ   | p t  |  ƒ } | d k r- t |  ƒ } n t |  ƒ } | d k	 ra t | t ƒ ra 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(	   R&   t
   PipeClientt   SocketClientR+   R,   R-   R.   R6   R5   (   R%   R   R2   R7   (    (    s0   /usr/lib/python2.7/multiprocessing/connection.pyR    ¡   s    c         C   sË   |  r… t  j ƒ  \ } } | j t ƒ | j t ƒ t j t j | j ƒ  ƒ ƒ } t j t j | j ƒ  ƒ ƒ } | j	 ƒ  | j	 ƒ  n< t j
 ƒ  \ } } t j | d t ƒ} t j | d t ƒ} | | f S(   sL   
        Returns pair of connection objects at either end of a pipe
        t   writablet   readable(   t   sockett
   socketpairt   setblockingt   Truet   _multiprocessingt
   ConnectionR   t   dupt   filenoR
   t   pipet   False(   t   duplext   s1t   s2t   c1t   c2t   fd1t   fd2(    (    s0   /usr/lib/python2.7/multiprocessing/connection.pyR   ·   s    
(   R   c      	   C   sU  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 j | d |  ƒ}	 t j | d |  ƒ}
 |	 |
 f S(   sL   
        Returns pair of connection objects at either end of a pipe
        R   i    i   RB   RC   N(   R    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_CONNECTEDRH   t   PipeConnection(   RN   R%   t   openmodet   accesst   obsizet   ibsizet   h1t   h2t   eRQ   RR   (    (    s0   /usr/lib/python2.7/multiprocessing/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  | ƒ ƒ |  _ yb |  j j t  j t  j d ƒ |  j j t ƒ |  j j | ƒ |  j j	 | ƒ |  j j
 ƒ  |  _ Wn$ t  j k
 r£ |  j j ƒ  ‚  n X| |  _ d  |  _ | d k ré t |  t j d | f d d ƒ|  _ n	 d  |  _ d  S(   Ni   R   Re   t   exitpriorityi    (   RD   t   getattrt   _sockett
   setsockoptt
   SOL_SOCKETt   SO_REUSEADDRRF   RG   t   bindt   listent   getsocknameR8   t   errorR
   t   _familyR+   R:   R   R   t   unlinkt   _unlink(   R0   R%   R   R1   (    (    s0   /usr/lib/python2.7/multiprocessing/connection.pyR3   û   s     		$c         C   s›   x\ t  r^ y |  j j ƒ  \ } |  _ Wn2 t j k
 rY } | j d t j k r[ ‚  q[ q XPq W| j	 t  ƒ t
 | j ƒ  ƒ } t j | ƒ } | j ƒ  | S(   Ni    (   RG   Rq   R4   R:   RD   Rx   Re   t   errnot   EINTRRF   R	   RK   RH   RI   R
   (   R0   t   sRn   t   fdt   conn(    (    s0   /usr/lib/python2.7/multiprocessing/connection.pyR4     s    	

c         C   sA   z |  j  j ƒ  Wd  |  j } | d  k	 r< d  |  _ | ƒ  n  Xd  S(   N(   Rq   R
   R{   R+   (   R0   Rz   (    (    s0   /usr/lib/python2.7/multiprocessing/connection.pyR
     s    		(   R;   R<   R=   R3   R4   R
   (    (    (    s0   /usr/lib/python2.7/multiprocessing/connection.pyR*   ÷   s   	c         C   sê   t  t t |  ƒ ƒ } t ƒ  } xš t j | ƒ } | j t ƒ y | j |  ƒ Wnb t j k
 r² } | j ƒ  | j	 d t
 j k s t | ƒ r¢ t d |  ƒ ‚  n  t j d ƒ q! XPq! W‚  t | j ƒ  ƒ } t j | ƒ } | j ƒ  | S(   sO   
    Return a connection object connected to the socket given by `address`
    i    s   failed to connect to address %sg{®Gáz„?(   Rp   RD   R&   R   RF   RG   t   connectRx   R
   Re   R|   t   ECONNREFUSEDR   R   R   t   sleepR	   RK   RH   RI   (   R%   R   R   R~   Rn   R   R€   (    (    s0   /usr/lib/python2.7/multiprocessing/connection.pyRA   )  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=%rRe   Ro   i    (   R8   R   RZ   RU   R[   R\   R]   t   PIPE_UNLIMITED_INSTANCESRX   R^   R_   t   _handle_queueR+   R:   R   R   R(   t   _finalize_pipe_listenerR
   (   R0   R%   R1   t   handle(    (    s0   /usr/lib/python2.7/multiprocessing/connection.pyR3   O  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
 ƒ Wn8 t k
 r· } | j d t  j t  j f k r¸ ‚  q¸ n Xt j | ƒ S(   Ni    (   R   RZ   R8   RU   R[   R\   R]   R„   RX   R^   R_   R…   t   appendt   popRc   Rd   Re   Rf   t   ERROR_NO_DATARH   Rg   (   R0   t	   newhandleR‡   Rn   (    (    s0   /usr/lib/python2.7/multiprocessing/connection.pyR4   b  s    
c         C   s,   t  d | ƒ x |  D] } t | ƒ q Wd  S(   Ns    closing listener with address=%r(   R   R
   (   t   queueR%   R‡   (    (    s0   /usr/lib/python2.7/multiprocessing/connection.pyR†   v  s    N(   R;   R<   R=   R+   R3   R4   t   staticmethodR†   (    (    (    s0   /usr/lib/python2.7/multiprocessing/connection.pyR(   K  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 j | ƒ S(   sU   
        Return a connection object connected to the pipe given by `address`
        iè  i    N(   R   R   t   WaitNamedPipeR`   RV   RW   R_   Ra   Rd   Re   t   ERROR_SEM_TIMEOUTt   ERROR_PIPE_BUSYR   Rb   R\   R+   RH   Rg   (   R%   R   t   hRn   (    (    s0   /usr/lib/python2.7/multiprocessing/connection.pyR@   |  s     	"
i   s   #CHALLENGE#s	   #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
   connectionR2   R’   t   messageR™   t   response(    (    s0   /usr/lib/python2.7/multiprocessing/connection.pyR5      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   R2   R’   Rž   R™   RŸ   (    (    s0   /usr/lib/python2.7/multiprocessing/connection.pyR6   ­  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(   NRK   R
   t   pollRš   R–   (   RK   R
   R¢   Rš   R–   (   t   _connt   _dumpst   _loadsRp   t   setattr(   R0   R€   t   dumpst   loadst   attrt   obj(    (    s0   /usr/lib/python2.7/multiprocessing/connection.pyR3   ¾  s    			c         C   s#   |  j  | ƒ } |  j j | ƒ d  S(   N(   R¤   R£   R–   (   R0   Rª   R~   (    (    s0   /usr/lib/python2.7/multiprocessing/connection.pyt   sendÅ  s    c         C   s   |  j  j ƒ  } |  j | ƒ S(   N(   R£   Rš   R¥   (   R0   R~   (    (    s0   /usr/lib/python2.7/multiprocessing/connection.pyt   recvÈ  s    (   R;   R<   R3   R«   R¬   (    (    (    s0   /usr/lib/python2.7/multiprocessing/connection.pyR¡   ½  s   		c         C   s   t  j |  f d  d  d  d ƒ S(   Ni   (   t	   xmlrpclibR§   R+   (   Rª   (    (    s0   /usr/lib/python2.7/multiprocessing/connection.pyt
   _xml_dumpsÌ  s    c         C   s   t  j |  ƒ \ \ } } | S(   N(   R­   R¨   (   R~   Rª   t   method(    (    s0   /usr/lib/python2.7/multiprocessing/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   R4   R¡   R®   R°   (   R0   Rª   (    (    s0   /usr/lib/python2.7/multiprocessing/connection.pyR4   Ô  s    (   R;   R<   R4   (    (    (    s0   /usr/lib/python2.7/multiprocessing/connection.pyR±   Ó  s   c          O   s%   d d  l  a  t t |  | Ž  t t ƒ S(   Niÿÿÿÿ(   R­   R¡   R    R®   R°   (   Re   t   kwds(    (    s0   /usr/lib/python2.7/multiprocessing/connection.pyt	   XmlClientÚ  s    (6   t   __all__R   t   sysRD   R|   R   R   t	   itertoolsRH   t   multiprocessingR   R   t   multiprocessing.utilR   R   R   R   t   multiprocessing.forkingR	   R
   RX   t   CONNECTION_TIMEOUTt   countR   R'   t   familiest   hasattrt   platformR   R   R    R&   t   objectR   R+   R    RG   R   R   R*   RA   R(   R@   R•   R—   R›   Rœ   R5   R6   R¡   R®   R°   R±   R³   (    (    (    s0   /usr/lib/python2.7/multiprocessing/connection.pyt   <module>#   s`   "				,*2	 1				