ó
Ù>k[c           @   s;  d  d l  Z  d  d l Z d  d l Z y d  d l Z Wn e k
 rS d  d l Z n Xd  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 „  Z y d  d l m Z Wn e k
 rÞ e Z n Xd e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d	 „  ƒ  YZ d
 e f d „  ƒ  YZ d S(   iÿÿÿÿNc         C   sf   t  |  ƒ t  | ƒ k r t Sd } x7 t |  | ƒ D]& \ } } | t | ƒ t | ƒ AO} q2 W| d k S(   sì   Implementation of hmac.compare_digest for python < 2.7.7.

    This function uses an approach designed to prevent timing analysis by
    avoiding content-based short circuiting behaviour, making it appropriate
    for cryptography.
    i    (   t   lent   Falset   zipt   ord(   t   at   bt
   differencet   a_chart   b_char(    (    s/   lib/python2.7/site-packages/rope/base/oi/doa.pyt   _compat_compare_digest   s    (   t   compare_digestt   PythonFileRunnerc           B   sY   e  Z d  Z d d d d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 RS(	   s(   A class for running python project filesc         C   sC   | |  _  | |  _ | |  _ g  |  _ | |  _ | |  _ | |  _ d  S(   N(   t   pycoret   filet   analyze_datat	   observerst   argst   stdint   stdout(   t   selfR   t   file_R   R   R   R   (    (    s/   lib/python2.7/site-packages/rope/base/oi/doa.pyt   __init__*   s    						c         C   sv  t  t j ƒ } |  j j } |  j j j ƒ  |  j j j ƒ  } t j	 j
 d „  | Dƒ ƒ | d <|  j j j d ƒ j } d |  _ |  j ƒ  d } |  j r© |  j j ƒ  } n  t j | | |  j j j |  j j g } |  j d k rì | d d 5n  |  j d k	 r| j |  j ƒ n  t j d t j d | d	 | d
 t j j | ƒ d d |  j d |  j d |  j d t j d k ƒ |  _ d S(   s   Execute the processc         s   s   |  ] } | j  Vq d  S(   N(   t	   real_path(   t   .0t   folder(    (    s/   lib/python2.7/site-packages/rope/base/oi/doa.pys	   <genexpr>:   s   t
   PYTHONPATHs   rope.base.oi.runmodt   -i   i   t
   executableR   t   envt   cwdi    R   R   t   stderrt	   close_fdst   ntN(   t   dictt   ost   environR   R   R   t   projectt   get_source_folderst   get_python_path_folderst   pathsept   joint   find_modulet   Nonet   receivert   _init_data_receivingt   get_send_infot   sysR   t   addressR   R   t   extendt
   subprocesst   Popent   patht   splitR   R   t   namet   process(   R   R   t	   file_patht   path_folderst   runmod_patht	   send_infoR   (    (    s/   lib/python2.7/site-packages/rope/base/oi/doa.pyt   run4   s,    	
		c         C   s|   |  j  d  k r d  St s( t j d k r7 t ƒ  |  _ n t ƒ  |  _ t j	 d |  j
 ƒ |  _ |  j j t ƒ |  j j ƒ  d  S(   NR    t   target(   R   R*   t   TrueR"   R5   t   _SocketReceiverR+   t   _FIFOReceivert	   threadingt   Threadt   _receive_informationt   receiving_threadt	   setDaemont   start(   R   (    (    s/   lib/python2.7/site-packages/rope/base/oi/doa.pyR,   M   s    	c         C   sF   x$ |  j  j ƒ  D] } |  j | ƒ q Wx |  j D] } | ƒ  q1 Wd  S(   N(   R+   t   receive_dataR   R   (   R   t   datat   observer(    (    s/   lib/python2.7/site-packages/rope/base/oi/doa.pyRB   \   s    c         C   s*   |  j  j ƒ  |  j r& |  j j ƒ  n  d S(   s   Wait for the process to finishN(   R6   t   waitR   RC   R(   (   R   (    (    s/   lib/python2.7/site-packages/rope/base/oi/doa.pyt   wait_processe   s    	c         C   s³   |  j  j ƒ  d k	 r d Sy‚ t |  j  d ƒ r> |  j  j ƒ  n\ t j d k rf t j |  j  j d ƒ n4 d d l	 } t
 |  j  j ƒ } | j j j | d ƒ Wn t k
 r® n Xd S(   s   Stop the processNt	   terminateR    i	   iÿÿÿÿ(   R6   t   pollR*   t   hasattrRK   R"   R5   t   killt   pidt   ctypest   intt   _handlet   windllt   kernel32t   TerminateProcesst   OSError(   R   RP   t   handle(    (    s/   lib/python2.7/site-packages/rope/base/oi/doa.pyt   kill_processk   s    c         C   s   |  j  j | ƒ d S(   s,   Notify this observer when execution finishesN(   R   t   append(   R   RH   (    (    s/   lib/python2.7/site-packages/rope/base/oi/doa.pyt   add_finishing_observer{   s    N(   t   __name__t
   __module__t   __doc__R*   R   R;   R,   RB   RJ   RX   RZ   (    (    (    s/   lib/python2.7/site-packages/rope/base/oi/doa.pyR   '   s   							t   _MessageReceiverc           B   s   e  Z d  „  Z d „  Z RS(   c         C   s   d  S(   N(    (   R   (    (    s/   lib/python2.7/site-packages/rope/base/oi/doa.pyRF   ‚   s    c         C   s   d  S(   N(    (   R   (    (    s/   lib/python2.7/site-packages/rope/base/oi/doa.pyR-   …   s    (   R[   R\   RF   R-   (    (    (    s/   lib/python2.7/site-packages/rope/base/oi/doa.pyR^   €   s   	R>   c           B   s#   e  Z d  „  Z d „  Z d „  Z RS(   c         C   s¤   t  j  t  j t  j ƒ |  _ d |  _ t j d ƒ |  _ xW |  j d k  r y |  j j d |  j f ƒ PWq9 t  j	 k
 r‹ |  j d 7_ q9 Xq9 W|  j j
 d ƒ d  S(   NiÝ  i    i   t	   localhosti   (   t   sockett   AF_INETt   SOCK_STREAMt   server_sockett	   data_portR"   t   urandomt   keyt   bindt   errort   listen(   R   (    (    s/   lib/python2.7/site-packages/rope/base/oi/doa.pyR   ‹   s    	c         C   s&   d |  j  t j |  j ƒ j d ƒ f S(   Ns   %d:%ss   utf-8(   Rd   t   base64t	   b64encodeRf   t   decode(   R   (    (    s/   lib/python2.7/site-packages/rope/base/oi/doa.pyR-   ˜   s    	c   
      c   s(  |  j  j ƒ  \ } } |  j  j ƒ  | j d ƒ } xÜ t ry½ | j ƒ  } t | ƒ d k r_ Pn  yF | j d ƒ } t j	 | |  ƒ } | | d d !} t j	 | ƒ } Wn
 w4 n Xt
 j |  j | t j ƒ j ƒ  }	 t | |	 ƒ sè w4 n  t j | ƒ VWq4 t k
 rPq4 Xq4 W| j ƒ  | j ƒ  d  S(   Nt   rbi    t   :i   iÿÿÿÿ(   Rc   t   acceptt   closet   makefileR=   t   readlineR    t   indexRj   t	   b64decodet   hmact   newRf   t   hashlibt   sha256t   digestR
   t   picklet   loadst   EOFError(
   R   t   connt   addrt   my_filet   buft
   digest_endt
   buf_digestt   buf_datat   decoded_buf_dataRy   (    (    s/   lib/python2.7/site-packages/rope/base/oi/doa.pyRF   œ   s.    		!	
(   R[   R\   R   R-   RF   (    (    (    s/   lib/python2.7/site-packages/rope/base/oi/doa.pyR>   ‰   s   		R?   c           B   s,   e  Z d  „  Z d „  Z d „  Z d „  Z RS(   c         C   s#   |  j  ƒ  |  _ t j |  j ƒ d  S(   N(   t   _get_file_namet	   file_nameR"   t   mkfifo(   R   (    (    s/   lib/python2.7/site-packages/rope/base/oi/doa.pyR   Ç   s    c         C   si   t  j ƒ  d } d } x6 t j j | t | ƒ j d d ƒ ƒ rN | d 7} q W| t | ƒ j d d ƒ S(   Ns   /__rope_i    i   t   0i   (   t   tempfilet
   gettempdirR"   R3   t   existst   strt   rjust(   R   t   prefixt   i(    (    s/   lib/python2.7/site-packages/rope/base/oi/doa.pyR…   Ì   s
    +c         C   s   |  j  S(   N(   R†   (   R   (    (    s/   lib/python2.7/site-packages/rope/base/oi/doa.pyR-   Ó   s    c         c   sd   t  |  j d ƒ } x1 t rE y t j | ƒ VWq t k
 rA Pq Xq W| j ƒ  t j |  j ƒ d  S(   NRm   (	   t   openR†   R=   t   marshalt   loadR|   Rp   R"   t   remove(   R   R   (    (    s/   lib/python2.7/site-packages/rope/base/oi/doa.pyRF   Ö   s    		
(   R[   R\   R   R…   R-   RF   (    (    (    s/   lib/python2.7/site-packages/rope/base/oi/doa.pyR?   Å   s   			(   Rj   Rw   Ru   t   cPickleRz   t   ImportErrorR‘   R"   R`   R1   R.   R‰   R@   R	   R
   t   objectR   R^   R>   R?   (    (    (    s/   lib/python2.7/site-packages/rope/base/oi/doa.pyt   <module>   s,   	
Y	<