ó
[³XMc           @   s@  d  Z  d d l Z d d l m Z d d l m Z d d l m Z d d l m Z d d l	 m
 Z
 d d l m Z d	 e
 j f d
 „  ƒ  YZ d e j f d „  ƒ  YZ d e j f d „  ƒ  YZ d e f d „  ƒ  YZ d e
 j f d „  ƒ  YZ e j d d ƒ d d k rd Z d Z n d Z d Z d e
 j f d „  ƒ  YZ d S(   s0   
Test cases for twisted.protocols.ident module.
iÿÿÿÿN(   t   ident(   t   failure(   t   error(   t   defer(   t   unittest(   t   StringTransportt   ClassParserTestCasec           B   sD   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s*   
    Test parsing of ident responses.
    c         C   s   t  j ƒ  |  _ d S(   s6   
        Create a ident client used in tests.
        N(   R    t   IdentClientt   client(   t   self(    (    s;   /usr/lib/python2.7/dist-packages/twisted/test/test_ident.pyt   setUp   s    c         C   sK   t  j ƒ  } |  j j j | d d f ƒ |  j j d ƒ |  j | t j ƒ S(   sX   
        'UNKNOWN-ERROR' error should map to the L{ident.IdentError} exception.
        i{   iÈ  s    123, 456 : ERROR : UNKNOWN-ERROR(	   R   t   DeferredR   t   queriest   appendt   lineReceivedt   assertFailureR    t
   IdentError(   R	   t   d(    (    s;   /usr/lib/python2.7/dist-packages/twisted/test/test_ident.pyt   test_indentError!   s    c         C   sK   t  j ƒ  } |  j j j | d d f ƒ |  j j d ƒ |  j | t j ƒ S(   sN   
        'NO-USER' error should map to the L{ident.NoUser} exception.
        iê   iÈ  s   234, 456 : ERROR : NO-USER(	   R   R   R   R   R   R   R   R    t   NoUser(   R	   R   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/test/test_ident.pyt   test_noUSerError+   s    c         C   sK   t  j ƒ  } |  j j j | d d f ƒ |  j j d ƒ |  j | t j ƒ S(   sX   
        'INVALID-PORT' error should map to the L{ident.InvalidPort} exception.
        iY  i7  s    345, 567 :  ERROR : INVALID-PORT(	   R   R   R   R   R   R   R   R    t   InvalidPort(   R	   R   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/test/test_ident.pyt   test_invalidPortError5   s    c         C   sK   t  j ƒ  } |  j j j | d d f ƒ |  j j d ƒ |  j | t j ƒ S(   sV   
        'HIDDEN-USER' error should map to the L{ident.HiddenUser} exception.
        i7  i  s   567, 789 : ERROR : HIDDEN-USER(	   R   R   R   R   R   R   R   R    t
   HiddenUser(   R	   R   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/test/test_ident.pyt   test_hiddenUserError?   s    c         C   sZ   t  j ƒ  } |  j j j | d d f ƒ |  j j t j t j	 ƒ  ƒ ƒ |  j
 | t j ƒ S(   sy   
        A pending query which failed because of a ConnectionLost should
        receive an L{ident.IdentError}.
        iý  i°  (   R   R   R   R   R   t   connectionLostR   t   FailureR   t   ConnectionLostR   R    R   (   R	   R   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/test/test_ident.pyt   test_lostConnectionI   s    (	   t   __name__t
   __module__t   __doc__R
   R   R   R   R   R   (    (    (    s;   /usr/lib/python2.7/dist-packages/twisted/test/test_ident.pyR      s   		
	
	
	
t   TestIdentServerc           B   s   e  Z d  „  Z RS(   c         C   s   |  j  S(   N(   t   resultValue(   R	   t   serverAddresst   clientAddress(    (    s;   /usr/lib/python2.7/dist-packages/twisted/test/test_ident.pyt   lookupV   s    (   R   R   R$   (    (    (    s;   /usr/lib/python2.7/dist-packages/twisted/test/test_ident.pyR    U   s   t   TestErrorIdentServerc           B   s   e  Z d  „  Z RS(   c         C   s   |  j  ƒ  ‚ d  S(   N(   t   exceptionType(   R	   R"   R#   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/test/test_ident.pyR$   [   s    (   R   R   R$   (    (    (    s;   /usr/lib/python2.7/dist-packages/twisted/test/test_ident.pyR%   Z   s   t   NewExceptionc           B   s   e  Z RS(    (   R   R   (    (    (    s;   /usr/lib/python2.7/dist-packages/twisted/test/test_ident.pyR'   _   s   t   ServerParserTestCasec           B   s   e  Z d  „  Z d „  Z RS(   c         C   s“  t  ƒ  } | j t ƒ  ƒ g  } | j | _ t j | _ | j d ƒ |  j	 | d d ƒ t j
 | _ | j d ƒ |  j	 | d d ƒ t j | _ | j d ƒ |  j	 | d d	 ƒ t j | _ | j d
 ƒ |  j	 | d d ƒ t | _ | j d ƒ |  j	 | d d ƒ |  j t ƒ } |  j	 t | ƒ d ƒ x^ d D]V } | 2| j d | f ƒ | j d | f ƒ |  j	 | d | f d | f g ƒ q5Wd  S(   Ns   123, 345i    s    123, 345 : ERROR : UNKNOWN-ERRORs   432, 210i   s   432, 210 : ERROR : NO-USERs   987, 654i   s   987, 654 : ERROR : INVALID-PORTs   756, 827i   s   756, 827 : ERROR : HIDDEN-USERs   987, 789i   s    987, 789 : ERROR : UNKNOWN-ERRORiÿÿÿÿi   i  s   %d, 5s   5, %ds   %d, 5 : ERROR : INVALID-PORTs   5, %d : ERROR : INVALID-PORT(   iÿÿÿÿi    i   i  (   R%   t   makeConnectionR   R   t   sendLineR    R   R&   R   t   assertEqualsR   R   R   R'   t   flushLoggedErrorst   len(   R	   t   pt   Lt   errst   port(    (    s;   /usr/lib/python2.7/dist-packages/twisted/test/test_ident.pyt
   testErrorsd   s8    		c         C   sY   t  ƒ  } | j t ƒ  ƒ g  } | j | _ d | _ | j d ƒ |  j | d d ƒ d  S(   Nt   SYSt   USERs   123, 456i    s   123, 456 : USERID : SYS : USER(   R3   R4   (   R    R)   R   R   R*   R!   R   R+   (   R	   R.   R/   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/test/test_ident.pyt   testSuccessˆ   s    		(   R   R   R2   R5   (    (    (    s;   /usr/lib/python2.7/dist-packages/twisted/test/test_ident.pyR(   c   s   	$s   =Li   i    s   t   0100007Ft   04030201t   7F000001t   01020304t   ProcMixinTestCasec           B   sE   e  Z d  e e f Z d „  Z d „  Z d „  Z d „  Z d „  Z	 RS(   sj   4: %s:0019 %s:02FA 0A 00000000:00000000 00:00000000 00000000     0        0 10927 1 f72a5b80 3000 0 0 2 -1c         C   s)   t  j ƒ  } |  j | j t ƒ d ƒ d  S(   Ns	   127.0.0.1(   R    t   ProcServerMixinR+   t   dottedQuadFromHexStringt   _addr1(   R	   R.   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/test/test_ident.pyt   testDottedQuadFromHexString    s    c         C   s-   t  j ƒ  } |  j | j t d ƒ d ƒ d  S(   Ns   :0277s	   127.0.0.1iw  (   s	   127.0.0.1iw  (   R    R;   R+   t   unpackAddressR=   (   R	   R.   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/test/test_ident.pyt   testUnpackAddress¤   s    c         C   s5   t  j ƒ  } |  j | j |  j ƒ d d d f ƒ d  S(   Ns	   127.0.0.1i   s   1.2.3.4iú  i    (   s	   127.0.0.1i   (   s   1.2.3.4iú  (   R    R;   R+   t	   parseLinet   line(   R	   R.   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/test/test_ident.pyt   testLineParser©   s    c            sr   g  ‰  t  j ƒ  } ‡ f d †  | _ ‡  f d †  | _ ˆ j | j d	 d
 ƒ | j d f ƒ ˆ j ˆ  d g ƒ d  S(   Nc              s   t  ˆ  j g ƒ S(   N(   t   iterRB   (    (   R	   (    s;   /usr/lib/python2.7/dist-packages/twisted/test/test_ident.pyt   <lambda>²   s    c            s   ˆ  j  |  ƒ d f d S(   Nt   rooti   (   R   (   t   uid(   t   username(    s;   /usr/lib/python2.7/dist-packages/twisted/test/test_ident.pyRE   ³   s    s	   127.0.0.1i   s   1.2.3.4iú  RF   i    (   s	   127.0.0.1i   (   s   1.2.3.4iú  (   R    R;   t   entriest   getUsernameR+   R$   t   SYSTEM_NAME(   R	   R.   (    (   RH   R	   s;   /usr/lib/python2.7/dist-packages/twisted/test/test_ident.pyt   testExistingAddress¯   s    c            sv   t  j ƒ  } ‡  f d †  | _ ˆ  j t  j | j d	 d
 ƒ ˆ  j t  j | j d d ƒ ˆ  j t  j | j d d ƒ d  S(   Nc              s   t  ˆ  j g ƒ S(   N(   RD   RB   (    (   R	   (    s;   /usr/lib/python2.7/dist-packages/twisted/test/test_ident.pyRE   »   s    s	   127.0.0.1i   s   1.2.3.4iú  i   s   1.2.3.5iû  (   s	   127.0.0.1i   (   s   1.2.3.4iú  (   s	   127.0.0.1i   (   s   1.2.3.5iú  (   s	   127.0.0.1i   (   s   1.2.3.4iû  (   R    R;   RI   t   assertRaisesR   R$   (   R	   R.   (    (   R	   s;   /usr/lib/python2.7/dist-packages/twisted/test/test_ident.pyt   testNonExistingAddress¹   s    (
   R   R   R=   t   _addr2RB   R>   R@   RC   RL   RN   (    (    (    s;   /usr/lib/python2.7/dist-packages/twisted/test/test_ident.pyR:   ›   s   				
(   R   t   structt   twisted.protocolsR    t   twisted.pythonR   t   twisted.internetR   R   t   twisted.trialR   t   twisted.test.proto_helpersR   t   TestCaseR   t   IdentServerR    R%   t   RuntimeErrorR'   R(   t   packR=   RO   R:   (    (    (    s;   /usr/lib/python2.7/dist-packages/twisted/test/test_ident.pyt   <module>   s$   @0	