ó
HØê[c           @   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   sw   |  d k r d S|  d k r5 t  j d d d t ƒ  ƒ S|  d k rg t  j d d	 t j ƒ  t j ƒ  f ƒ 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-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(   R/   t   c(    (    s0   /usr/lib/python2.7/multiprocessing/connection.pyR3   ‹   s
    	c         C   s   |  j  j ƒ  S(   sA   
        Close the bound socket or named pipe of `self`.
        (   R(   R
   (   R/   (    (    s0   /usr/lib/python2.7/multiprocessing/connection.pyR
   —   s    c         C   s
   |  j  j S(   N(   R(   t   _address(   R/   (    (    s0   /usr/lib/python2.7/multiprocessing/connection.pyt   <lambda>   s    c         C   s
   |  j  j S(   N(   R(   t   _last_accepted(   R/   (    (    s0   /usr/lib/python2.7/multiprocessing/connection.pyR8   ž   s    N(
   t   __name__t
   __module__t   __doc__R*   R2   R3   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-   R5   R4   (   R$   R   R1   R6   (    (    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   RA   RB   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_CONNECTEDRG   t   PipeConnection(   RM   R$   t   openmodet   accesst   obsizet   ibsizet   h1t   h2t   eRP   RQ   (    (    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   Rd   t   exitpriorityi    (   RC   t   getattrt   _sockett
   setsockoptt
   SOL_SOCKETt   SO_REUSEADDRRE   RF   t   bindt   listent   getsocknameR7   t   errorR
   t   _familyR*   R9   R   R   t   unlinkt   _unlink(   R/   R$   R   R0   (    (    s0   /usr/lib/python2.7/multiprocessing/connection.pyR2   û   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    (   RF   Rp   R3   R9   RC   Rw   Rd   t   errnot   EINTRRE   R	   RJ   RG   RH   R
   (   R/   t   sRm   t   fdt   conn(    (    s0   /usr/lib/python2.7/multiprocessing/connection.pyR3     s    	

c         C   s-   |  j  j ƒ  |  j d  k	 r) |  j ƒ  n  d  S(   N(   Rp   R
   Rz   R*   (   R/   (    (    s0   /usr/lib/python2.7/multiprocessing/connection.pyR
     s    (   R:   R;   R<   R2   R3   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! ‚  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„?(   Ro   RC   R%   R   RE   RF   t   connectRw   R
   Rd   R{   t   ECONNREFUSEDR   R   R   t   sleepR	   RJ   RG   RH   (   R$   R   R   R}   Rm   R~   R   (    (    s0   /usr/lib/python2.7/multiprocessing/connection.pyR@   %  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=%rRd   Rn   i    (   R7   R   RY   RT   RZ   R[   R\   t   PIPE_UNLIMITED_INSTANCESRW   R]   R^   t   _handle_queueR*   R9   R   R   R'   t   _finalize_pipe_listenerR
   (   R/   R$   R0   t   handle(    (    s0   /usr/lib/python2.7/multiprocessing/connection.pyR2   K  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   RY   R7   RT   RZ   R[   R\   Rƒ   RW   R]   R^   R„   t   appendt   popRb   Rc   Rd   Re   t   ERROR_NO_DATARG   Rf   (   R/   t	   newhandleR†   Rm   (    (    s0   /usr/lib/python2.7/multiprocessing/connection.pyR3   ^  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…   r  s    N(   R:   R;   R<   R*   R2   R3   t   staticmethodR…   (    (    (    s0   /usr/lib/python2.7/multiprocessing/connection.pyR'   G  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 ‚  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_   RU   RV   R^   R`   Rc   Rd   t   ERROR_SEM_TIMEOUTt   ERROR_PIPE_BUSYR   Ra   R[   R*   RG   Rf   (   R$   R   t   hRm   (    (    s0   /usr/lib/python2.7/multiprocessing/connection.pyR?   x  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
   connectionR1   R‘   t   messageR˜   t   response(    (    s0   /usr/lib/python2.7/multiprocessing/connection.pyR4   œ  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œ   R1   R‘   R   R˜   Rž   (    (    s0   /usr/lib/python2.7/multiprocessing/connection.pyR5   ©  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(   NRJ   R
   t   pollR™   R•   (   s   filenos   closeR¡   s
   recv_bytess
   send_bytes(   t   _connt   _dumpst   _loadsRo   t   setattr(   R/   R   t   dumpst   loadst   attrt   obj(    (    s0   /usr/lib/python2.7/multiprocessing/connection.pyR2   º  s    			c         C   s#   |  j  | ƒ } |  j j | ƒ d  S(   N(   R£   R¢   R•   (   R/   R©   R}   (    (    s0   /usr/lib/python2.7/multiprocessing/connection.pyt   sendÁ  s    c         C   s   |  j  j ƒ  } |  j | ƒ S(   N(   R¢   R™   R¤   (   R/   R}   (    (    s0   /usr/lib/python2.7/multiprocessing/connection.pyt   recvÄ  s    (   R:   R;   R2   Rª   R«   (    (    (    s0   /usr/lib/python2.7/multiprocessing/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©   (    (    s0   /usr/lib/python2.7/multiprocessing/connection.pyt
   _xml_dumpsÈ  s    c         C   s%   t  j |  j d ƒ ƒ \ \ } } | S(   NR¬   (   R­   R§   t   decode(   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   R3   R    R¯   R²   (   R/   R©   (    (    s0   /usr/lib/python2.7/multiprocessing/connection.pyR3   Ð  s    (   R:   R;   R3   (    (    (    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²   (   Rd   t   kwds(    (    s0   /usr/lib/python2.7/multiprocessing/connection.pyt	   XmlClientÖ  s    (6   t   __all__R   t   sysRC   R{   R   R   t	   itertoolsRG   t   multiprocessingR   R   t   multiprocessing.utilR   R   R   R   t   multiprocessing.forkingR	   R
   RW   t   CONNECTION_TIMEOUTt   countR   R&   t   familiest   hasattrt   platformR   R   R   R%   t   objectR   R*   R    RF   R   R   R)   R@   R'   R?   R”   R–   Rš   R›   R4   R5   R    R¯   R²   R³   Rµ   (    (    (    s0   /usr/lib/python2.7/multiprocessing/connection.pyt   <module>#   s`   "				,*.	 1				