ó
­«Y]c           @   s/  d  d l  m Z m Z m Z e d ƒ Z e d ƒ 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 Z d Z e r¼ d „  Z n	 d „  Z d	 „  Z d
 „  Z d e j f d „  ƒ  YZ d e j f d „  ƒ  YZ d d „ Z e d k r+e ƒ  n  d S(   iÿÿÿÿ(   t   verboset   run_unittestt   import_modulet   fcntlt   termiosNs   I wish to buy a fish license.
s   For my pet fish, Eric.
c         C   s	   |  GHd  S(   N(    (   t   msg(    (    s   lib/python2.7/test/test_pty.pyt   debug   s    c         C   s   d  S(   N(    (   R   (    (    s   lib/python2.7/test/test_pty.pyR      s    c         C   sB   |  j  d ƒ r |  j d d ƒ S|  j  d ƒ r> |  j d d ƒ S|  S(   Ns   
s   
s   
(   t   endswitht   replace(   t   data(    (    s   lib/python2.7/test/test_pty.pyt   normalize_output&   s
    c         C   s%   t  j |  d d d t ƒ} | j ƒ  S(   s8   Read one line.  May block forever if no newline is read.t   modet   rbt   closefd(   t   iot   FileIOt   Falset   readline(   t   fdt   reader(    (    s   lib/python2.7/test/test_pty.pyt	   _readline;   s    t   PtyTestc           B   s,   e  Z d  „  Z d „  Z d „  Z d „  Z RS(   c         C   sU   t  j  t  j |  j ƒ } |  j t  j  t  j | ƒ |  j t  j d ƒ t  j d ƒ d  S(   Ni    i
   (   t   signalt   SIGALRMt
   handle_sigt
   addCleanupt   alarm(   t   selft	   old_alarm(    (    s   lib/python2.7/test/test_pty.pyt   setUpF   s    c         C   s   |  j  d ƒ d  S(   Ns   isatty hung(   t   fail(   R   t   sigt   frame(    (    s   lib/python2.7/test/test_pty.pyR   N   s    c         C   så  yb t  d ƒ t j ƒ  \ } } t  d | | f ƒ t  d | f ƒ t j | ƒ } t  d | ƒ Wn t k
 r t j d ‚ n X|  j t j	 | ƒ d ƒ t
 j
 | t
 j ƒ } t
 j
 | t
 j | t j Bƒ y& t j | d ƒ } |  j d | ƒ Wn+ t k
 r } | j t j k r!‚  q!n Xt
 j
 | t
 j | ƒ t  d	 ƒ t j | t ƒ t | ƒ } |  j d
 t | ƒ ƒ t  d ƒ t j | t d  ƒ t j | t d ƒ t | ƒ } |  j d t | ƒ ƒ t j | ƒ t j | ƒ d  S(   Ns   Calling master_open()s#   Got master_fd '%d', slave_name '%s's   Calling slave_open(%r)s   Got slave_fd '%d's,   Pseudo-terminals (seemingly) not functional.s   slave_fd is not a ttyi   t    s   Writing to slave_fds   I wish to buy a fish license.
s   Writing chunked outputi   s   For my pet fish, Eric.
(   R   t   ptyt   master_opent
   slave_opent   OSErrort   unittestt   SkipTestt
   assertTruet   ost   isattyR   t   F_GETFLt   F_SETFLt
   O_NONBLOCKt   readt   assertEqualt   errnot   EAGAINt   writet   TEST_STRING_1R   R
   t   TEST_STRING_2t   close(   R   t	   master_fdt
   slave_namet   slave_fdt
   orig_flagst   s1t   et   s2(    (    s   lib/python2.7/test/test_pty.pyt
   test_basicQ   s@    


	
c         C   s  t  d ƒ t j ƒ  \ } } | t j k rè t j d ƒ sT t  d ƒ t j d ƒ n  t  d ƒ y t j ƒ  WnR t k
 r‰ t  d ƒ nO t	 k
 r£ t  d ƒ n5 t  d ƒ t j d ƒ n Xt  d	 ƒ t j d
 ƒ t j d ƒ nt  d | ƒ x[ t
 rSy t j | d ƒ } Wn t k
 r)Pn X| s4Pn  t j j | j d d ƒ ƒ qù Wt j | d ƒ \ } } | d ?} t  d | | | f ƒ | d k r©|  j d ƒ nT | d
 k rÅ|  j d ƒ n8 | d k rá|  j d ƒ n | d k rý|  j d ƒ n  t j | ƒ d  S(   Ns   calling pty.fork()i   s   Child's fd 1 is not a tty?!i   s   In child, calling os.setsid()s   Good: OSError was raised.s   No setsid() available?s   An unexpected error was raised.s   os.setsid() succeeded! (bad!)i   i   s!   Waiting for child (%d) to finish.iP   s   
s   
i    i   s&   Child (%d) exited with status %d (%d).s3   Child raised an unexpected exception in os.setsid()s1   pty.fork() failed to make child a session leader.s8   Child spawned by pty.fork() did not have a tty as stdouts&   pty.fork() failed for unknown reasons.(   R   R"   t   forkt   CHILDR)   R*   t   _exitt   setsidR%   t   AttributeErrort   TrueR.   t   syst   stdoutR2   R   t   waitpidR   R5   (   R   t   pidR6   R	   t   statust   res(    (    s   lib/python2.7/test/test_pty.pyt	   test_fork€   sT    






	 

(   t   __name__t
   __module__R   R   R=   RJ   (    (    (    s   lib/python2.7/test/test_pty.pyR   E   s   			/t   SmallPtyTestsc           B   sD   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s)   These tests don't spawn children or hang.c         C   sC   t  j |  _ t  j |  _ t  j |  _ g  |  _ g  |  _ g  |  _	 d  S(   N(
   R"   t   STDIN_FILENOt   orig_stdin_filenot   STDOUT_FILENOt   orig_stdout_filenot   selectt   orig_pty_selectt   fdst   select_rfds_lengthst   select_rfds_results(   R   (    (    s   lib/python2.7/test/test_pty.pyR   Ø   s    		c         C   sW   |  j  t _ |  j t _ |  j t _ x, |  j D]! } y t j	 | ƒ Wq. q. Xq. Wd  S(   N(
   RO   R"   RN   RQ   RP   RS   RR   RT   R)   R5   (   R   R   (    (    s   lib/python2.7/test/test_pty.pyt   tearDownà   s    c         C   s    t  j ƒ  } |  j j | ƒ | S(   N(   R)   t   pipeRT   t   extend(   R   t   pipe_fds(    (    s   lib/python2.7/test/test_pty.pyt   _pipeê   s    c         C   s;   |  j  |  j j d ƒ t | ƒ ƒ |  j j d ƒ g  g  f S(   Ni    (   R/   RU   t   popt   lenRV   (   R   t   rfdst   wfdst   xfds(    (    s   lib/python2.7/test/test_pty.pyt   _mock_selectï   s    "c   	      C   s‚  |  j  ƒ  \ } } | t _ |  j  ƒ  \ } } | t _ t j ƒ  } g  | D] } | j ƒ  ^ qI } |  j j | ƒ t	 j
 | d d ƒ t	 j
 | d ƒ |  j t _ |  j j d ƒ |  j j | | d g ƒ |  j j d ƒ |  j t ƒ  t j | d ƒ Wd QXt j | | d g g  g  d ƒ d } |  j | | d g | ƒ |  j t	 j | d ƒ d ƒ |  j t	 j | d d ƒ d ƒ d S(   s6   Test the normal data case on both master_fd and stdin.i   s   from masters
   from stdini   i    Ni   (   R[   R"   RP   RN   t   sockett
   socketpairt   filenoRT   RY   R)   R2   Ra   RR   RU   t   appendRV   t   assertRaisest
   IndexErrort   _copyR/   R.   (	   R   t   read_from_stdout_fdt   mock_stdout_fdt   mock_stdin_fdt   write_to_stdin_fdRc   t   st   mastersR^   (    (    s   lib/python2.7/test/test_pty.pyt   test__copy_to_eachô   s&    		&c         C   s  |  j  ƒ  \ } } | t _ |  j  ƒ  \ } } | t _ t j ƒ  } g  | D] } | j ƒ  ^ qI } |  j j | ƒ t	 j
 | d ƒ | d j
 ƒ  t	 j
 | ƒ |  j t _ |  j j d ƒ |  j j | | d g ƒ |  j j d ƒ |  j t ƒ  t j | d ƒ Wd QXd S(   s9   Test the empty read EOF case on both master_fd and stdin.i   i   i    N(   R[   R"   RP   RN   Rb   Rc   Rd   RT   RY   R)   R5   Ra   RR   RU   Re   RV   Rf   Rg   Rh   (   R   Ri   Rj   Rk   Rl   Rc   Rm   Rn   (    (    s   lib/python2.7/test/test_pty.pyt   test__copy_eof_on_all  s     		(	   RK   RL   t   __doc__R   RW   R[   Ra   Ro   Rp   (    (    (    s   lib/python2.7/test/test_pty.pyRM   Õ   s   		
			c         C   s   t  t t ƒ d  S(   N(   R   RM   R   (   R    (    (    s   lib/python2.7/test/test_pty.pyt	   test_main+  s    t   __main__(   t   test.test_supportR    R   R   R   R0   R"   R)   RD   RR   R   Rb   R   R&   R3   R4   R   R
   R   t   TestCaseR   RM   t   NoneRr   RK   (    (    (    s   lib/python2.7/test/test_pty.pyt   <module>   s.   
			
V