
    h*                    (   S r SSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKJ	r	  SSK
Jr  SSKJr  SSKJrJrJr  SSKJr  SSKJr  SS	KJrJrJrJrJr  SS
KJr  SSKJrJ r J!r!  SSK"J#r#J$r$J%r%  SSK&J'r'  SSK(J)r)J*r*  SSK+J,r,  \%RZ                  R]                  5       (       d  Sr/OSr/S r0\0" 5       r1S r2 " S S\Rf                  5      r4 " S S\Rj                  5      r6S\S jr7 " S S\,5      r8 " S S\85      r9 " S S\85      r: " S S\85      r; " S  S!\85      r<\2 " S" S#\<5      5       r=\* " S$ S%\<5      5       r> " S& S'\<5      r? " S( S)\<5      r@ " S* S+\,5      rA " S, S-\,5      rB " S. S/\Rj                  5      rC " S0 S1\ R                  5      rE " S2 S3\,5      rF " S4 S5\,5      rG " S6 S7\,5      rH " S8 S9\,5      rI " S: S;\,5      rJ " S< S=\,5      rK " S> S?\,5      rL " S@ SA\,5      rM " SB SC\,5      rN " SD SE\,5      rO " SF SG\,5      rP " SH SI5      rQ " SJ SK\,\Q5      rR\" \5       " SL SM5      5       rS " SN SO5      rT " SP SQ5      rU " SR SS\,\U5      rV\" \ R                  5       " ST SU5      5       rX " SV SW5      rY " SX SY\,5      rZ " SZ S[\,5      r[g)]z
FTP tests.
    N)BytesIO)implementer)verifyClass)checkerscredentialsportal)UnauthorizedLogin)IRealm)defererrorprotocolreactortask)	IConsumer)basicftploopback)failurefilepathruntime)proto_helpers)HAS_IPV6skipWithoutIPv6)TestCasezCannot run on Windowsc                     [         (       d  gSn SnSn [        R                  " [        R                  5      n U R                  S5        U R	                  S5        [        R                  " [        R
                  5      nUR                  SU R                  5       S   45        SnU(       a  UR                  5         U (       a  U R                  5         U$ ! [         a     N<f = f)z?Returns True if the system supports IPv4-mapped IPv6 addresses.FN)::r      	127.0.0.1T)
r   socketAF_INET6bindlistenAF_INETconnectgetsocknameOSErrorclose)serverclienthas_ipv4_mapped_addressess      \/root/1688_scrapy/alibaba-scraper/venv/lib/python3.13/site-packages/twisted/test/test_ftp.py_hasIPv4MappedAddressesr,   %   s    8FF %v/Iav~~.V%7%7%9!%<=>$(! $$  s   BC 
C! C!c                 *    [         (       d  SU l        U $ )Nz<Does not work on systems without IPv4-mapped IPv6 addresses.)HAS_IPV4_MAPPED_ADDRESSESskip)fs    r+   skipWithoutIPv4MappedAddressesr1   A   s    $$OH    c                   6    \ rS rSrSrS rS rS rS rS r	Sr
g)	DummyG   Nc                      / U l         / U l        g N)linesrawDataselfs    r+   __init__Dummy.__init__J   s    
r2   c                 &    U R                   U l        g r7   )factoryr0   r:   s    r+   connectionMadeDummy.connectionMadeN   s    r2   c                 :    U R                   R                  U5        g r7   )r8   appendr;   lines     r+   lineReceivedDummy.lineReceivedQ       

$r2   c                 :    U R                   R                  U5        g r7   )r9   rC   r;   datas     r+   rawDataReceivedDummy.rawDataReceivedT   s    D!r2   c                     g r7    rD   s     r+   lineLengthExceededDummy.lineLengthExceededW   s    r2   )r0   r8   r9   )__name__
__module____qualname____firstlineno__lognamer<   r@   rF   rL   rP   __static_attributes__rO   r2   r+   r4   r4   G   s     G "r2   r4   c                   &    \ rS rSrS rS rS rSrg)_BufferingProtocol[   c                 F    SU l         [        R                  " 5       U l        g Nr2   )bufferr   Deferreddr:   s    r+   r@   !_BufferingProtocol.connectionMade\   s    !r2   c                 .    U =R                   U-  sl         g r7   r]   rJ   s     r+   dataReceived_BufferingProtocol.dataReceived`   s    tr2   c                 :    U R                   R                  U 5        g r7   )r_   callback)r;   reasons     r+   connectionLost!_BufferingProtocol.connectionLostc   s    r2   )r]   r_   N)rR   rS   rT   rU   r@   rc   rh   rW   rO   r2   r+   rY   rY   [   s    "r2   rY   c                 l    S[         R                  " X5       S3nUR                  U R                  5      $ )z
Construct a passive mode message with the correct encoding

@param protocol: the FTP protocol from which to base the encoding
@param host: the hostname
@param port: the port
@return: the passive mode message
z227 Entering Passive Mode (z).)r   encodeHostPortencode	_encoding)r   hostportmsgs       r+   passivemode_msgrq   g   s3     ((:(:4(F'Gr
JC::h(())r2   c                   d    \ rS rSrSr\R                  rSrSr	S r
SS jrSS jrS	 rS
 rS rSrg)FTPServerTestCaset   zk
Simple tests for an FTP server with the default settings.

@ivar clientFactory: class used as ftp client.
	anonymousr   c                 *  ^ ^	^
^ / mT R                  5       T l        [        R                  " T R                  5        [        R
                  " T R                  5      T l        [        R                  " [        R                  " T R                  T R                  S95      nUR                  [        R                  " 5       [        R                  5        [        R                   " 5       nST l        ST l        UR'                  T R"                  T R$                  5        UR                  U[        R(                  5        [        R*                  " UT R,                  S9T l        [0        R2                  " ST R.                  T R4                  S9=T l        nT R9                  UR:                  5        T R.                  R<                  m	[>        R@                  " 5       m
U	U
UU 4S jnUT R.                  l        URC                  5       R6                  n[D        RF                  " [0        T RH                  5      nURK                  SU5      nUU 4S	 jnURM                  U5        T R9                  [N        RP                  [0        T5        [>        RR                  " T
U/5      $ )
N)anonymousRootuserHomez	test-userztest-password)r   userAnonymousr   	interfacec                    > TR                   ?T" U 5      nUR                  Tl        U4S jnTR	                  U5        TR                  S 5        TR                  U5        U$ )Nc                  ~   > T R                   R                  b%  T R                   R                  R                  5         g g r7   serverProtocol	transportloseConnectionr:   s   r+   cleanupServerQFTPServerTestCase.setUp.<locals>._rememberProtocolInstance.<locals>.cleanupServer   s2    &&00<''11@@B =r2   )r?   buildProtocolwrappedProtocolr   
addCleanuprf   rC   )addrr   r   r   d1	protocolsr;   s      r+   _rememberProtocolInstance:FTPServerTestCase.setUp.<locals>._rememberProtocolInstance   sX    *$T*H"*":":DC OOM*KKX&Or2   r   c                    > U Tl         TR                  TR                   R                  R                  5        TR	                  TR                   5        g r7   )r)   r   r   r   rC   )r)   r   r;   s    r+   	gotClient*FTPServerTestCase.setUp.<locals>.gotClient   s8     DKOODKK11@@AT[[)r2   )*mktemp	directoryosmkdirr   FilePathdirPathr   Portalr   FTPRealmregisterCheckerr   AllowAnonymousAccessr   
IAnonymous'InMemoryUsernamePasswordDatabaseDontUseusernamepasswordaddUserIUsernamePassword
FTPFactoryry   r?   r   	listenTCPbindAddressro   r   stopListeningr   r   r^   getHostr   ClientCreatorclientFactory
connectTCPaddCallbackr   waitUntilAllDisconnectedgatherResults)r;   pusers_checkerro   r   portNumclientCreatord2r   r   r   r   s   `        @@@r+   setUpFTPServerTestCase.setUp   s    	 
 ((8 MMLL"nn
 	
(779;;Q;QR HHJ#'dmmT]];	-)F)FG~~Qd>P>PQ",,t||t'7'7
 	
	D 	**+ 22^^	 	  &?" ,,.%% ..w8J8JK%%k7;	*
 	y!>>S""B8,,r2   Nc                 l   ^ ^^ Uc  [         R                  " S5      nUUU 4S jnUR                  U5      $ )z
Asserts that a sending an FTP command receives the expected
response.

Returns a Deferred.  Optionally accepts a deferred to chain its actions
to.
Nc                 j   > TR                   R                  T5      nUU4S jnUR                  U5      $ )Nc                 *   > TR                  TU 5        g r7   assertEqual)responseLinesexpectedResponseLinesr;   s    r+   gotResponseRFTPServerTestCase.assertCommandResponse.<locals>.queueCommand.<locals>.gotResponse   s      !6Fr2   r)   queueStringCommandr   )ignoredr_   r   commandr   r;   s      r+   queueCommand=FTPServerTestCase.assertCommandResponse.<locals>.queueCommand   s.    ..w7AG ==--r2   )r   succeedr   )r;   r   r   chainDeferredr   s   ```  r+   assertCommandResponse'FTPServerTestCase.assertCommandResponse   s1      !MM$/M	. ((66r2   c                    ^ ^^ Uc  [         R                  " S 5      nUU 4S jnUR                  U5        T R                  U[        R
                  5        UU 4S jnUR                  U5      $ )Nc                 :   > TR                   R                  T5      $ r7   r)   r   )r   r   r;   s    r+   r   ;FTPServerTestCase.assertCommandFailed.<locals>.queueCommand   s    ;;11'::r2   c                 L   > Tb   TR                  TU R                  S   5        g g Nr   r   args)	exceptionexpectedResponser;   s    r+   failed5FTPServerTestCase.assertCommandFailed.<locals>.failed   s(    +  !19>>!3DE ,r2   )r   r   r   assertFailurer   CommandFailed)r;   r   r   r   r   r   s   ```   r+   assertCommandFailed%FTPServerTestCase.assertCommandFailed   s[     !MM$/M	; 	!!,/=#*;*;<	F ((00r2   c                 L    U R                  SS/5      nU R                  SS/US9$ )NUSER anonymous8331 Guest login ok, type your email address as password.PASS test@twistedmatrix.com2230 Anonymous login ok, access restrictions apply.r   r   r;   r_   s     r+   _anonymousLogin!FTPServerTestCase._anonymousLogin   sA    &&GH
 )))AB * 
 	
r2   c                     U R                  SU R                  -  SU R                  -  /5      nU R                  SU R                  -  S/US9$ )z`
Authenticates the FTP client using the test account.

@return: L{Deferred} of command response
zUSER %sz331 Password required for %s.zPASS %sz230 User logged in, proceedr   )r   r   r   r   s     r+   
_userLoginFTPServerTestCase._userLogin   s^     &&',>?
 ))'*+ * 
 	
r2   c                     [         R                  " SU5      nU R                  USU 35        [        R                  " UR                  S5      5      $ )z
Decode an FTP response specifying a protocol/address/port combination,
using the syntax defined in RFC 2428 sections 2 and 3.

@return: a 3-tuple of (protocol, host, port).
z\((.*)\)zNo extended address found in r   )researchassertIsNotNoner   decodeExtendedAddressgroup)r;   rE   matchs      r+   decodeExtendedAddressLine+FTPServerTestCase.decodeExtendedAddressLine  sE     		+t,U&CD6$JK((Q88r2   )r)   r   r   r?   r   ro   r   r   r7   )NN)rR   rS   rT   rU   __doc__r   FTPClientBasicr   ry   r   r   r   r   r   r   r   rW   rO   r2   r+   rs   rs   t   s>     &&MMKC-J7*1 	

 	9r2   rs   c                   "    \ rS rSrSrSrS rSrg)FTPAnonymousTestsi  z
Simple tests for an FTP server with different anonymous username.
The new anonymous username used in this test case is "guest"
guestc                 L    U R                  SS/5      nU R                  SS/US9$ )z
Tests whether the changing of the anonymous username is working or not.
The FTP server should not comply about the need of password for the
username 'guest', letting it login as anonymous asking just an email
address as password.
z
USER guestr   r   r   r   r   r   s     r+   test_anonymousLogin%FTPAnonymousTests.test_anonymousLogin  sC     &&UV
 )))AB * 
 	
r2   rO   N)rR   rS   rT   rU   r   ry   r   rW   rO   r2   r+   r   r     s    
 M
r2   r   c                       \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rS rS rS rS rS rS rS rS r\S 5       rS rS rS rS rS rS rS rS rS rS r S r!S r"S  r#S! r$S" r%S# r&S$ r'S%r(g&)'BasicFTPServerTestsi)  z$
Basic functionality of FTP server.
c                   ^  ST R                   l        [        R                  " [        [
        5      nUR                  ST R                  R                  5       R                  5      nUR                  S 5       nUR                  U 4S j5       nU$ )zV
When the connection limit is reached, the server should send an
appropriate response
r   r   c                     U R                   $ r7   )r_   )protos    r+   r   >BasicFTPServerTests.test_tooManyConnections.<locals>.gotClient7  s    77Nr2   c                 >   > TR                  SU R                  5        g )Ns;   421 Too many users right now, try again in a few minutes.
r   r]   )r   r;   s    r+   onConnectionLostEBasicFTPServerTests.test_tooManyConnections.<locals>.onConnectionLost;  s    Tr2   )
r?   connectionLimitr   r   r   rY   r   ro   r   r   )r;   ccr_   r   r   s   `    r+   test_tooManyConnections+BasicFTPServerTests.test_tooManyConnections.  s|    
 ()$##G-?@MM+tyy'8'8':'?'?@	
	 
	 
	 
	 r2   c                   ^  / SQnS/nU 4S jnU 4S jn/ nU H`  nT R                   R                  U5      nT R                  U[        R                  5        UR                  X65        UR                  U5        Mb     U H@  nT R                   R                  U5      nUR                  XF5        UR                  U5        MB     [        R                  " USS9$ )z
When not logged in, most commands other than USER and PASS should
get NOT_LOGGED_IN errors, but some can be called before USER and PASS.
)
CDUPCWDLISTMODEPASVPWDRETRSTRUSYSTTYPEFEATc                    > U R                   S   nTR                  US   R                  S5      U< SUS   < 35        g )Nr   530z# - Response didn't start with 530: )r   
assertTrue
startswith)r   r   failureResponseLinesr;   s      r+   checkFailResponseDBasicFTPServerTests.test_NotLoggedInReply.<locals>.checkFailResponseX  sC    #,>>!#4 OO$R(33E: (,r2   c                 `   > U S   n TR                  U R                  S5      U< SU < 35        g )Nr   r  z - Response start with 530: )assertFalser  )resultr   r;   s     r+   checkPassResponseDBasicFTPServerTests.test_NotLoggedInReply.<locals>.checkPassResponsec  s5    AYF!!%( r2   TfireOnOneErrback)	r)   r   r   r   r   r   rC   r   DeferredList)r;   loginRequiredCommandListloginNotRequiredCommandListr  r  	deferredsr   deferreds   `       r+   test_NotLoggedInReply)BasicFTPServerTests.test_NotLoggedInReplyD  s    
$
  (.h#				 	/G{{55g>Hx):):;  !2<X&	 0 3G{{55g>H  !2<X& 3
 !!)dCCr2   c                 (    U R                  SS/5      $ )z0
Issuing PASS before USER should give an error.
zPASS fooz=503 Incorrect sequence of commands: USER required before PASSr   r:   s    r+   test_PASSBeforeUSER'BasicFTPServerTests.test_PASSBeforeUSER|  s      ''LM
 	
r2   c                 (    U R                  SS/5      $ )z4
Issuing USER without a username is a syntax error.
USERz,500 Syntax error: USER requires an argument.r#  r:   s    r+   test_NoParamsForUSER(BasicFTPServerTests.test_NoParamsForUSER  s      ''CD
 	
r2   c                 \    U R                   R                  S5      nU R                  SS/US9$ )z4
Issuing PASS without a password is a syntax error.
USER fooPASSz,500 Syntax error: PASS requires an argument.r   )r)   r   r   r   s     r+   test_NoParamsForPASS(BasicFTPServerTests.test_NoParamsForPASS  s<     KK**:6''CDTU ( 
 	
r2   c                    ^  S nUT R                   R                  l        T R                  R	                  S5      nT R                  SS/US9  UR                  U 4S j5       nU$ )z9
Unexpected exceptions from the login handler are caught
c                  @    [         R                  " [        S5      5      $ )Nztest exceptionr   failAssertionError)r   kwargss     r+   _fake_loginhandler?BasicFTPServerTests.test_loginError.<locals>._fake_loginhandler  s    ::n-=>??r2   r+  zPASS barz5550 Requested action not taken: internal server errorr   c                    > TR                  5       nTR                  S[        U5      5        TR                  US   R                  [
        5        g )Nr   r   flushLoggedErrorsr   lenassertIsInstancevaluer3  r  logsr;   s     r+   	checkLogs6BasicFTPServerTests.test_loginError.<locals>.checkLogs  s=    ))+DQD	*!!$q'--@r2   )r   r   loginr)   r   r   r   )r;   r5  r_   r?  s   `   r+   test_loginError#BasicFTPServerTests.test_loginError  ss    
	@ ,>""(KK**:6  DE 	! 	
 
	A 
	A
 r2   c                 "    U R                  5       $ )z
Login with userid 'anonymous'
r   r:   s    r+   test_AnonymousLogin'BasicFTPServerTests.test_AnonymousLogin  s     ##%%r2   c                 F    U R                  5       nU R                  SS/US9$ )zU
Issuing QUIT should return a 221 message.

@return: L{Deferred} of command response
QUITz221 Goodbye.r   r   r   r   s     r+   	test_QuitBasicFTPServerTests.test_Quit  s.       "))&>2BRS)TTr2   c                 (   SU R                   l        [        R                  " 5       nU R                   R                  R                  U[        R                  5        U R                  SS/5      nU R                  SS/US9nU R                  SS/US9nU$ )	z
Reconfigure the server to disallow anonymous access, and to have an
IUsernamePassword checker that always rejects.

@return: L{Deferred} of command response
Fr   z$331 Password required for anonymous.r   z!530 Sorry, Authentication failed.r   r  z$530 Please login with USER and PASS.)
r?   allowAnonymousr   r   r   r   r   r   r   r   )r;   denyAlwaysCheckerr_   s      r+   test_AnonymousLoginDenied-BasicFTPServerTests.test_AnonymousLoginDenied  s     ',#$LLN++{<<	

 &&EF

 $$)01 % 
 $$:;1 % 
 r2   c                 F    U R                  5       nU R                  SS/US9$ )z
When an anonymous user attempts to edit the server-side filesystem, they
will receive a 550 error with a descriptive message.

@return: L{Deferred} of command response
z
MKD newdirz:550 Anonymous users are forbidden to change the filesystemr   r   r   r   s     r+   test_anonymousWriteDenied-BasicFTPServerTests.test_anonymousWriteDenied  s6       "''IJ ( 
 	
r2   c                 F    U R                  5       nU R                  SS/US9$ )zD
Send an invalid command.

@return: L{Deferred} of command response
	GIBBERISHz'502 Command 'GIBBERISH' not implementedr   rS  r   s     r+   test_UnknownCommand'BasicFTPServerTests.test_UnknownCommand  s6       "''CDTU ( 
 	
r2   c                 F    U R                  5       nU R                  SS/US9$ )zJ
Send RETR before sending PORT.

@return: L{Deferred} of command response
RETR foozR503 Incorrect sequence of commands: PORT, PASV, EPRT, or EPSV required before RETRr   rS  r   s     r+   test_RETRBeforePORT'BasicFTPServerTests.test_RETRBeforePORT  =       "''A  ( 
 	
r2   c                 F    U R                  5       nU R                  SS/US9$ )zJ
Send STOR before sending PORT.

@return: L{Deferred} of command response
zSTOR foozR503 Incorrect sequence of commands: PORT, PASV, EPRT, or EPSV required before STORr   rS  r   s     r+   test_STORBeforePORT'BasicFTPServerTests.test_STORBeforePORT  r^  r2   c                 n    U R                  5       nU R                  SS/US9  U R                  SS/US9  U$ )zL
Send command with bad arguments.

@return: L{Deferred} of command response
zMODE zz&504 Not implemented for parameter 'z'.r   zSTRU Iz&504 Not implemented for parameter 'I'.rS  r   s     r+   test_BadCommandArgs'BasicFTPServerTests.test_BadCommandArgs  sY       "  ?@PQ 	! 	
 	  ?@PQ 	! 	
 r2   c                 0   U R                  [        R                  " S5      S5        [        S5      n[        S5       HV  n[	        U5      nSX2'   SR                  [        [        U5      5      nU R                  [        [        R                  U5        MX     g)z
Decode a host port.
z25,234,129,22,100,23)z25.234.129.22id        ,N)
r   r   decodeHostPortrangelistjoinmapstrassertRaises
ValueError)r;   numsibadValuess        r+   test_DecodeHostPort'BasicFTPServerTests.test_DecodeHostPort$  sz     	568P	
 QxqADzHHKS(+,Aj#*<*<a@	 r2   c                    ^  T R                  5       nUR                  U 4S j5        U 4S jnUR                  U5        UR                  U 4S j5        U$ )zu
When the client sends the command C{PASV}, the server responds with a
host and port, and is listening on that port.
c                 :   > TR                   R                  S5      $ )Nr  r   _r;   s    r+   <lambda>/BasicFTPServerTests.test_PASV.<locals>.<lambda>:       > >v Fr2   c                    > [         R                  " U S   SS 5      u  pTR                  UTR                  R                  R                  5       R                  5        g)zm
Extract the host and port from the resonse, and
verify the server is listening of the port it claims to be.
r     N)r   ri  r   r   dtpPortr   ro   )r   rn   ro   r;   s      r+   cb)BasicFTPServerTests.test_PASV.<locals>.cb<  sN    
 ++M",=ab,ABJDT4#6#6#>#>#F#F#H#M#MNr2   c                 L   > TR                   R                  R                  5       $ r7   r~   ry  s    r+   r{  r|  F       3 3 = = L L Nr2   r   r   r;   r_   r  s   `  r+   	test_PASVBasicFTPServerTests.test_PASV2  sF       "	FG	O 	
b	NOr2   c                   ^  [         R                  " ST R                  SS9nT R                  UR                  5        UR                  5       R                  n[        R                  " [         T R                  5      nUR                  SU5      nU 4S jnUR                  U5        UR                  U 4S j5        T R                  SS/US9$ )	zI
The C{PASV} command is rejected for IPv6 clients.  Use C{EPSV}
instead.
r   ::1rz   c                 r   > U Tl         TR                  TR                   R                  R                  5        g r7   )r)   r   r   r   )r)   r;   s    r+   r   <BasicFTPServerTests.test_PASVDeniedIfIPv6.<locals>.gotClientU  s&     DKOODKK11@@Ar2   c                 $   > TR                  5       $ r7   rE  ry  s    r+   r{  ;BasicFTPServerTests.test_PASVDeniedIfIPv6.<locals>.<lambda>Z  s     4 4 6r2   r  z3502 PASV available only for IPv4 (use EPSV instead)r   )r   r   r?   r   r   r   ro   r   r   r   r   r   r   )r;   ro   r   r   r_   r   s   `     r+   test_PASVDeniedIfIPv6)BasicFTPServerTests.test_PASVDeniedIfIPv6I  s       DLLEB**+,,.%% ..w8J8JK$$UG4	B 	
i 	67''BC ( 
 	
r2   c                 n    U R                  5       nU R                  SS/US9  U R                  SS/US9  U$ )zZ
When the client sends the command C{EPSV ALL}, a subsequent C{PASV}
command is rejected.
EPSV ALL200 EPSV ALL OKr   r  zD503 Incorrect sequence of commands: may not send PASV after EPSV ALLr   r   r   r   s     r+   test_EPSVALLBeforePASV*BasicFTPServerTests.test_EPSVALLBeforePASVa  sR    
   """:0A/BRS"T  ST 	! 	

 r2   c                    ^  T R                  5       nUR                  U 4S j5        U 4S jnUR                  U5        UR                  U 4S j5        U$ )zl
When the client sends the command C{EPSV}, the server responds with a
port, and is listening on that port.
c                 :   > TR                   R                  S5      $ NEPSVr   ry  s    r+   r{  /BasicFTPServerTests.test_EPSV.<locals>.<lambda>u  r}  r2   c                    > TR                  U S   SS 5      u    pTR                  UTR                  R                  R	                  5       R
                  5        gze
Extract the port from the response, and verify the server is
listening on the port it claims to be.
r  r  Nr   r   r   r  r   ro   r   rz  ro   r;   s      r+   r  )BasicFTPServerTests.test_EPSV.<locals>.cbw  P    
 77b8I!"8MNJAqT4#6#6#>#>#F#F#H#M#MNr2   c                 L   > TR                   R                  R                  5       $ r7   r~   ry  s    r+   r{  r    r  r2   r  r  s   `  r+   	test_EPSVBasicFTPServerTests.test_EPSVo  sF    
   "	FG	O 	
b	NOr2   c                    ^  T R                  5       nUR                  U 4S j5        U 4S jnUR                  U5        UR                  U 4S j5        U$ )z
When the client sends the command C{EPSV} with a network protocol
number, the server responds with a port, and is listening on that
port.
c                 :   > TR                   R                  S5      $ )NzEPSV 2r   ry  s    r+   r{  ;BasicFTPServerTests.test_EPSVWithProtocol.<locals>.<lambda>  s     > >x Hr2   c                    > TR                  U S   SS 5      u    pTR                  UTR                  R                  R	                  5       R
                  5        gr  r  r  s      r+   r  5BasicFTPServerTests.test_EPSVWithProtocol.<locals>.cb  r  r2   c                 L   > TR                   R                  R                  5       $ r7   r~   ry  s    r+   r{  r    r  r2   r  r  s   `  r+   test_EPSVWithProtocol)BasicFTPServerTests.test_EPSVWithProtocol  sF       "	HI	O 	
b	NOr2   c                 n    U R                  5       nU R                  SS/US9  U R                  SS/US9  U$ )zC
Sending EPSV with a bad protocol number returns a suitable error.
zEPSV nonsense)501 syntax error in argument(s) nonsense.r   z
EPSV 65535-522 Network protocol not supported, use (1,2)rS  r   s     r+   test_EPSVWithBadProtocol,BasicFTPServerTests.test_EPSVWithBadProtocol  sY       "  89 	! 	

 	  <= 	! 	

 r2   c                    ^  T R                  5       nT R                  SS/US9  UR                  U 4S j5        U 4S jnUR                  U5        UR                  U 4S j5        U$ )z=
The client may send the command C{EPSV ALL} before C{EPSV}.
r  r  r   c                 :   > TR                   R                  S5      $ r  r   ry  s    r+   r{  <BasicFTPServerTests.test_EPSVALLBeforeEPSV.<locals>.<lambda>  r}  r2   c                    > TR                  U S   SS 5      u    pTR                  UTR                  R                  R	                  5       R
                  5        gr  r  r  s      r+   r  6BasicFTPServerTests.test_EPSVALLBeforeEPSV.<locals>.cb  r  r2   c                 L   > TR                   R                  R                  5       $ r7   r~   ry  s    r+   r{  r    r  r2   )r   r   r   r  s   `  r+   test_EPSVALLBeforeEPSV*BasicFTPServerTests.test_EPSVALLBeforeEPSV  s`       """:0A/BRS"T	FG	O 	
b	NOr2   c                     U R                  5       nU R                  SS/US9  U R                  S[        R                  " SS5      -   S/US9  U$ )zZ
When the client sends the command C{EPSV ALL}, a subsequent C{PORT}
command is rejected.
r  r  r   PORT r   r   zD503 Incorrect sequence of commands: may not send PORT after EPSV ALL)r   r   r   r   rk   r   s     r+   test_EPSVALLBeforePORT*BasicFTPServerTests.test_EPSVALLBeforePORT  sd    
   """:0A/BRS"T  c((a88ST 	! 	

 r2   c                 n    U R                  5       nU R                  SS/US9  U R                  SS/US9  U$ )zZ
When the client sends the command C{EPSV ALL}, a subsequent C{EPRT}
command is rejected.
r  r  r   zEPRT |1|127.0.0.1|0|zD503 Incorrect sequence of commands: may not send EPRT after EPSV ALLr  r   s     r+   test_EPSVALLBeforeEPRT*BasicFTPServerTests.test_EPSVALLBeforeEPRT  sR    
   """:0A/BRS"T  "ST 	! 	

 r2   c                 J    U R                  5       nU R                  SS/US9  U$ )z/
SYST command will always return UNIX Type: L8
r	  z215 UNIX Type: L8r   rJ  r   s     r+   	test_SYSTBasicFTPServerTests.test_SYST  s1       """6,?+@PQ"Rr2   c                   ^  T R                   R                  T R                  5      R                  5         T R                   R                  T R                  5      R                  S5      R	                  5         T R                  5       nT R                  SS/US9  T R                  SS/US9  U 4S jnUR                  U5        U$ )zn
Sending the RNFR command followed by RNTO, with valid filenames, will
perform a successful rename operation.
fooRNFR foo6350 Requested file action pending further information.r   zRNTO bar&250 Requested File Action Completed OKc                    > TR                  TR                  R                  TR                  5      R                  S5      R	                  5       5        U $ Nbar)r  r   childr   existsr  r;   s    r+   check_rename:BasicFTPServerTests.test_RNFRandRNTO.<locals>.check_rename  s;    OODLL..t}}=CCEJQQSTMr2   )r   r  r   createDirectorytouchr   r   r   )r;   r_   r  s   `  r+   test_RNFRandRNTO$BasicFTPServerTests.test_RNFRandRNTO  s     	4==)99;4==)//6<<>OO""EF 	# 	

 	""ABRS 	# 	
	 	
l#r2   c                 n    U R                  5       nU R                  SS/US9  U R                  SS/US9  U$ )z
Sending the RNFR command followed by any command other than RNTO
should return an error informing users that RNFR should be followed
by RNTO.
r  r  r   zOTHER don-tcarez<503 Incorrect sequence of commands: RNTO required after RNFRr  r   s     r+   test_RNFRwithoutRNTO(BasicFTPServerTests.test_RNFRwithoutRNTO  sY       """EF 	# 	

 	  KL 	! 	

 r2   c                     S nXR                   l        U R                  [        U R                   R                  [
        R                  " 5       5        g)z
Exceptions other than L{error.CannotListenError} which are raised by
C{listenFactory} should be raised to the caller of L{FTP.getDTPPort}.
c                     [        5       er7   )RuntimeError
portNumberr?   r4  s      r+   listenFactoryEBasicFTPServerTests.test_portRangeForwardError.<locals>.listenFactory  s
    . r2   N)r   r  ro  r  
getDTPPortr   Factory)r;   r  s     r+   test_portRangeForwardError.BasicFTPServerTests.test_portRangeForwardError  s?    	! -:)$--88(:J:J:L	
r2   c                 &   S nXR                   l        U R                   R                  [        R                  " 5       5      nU R                  US5        [        SS5      U R                   l        U R                   R                  [        R                  " 5       5      nU R                  US5        [        SS5      U R                   l        U R                  [        R                  U R                   R                  [        R                  " 5       5        g)a  
L{FTP.passivePortRange} should determine the ports which
L{FTP.getDTPPort} attempts to bind. If no port from that iterator can
be bound, L{error.CannotListenError} should be raised, otherwise the
first successful result from L{FTP.listenFactory} should be returned.
c                 B    U S;   a  [         R                  " SU S5      eU $ )N)V  iV  iV  	localhostr   )r   CannotListenErrorr  s      r+   r  9BasicFTPServerTests.test_portRange.<locals>.listenFactory%  s&    22--k:wOOr2   r   r  i   iV  N)r   r  r  r   r  r   rj  passivePortRangero  r   r  )r;   r  ro   s      r+   test_portRange"BasicFTPServerTests.test_portRange  s    	
 -:)""--h.>.>.@Aq!/4UE/B,""--h.>.>.@Au%/4UE/B,##T%8%8%C%CXEUEUEW	
r2   c                     [        SS5      nXR                  l        U R                  R                  S5      nU R	                  XR
                  R                  5        g)z
The L{FTP} instances created by L{ftp.FTPFactory.buildProtocol} have
their C{passivePortRange} attribute set to the same object the
factory's C{passivePortRange} attribute is set to.
i  i  N)rj  r?   r  r   r   r   )r;   	portRanger   s      r+   "test_portRangeInheritedFromFactory6BasicFTPServerTests.test_portRangeInheritedFromFactory8  sH     $%	(1%<<--d3$<$<$M$MNr2   c                 h   ^  T R                   R                  S5      nU 4S jnUR                  U5      $ )z
When the server receives 'FEAT', it should report the list of supported
features. (Additionally, ensure that the server reports various
particular features that are supported by all Twisted FTP servers.)
r  c                    > TR                  SU S   5        TR                  SU 5        TR                  SU 5        TR                  SU 5        TR                  SU 5        TR                  SU S   5        g )	Nz211-Features:r   z MDTMz PASVz	 TYPE A;Iz SIZEz211 Endr  )r   assertIn)r   r;   s    r+   r   2BasicFTPServerTests.test_FEAT.<locals>.gotResponseK  se    _mA.>?MM'=1MM'=1MM+}5MM'=1Yb(9:r2   r   )r;   r_   r   s   `  r+   	test_FEATBasicFTPServerTests.test_FEATC  s/     KK**62	; }}[))r2   c                 J    U R                  5       nU R                  SS/US9  U$ )z
When the server receives 'OPTS something', it should report
that the FTP server does not support the option called 'something'.
zOPTS somethingz'502 Option 'something' not implemented.r   rS  r   s     r+   	test_OPTSBasicFTPServerTests.test_OPTSU  s8    
   "  67 	! 	

 r2   c                   ^  T R                   R                  T R                  5      R                  5         T R                   R                  T R                  5      R                  S5      R                  5         T R	                  5       nU 4S jnU 4S jnUR                  U5        UR                  U5        T R                  SS/US9  U$ )zT
Any FTP error raised inside STOR while opening the file is returned
to the client.
folderc                 :   > TR                   R                  S5      $ )z-
Send the PASV command required before port.
r  r   r  s    r+   sendPASVCBasicFTPServerTests.test_STORreturnsErrorFromOpen.<locals>.sendPASVn  s     ;;11&99r2   c                    > TR                   R                  R                  R                  S5        [	        5       TR                   l        U $ )zs
Fake an incoming connection and create a mock DTPInstance so
that PORT command will start processing the request.
N)r   
dtpFactoryr  rf   objectdtpInstancer  s    r+   mockDTPInstanceJBasicFTPServerTests.test_STORreturnsErrorFromOpen.<locals>.mockDTPInstancet  s:    
 **33<<TB.4hD+Mr2   zSTOR folderz550 folder: is a directoryr   )r   r  r   r  r   r   r   )r;   r_   r  r  s   `   r+   test_STORreturnsErrorFromOpen1BasicFTPServerTests.test_STORreturnsErrorFromOpenb  s     	4==)99;4==)//9IIKOO	:	 	
h	o&  )* 	! 	

 r2   c                    ^ ^ T R                  5       nS mU 4S jnUU 4S jnU 4S jnUR                  U5        UR                  U5        T R                  SS/US9  UR                  U5        U$ )z
Any non FTP error raised inside STOR while opening the file is
converted into FileNotFound error and returned to the client together
with the path.

The unknown error is logged.
c                 >    [         R                  " [        5       5      $ )zW
Override openForWriting.

@param ignore: ignored, used for callback
@return: an error
r1  )ignores    r+   failingOpenForWriting[BasicFTPServerTests.test_STORunknownErrorBecomesFileNotFound.<locals>.failingOpenForWriting  s     ::n.//r2   c                 :   > TR                   R                  S5      $ )z[
Send the PASV command required before port.

@param result: parameter used in L{Deferred}
r  r   r  s    r+   r  NBasicFTPServerTests.test_STORunknownErrorBecomesFileNotFound.<locals>.sendPASV  s     ;;11&99r2   c                    > TR                   R                  R                  R                  S5        [	        5       TR                   l        TTR                   R                  l        U $ )z
Fake an incoming connection and create a mock DTPInstance so
that PORT command will start processing the request.

@param result: parameter used in L{Deferred}
N)r   r  r  rf   r   r  shellopenForWriting)r  r	  r;   s    r+   r  UBasicFTPServerTests.test_STORunknownErrorBecomesFileNotFound.<locals>.mockDTPInstance  sN     **33<<TB.4hD+7LD%%4Mr2   c                    > TR                  5       nTR                  S[        U5      5        TR                  US   R                  [
        5        g)zU
Check that unknown errors are logged.

@param result: parameter used in L{Deferred}
r   r   Nr8  r=  s     r+   r?  OBasicFTPServerTests.test_STORunknownErrorBecomesFileNotFound.<locals>.checkLogs  s?     ))+DQD	*!!$q'--@r2   zSTOR somethingz)550 something: No such file or directory.r   )r   r   r   )r;   r_   r  r  r?  r	  s   `    @r+   (test_STORunknownErrorBecomesFileNotFound<BasicFTPServerTests.test_STORunknownErrorBecomesFileNotFound  sr     OO	0	:
		A 	
h	o&  89 	! 	

 	
i r2   )r)   N))rR   rS   rT   rU   r   r   r   r$  r(  r-  rB  rF  rK  rP  rT  rX  r\  r`  rc  ru  r  r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rW   rO   r2   r+   r   r   )  s    ,6Dp


0&U>
	

 
 A. 
 
.(*"(4&

6	O*$"H:r2   r   c                   H    \ rS rSrSr\R                  rS rS r	S r
S rSrg)	FTPServerAdvancedClientTestsi  z2
Test FTP server with the L{ftp.FTPClient} class.
c                    ^  U 4S jnT R                   R                  S5      u  p#UR                  U5        [        R                  " X#/5      $ )zT
Try to make an STOR as anonymous, and check that we got a permission
denied error.
c                    > U R                  [        R                  5        TR                  U R                  R
                  S   S   S5        g )Nr   z550 foo: Permission denied.)trapr   r   r   r<  r   resr;   s    r+   eb;FTPServerAdvancedClientTests.test_anonymousSTOR.<locals>.eb  s8    HHS&&'SYY^^A.q13PQr2   r  )r)   	storeFile
addErrbackr   r   )r;   r  r   r   s   `   r+   test_anonymousSTOR/FTPServerAdvancedClientTests.test_anonymousSTOR  s@    	R &&u-
b""B8,,r2   c                   ^ ^  " S S[         R                  5      mU4S jnT R                  [         R                  SU5        U 4S jnT R                  R                  S5      u  p4UR                  U5        [        R                  " X4/5      $ )zU
Any FTP error raised by STOR while transferring the file is returned
to the client.
c                       \ rS rSrS rSrg)XFTPServerAdvancedClientTests.test_STORtransferErrorIsReturned.<locals>.FailingFileWriteri  c                 V    [         R                  " [        R                  " S5      5      $ )Nfailing_filer   r2  r   IsADirectoryErrorr:   s    r+   receive`FTPServerAdvancedClientTests.test_STORtransferErrorIsReturned.<locals>.FailingFileWriter.receive  s    zz#"7"7"GHHr2   rO   NrR   rS   rT   rU   r)  rW   rO   r2   r+   FailingFileWriterr$    s    Ir2   r,  c                 <   > [         R                  " T" S 5      5      $ r7   r   r   abr,  s     r+   failingSTORRFTPServerAdvancedClientTests.test_STORtransferErrorIsReturned.<locals>.failingSTOR      ==!24!899r2   r  c                 L  > U R                  [        R                  5        TR                  5       nTR	                  S[        U5      5        TR                  US   R                  [        R                  5        TR	                  U R                  R                  S   S   S5        g )Nr   r   z 550 failing_file: is a directory)
r  r   r   r9  r   r:  r;  r<  r(  r   r  r>  r;   s     r+   r  IFTPServerAdvancedClientTests.test_STORtransferErrorIsReturned.<locals>.eb  sx    HHS&&'))+DQD	*!!$q'--1F1FGSYY^^A.q13UVr2   r&  	r   _FileWriterpatchFTPAnonymousShellr)   r  r  r   r   r;   r2  r  r   r   r,  s   `    @r+    test_STORtransferErrorIsReturned=FTPServerAdvancedClientTests.test_STORtransferErrorIsReturned  sp    	I 	I	:
 	

3((*:KH	W &&~6
b""B8,,r2   c                   ^ ^  " S S[         R                  5      mU4S jnT R                  [         R                  SU5        U 4S jnT R                  R                  S5      u  p4UR                  U5        [        R                  " X4/5      $ )z
Any non FTP error raised by STOR while transferring the file is
converted into a critical error and transfer is closed.

The unknown error is logged.
c                       \ rS rSrS rSrg)aFTPServerAdvancedClientTests.test_STORunknownTransferErrorBecomesAbort.<locals>.FailingFileWriteri  c                 >    [         R                  " [        5       5      $ r7   r1  r:   s    r+   r)  iFTPServerAdvancedClientTests.test_STORunknownTransferErrorBecomesAbort.<locals>.FailingFileWriter.receive  s    zz."233r2   rO   Nr+  rO   r2   r+   r,  rA    s    4r2   r,  c                 <   > [         R                  " T" S 5      5      $ r7   r.  r/  s     r+   r2  [FTPServerAdvancedClientTests.test_STORunknownTransferErrorBecomesAbort.<locals>.failingSTOR  r4  r2   r  c                 8  > U R                  [        R                  5        TR                  5       nTR	                  S[        U5      5        TR                  US   R                  [        5        TR	                  U R                  R                  S   S   S5        g )Nr   r   z.426 Transfer aborted.  Data connection closed.)
r  r   r   r9  r   r:  r;  r<  r3  r   r6  s     r+   r  RFTPServerAdvancedClientTests.test_STORunknownTransferErrorBecomesAbort.<locals>.eb  su    HHS&&'))+DQD	*!!$q'--@		q!!$&Vr2   r&  r8  r<  s   `    @r+   )test_STORunknownTransferErrorBecomesAbortFFTPServerAdvancedClientTests.test_STORunknownTransferErrorBecomesAbort  sm    	4 	4	:
 	

3((*:KH	 &&~6
b""B8,,r2   c                   ^ ^  " S S[         R                  5      mU4S jnT R                  [         R                  SU5        U 4S jn[	        5       nT R
                  R                  SU5      nUR                  U5        U$ )zR
Any errors during reading a file inside a RETR should be returned to
the client.
c                       \ rS rSrS rSrg)JFTPServerAdvancedClientTests.test_RETRreadError.<locals>.FailingFileReaderi  c                 V    [         R                  " [        R                  " S5      5      $ )Nblahr'  )r;   consumers     r+   sendOFTPServerAdvancedClientTests.test_RETRreadError.<locals>.FailingFileReader.send  s    zz#"7"7"?@@r2   rO   N)rR   rS   rT   rU   rP  rW   rO   r2   r+   FailingFileReaderrL    s    Ar2   rR  c                 <   > [         R                  " T" S 5      5      $ r7   r.  )r0  r1  rR  s     r+   failingRETRDFTPServerAdvancedClientTests.test_RETRreadError.<locals>.failingRETR   r4  r2   openForReadingc                   > TR                  5         U R                  " [        R                  5        TR	                  U R
                  R                  S   S   S5        TR	                  U R
                  R                  S   S   S5        g )Nr   z3125 Data connection already open, starting transferr   z550 blah: is a directory)r9  r  r   r   r   r<  r   )r   r;   s    r+   check_responseGFTPServerAdvancedClientTests.test_RETRreadError.<locals>.check_response'  sp    ""$LL**+""1%a(E W]]//2157QRr2   r&  )r   _FileReaderr:  r;  rY   r)   retrieveFiler  )r;   rT  rX  r   r_   rR  s   `    @r+   test_RETRreadError/FTPServerAdvancedClientTests.test_RETRreadError  sj    	A 	A	:
 	

3((*:KH	S #$KK$$^U;	^$r2   rO   N)rR   rS   rT   rU   r   r   	FTPClientr   r   r=  rH  r\  rW   rO   r2   r+   r  r    s'     MMM--:-@r2   r  c                   z    \ rS rSrSrSS jrSS jrS rS rS r	S	 r
S
 rS rS rS rS rS rS rS rS rSrg) FTPServerPasvDataConnectionTestsi6  z
PASV data connection.
Nc                 h   ^  T R                   R                  S5      nU 4S jnUR                  U5      $ )
Establish a passive data connection (i.e. client connecting to
server).

@param ignored: ignored
@return: L{Deferred.addCallback}
r  c                    > TR                  U S   S5        [        R                  " U S   SS  5      u  p[        R                  " [
        [        5      nUR                  SU5      $ )Nr  z0^227 Entering Passive Mode \((?:\d+,){5}\d+\)\.$r  r   )assertRegexr   ri  r   r   r   rY   r   )r   rn   ro   r   r;   s       r+   gotPASVEFTPServerPasvDataConnectionTests._makeDataConnection.<locals>.gotPASVE  sb    
 b!#V ++M",=ab,ABJD''1CDB==d33r2   r   )r;   r   r_   re  s   `   r+   _makeDataConnection4FTPServerPasvDataConnectionTests._makeDataConnection;  s/     KK**62
	4 }}W%%r2   c                    ^ ^ Uc  [         R                  " S5      nUR                  T R                  5        UU 4S jnUR                  U5        S nUR                  U5      $ )z
Download file.

@param command: command to run
@param chainDeferred: L{Deferred} used to queue commands.
@return: L{Deferred} of command response
Nc                    > TR                   R                  T5      nU R                  n[        R                  " X/5      $ r7   )r)   r   r_   r   r   )
downloaderr   r   r   r;   s      r+   r   @FTPServerPasvDataConnectionTests._download.<locals>.queueCommand`  s5     //8BB&&x00r2   c                 "    U u  pUR                   $ r7   rb   )r  r   rk  s      r+   downloadDone@FTPServerPasvDataConnectionTests._download.<locals>.downloadDonei  s    $*!W$$$r2   )r   r   r   rg  )r;   r   r   r   rn  s   ``   r+   	_download*FTPServerPasvDataConnectionTests._downloadS  sZ      !MM$/M!!$":":;	1 	!!,/	% ((66r2   c                 r   ^  T R                  5       nT R                  SUS9  U 4S jnUR                  U5      $ )z=
When listing empty folders, LIST returns an empty response.
r  r   c                 *   > TR                  SU 5        g r\   r   r  s    r+   
checkEmptyCFTPServerPasvDataConnectionTests.test_LISTEmpty.<locals>.checkEmptyx  s    S&)r2   r   rp  r   )r;   r_   rt  s   `  r+   test_LISTEmpty/FTPServerPasvDataConnectionTests.test_LISTEmptyo  s;       " 	vQ/	* }}Z((r2   c                 j  ^  [         R                  " [         R                  R                  T R                  S5      5        [         R                  " [         R                  R                  T R                  S5      5        T R                  5       nT R                  SUS9  U 4S jnUR                  U5      $ )ze
LIST ignores requests for folder with names like '-al' and will list
the content of current folder.
r  r  zLIST -aLr   c                    > / nU R                  5        H&  nUR                  UR                  S5      S   5        M(     TR                  S[	        U5      5        TR                  SU5        TR                  SU5        g )N    r        foo   bar)
splitlinesrC   splitr   r:  r  )downloadnamesrE   r;   s      r+   checkDownloadOFTPServerPasvDataConnectionTests.test_LISTWithBinLsFlags.<locals>.checkDownload  se    E ++-TZZ-b12 .QE
+MM&%(MM&%(r2   r   r   pathrl  r   r   rp  r   r;   r_   r  s   `  r+   test_LISTWithBinLsFlags8FTPServerPasvDataConnectionTests.test_LISTWithBinLsFlags}  sy    
 	dnne45
dnne45   "z3	) }}]++r2   c                   ^  [         R                  " [         R                  R                  T R                  S5      5        [         R                  " [         R                  R                  T R                  S5      5        T R                  5       nT R                  SUS9  U 4S jnUR                  U5        T R                  SUS9  U 4S jnUR                  U5        T R                  SUS9  U 4S	 jnUR                  U5        U 4S
 jnUR                  U5        T R                  SUS9  U 4S jnUR                  U5      $ )zk
LIST returns all folder's members, each member listed on a separate
line and with name and other details.
r  r  r  r   c                 `   > TR                  S[        U S S R                  S5      5      5        g )Nr|     
)r   r:  r  r  r;   s    r+   r  LFTPServerPasvDataConnectionTests.test_LISTWithContent.<locals>.checkDownload  s)    QHSbM$7$7$@ ABr2   NLST c                 v   > U S S R                  S5      nUR                  5         TR                  SS/U5        g )Nr  r  r~  r}  r  sortr   r  	filenamesr;   s     r+   r  r    s8     "++G4INNff-y9r2   zLIST fooc                 *   > TR                  SU 5        g r\   r   r  s    r+   r  r        S(+r2   c                 :   > TR                   R                  S5      $ )NzCWD foor   )r   r;   s    r+   chdirDFTPServerPasvDataConnectionTests.test_LISTWithContent.<locals>.chdir  s    ;;11)<<r2   c                 *   > TR                  SU 5        g r\   r   r  s    r+   r  r    r  r2   r  )r;   r_   r  r  s   `   r+   test_LISTWithContent5FTPServerPasvDataConnectionTests.test_LISTWithContent  s    
 	dnne45
dnne45   " 	vQ/	C 	
m$ 	wa0	:
 	
m$ 	z3	, 	
m$	= 	
e 	vQ/	, }}]++r2   c                    ^ ^^^ T R                  5       nSU4S jjmUU 4S jnUR                  U5        T R                  U S3US9  UUU 4S jnUR                  U5      $ )a  
Exercise handling by the implementation of I{LIST} or I{NLST} of certain
return values and types from an L{IFTPShell.list} implementation.

This will issue C{command} and assert that if the L{IFTPShell.list}
implementation includes C{listOutput} as one of the file entries then
the result given to the client is matches C{expectedOutput}.

@param command: Either C{b"LIST"} or C{b"NLST"}
@type command: L{bytes}

@param listOutput: A value suitable to be used as an element of the list
    returned by L{IFTPShell.list}.  Vary the values and types of the
    contents to exercise different code paths in the server's handling
    of this result.

@param expectedOutput: A line of output to expect as a result of
    C{listOutput} being transformed into a response to the command
    issued.
@type expectedOutput: L{bytes}

@return: A L{Deferred} which fires when the test is done, either with an
    L{Failure} if the test failed or with a function object if it
    succeeds.  The function object is the function which implements
    L{IFTPShell.list} (and is useful to make assertions about what
    warnings might have been emitted).
@rtype: L{Deferred}
c                 2   > [         R                  " T/5      $ r7   r.  )segmentskeys
listOutputs     r+   patchedListEFTPServerPasvDataConnectionTests._listTestHelper.<locals>.patchedList  s    ==*..r2   c                 >   > TTR                   R                  l        U $ r7   )r   r  rk  )r  r  r;   s    r+   loggedInBFTPServerPasvDataConnectionTests._listTestHelper.<locals>.loggedIn  s    -8D%%*Mr2   z
 somethingr   c                 ,   > TR                  TU 5        T$ r7   r   )r  expectedOutputr  r;   s    r+   r  GFTPServerPasvDataConnectionTests._listTestHelper.<locals>.checkDownload  s    ^X6r2   )rO   )r   r   rp  )r;   r   r  r  r_   r  r  r  s   ` ``   @r+   _listTestHelper0FTPServerPasvDataConnectionTests._listTestHelper  sX    <   "	/	 	
h'*-Q?	 }}]++r2   c                 b    U R                  SSSS[        R                  " S5      SSSS44S5      $ )	zp
Unicode filenames returned from L{IFTPShell.list} are encoded using
UTF-8 before being sent with the response.
r  
   my resumér   r     userr   L   drwxrwxrwx   0 user      group                   0 Jan 01  1970 my resumé
r  r   Permissionsr:   s    r+   test_LISTUnicode1FTPServerPasvDataConnectionTests.test_LISTUnicode  sD    
 ##Ax++E2Aq&'J3
 	
r2   c                 b    U R                  SSSS[        R                  " S5      SSSS44S5      $ )	z
When LIST receive a filename as byte string from L{IFTPShell.list}
it will just pass the data to lower level without any change.

@return: L{_listTestHelper}
r  
   my resumér   r   r  r  r   r  r  r:   s    r+   test_LISTNonASCIIBytes7FTPServerPasvDataConnectionTests.test_LISTNonASCIIBytes	  sD     ###Ax++E2Aq&'J3
 	
r2   c                 x  ^  T R                  5       n[        SSS5       H  n[        [        R                  R                  T R                  SU4-  5      S5       nUR                  SU-  5        SSS5        T R                  SU4-  US	9  U4U 4S
 jjnUR                  U5        M     U$ ! , (       d  f       NB= f)z2
Download many large files.

@return: L{Deferred}
i i i  z%d.txtwb   xNzRETR %d.txtr   c                 <   > TR                  U[        U 5      5        g r7   r   r:  )r  sizer;   s     r+   r  OFTPServerPasvDataConnectionTests.test_ManyLargeDownloads.<locals>.checkDownload*  s      s8}5r2   )
r   rj  openr   r  rl  r   writerp  r   )r;   r_   r  fObjr  s   `    r+   test_ManyLargeDownloads8FTPServerPasvDataConnectionTests.test_ManyLargeDownloads  s       " &&#.Dbggll4>>8tg3EFMQU

4$;' N NN=D72!ND-1 6 MM-( /  NMs   B++
B9	c                 4  ^  T R                   R                  S5      R                  5         T R                  5       nUR	                  T R
                  5        U 4S jnUR	                  U5        S nUR	                  U5        U 4S jnUR                  U5        U$ )zW
When RETR is called for a folder, it will fail complaining that
the path is a folder.
r  c                 r   > U R                   R                  5         TR                  R                  S5      nU$ )Nr[  )r   r   r)   r   )rk  r  r;   s     r+   
retrFolderHFTPServerPasvDataConnectionTests.test_downloadFolder.<locals>.retrFolder;  s.      //1{{55jAHOr2   c                     [        S5      e)Nz(Downloading a folder should not succeed.)r3  )r  s    r+   failOnSuccessKFTPServerPasvDataConnectionTests.test_downloadFolder.<locals>.failOnSuccessB  s     !KLLr2   c                    > U R                   " [        R                  5        TR                  S/U R                  R
                  S   5        TR                  5       nTR                  S[        U5      S5        g )Nz550 foo: is a directoryr   z6No errors should be logged while downloading a folder.)r  r   r   r   r<  r   r9  r:  )r   current_errorsr;   s     r+   
checkErrorHFTPServerPasvDataConnectionTests.test_downloadFolder.<locals>.checkErrorG  sb    LL**+78'--:L:LQ:OP!335NN#Hr2   )r   r  r  r   r   rg  r  )r;   r_   r  r  r  s   `    r+   test_downloadFolder4FTPServerPasvDataConnectionTests.test_downloadFolder0  s     	5!113  "	d../	
 	
j!	M 	
m$	 	
Z r2   c                   ^  T R                  5       nT R                  R                  S5      R                  5         T R                  R                  S5      R	                  5         T R                  SUS9  U 4S jnUR                  U5      $ )zX
NLST with no argument returns the directory listing for the current
working directory.
test.txtr  r  r   c                 v   > U S S R                  S5      nUR                  5         TR                  SS/U5        g )Nr  r  r}     test.txtr  r  s     r+   r  FFTPServerPasvDataConnectionTests.test_NLSTEmpty.<locals>.checkDownloadc  s8     "++G4INNfk2I>r2   )r   r   r  r  r  rp  r   r  s   `  r+   test_NLSTEmpty/FTPServerPasvDataConnectionTests.test_NLSTEmptyT  sq       " 	:&,,.5!113wa0	?
 }}]++r2   c                 r   ^  T R                  5       nT R                  SUS9  U 4S jnUR                  U5      $ )z8
NLST on a non-existent file/directory returns nothing.
zNLST nonexistent.txtr   c                 *   > TR                  SU 5        g r\   r   r  s    r+   r  LFTPServerPasvDataConnectionTests.test_NLSTNonexistent.<locals>.checkDownloads  r  r2   rv  r  s   `  r+   test_NLSTNonexistent5FTPServerPasvDataConnectionTests.test_NLSTNonexistentj  s:    
   "-Q?	, }}]++r2   c                 b    U R                  SSSS[        R                  " S5      SSSS44S5      $ )	z[
NLST will receive Unicode filenames for IFTPShell.list, and will
encode them using UTF-8.
NLSTr  r   r   r  r  r      my resumé
r  r:   s    r+   test_NLSTUnicode1FTPServerPasvDataConnectionTests.test_NLSTUnicodex  sD    
 ##Ax++E2Aq&'J $
 	
r2   c                 b    U R                  SSSS[        R                  " S5      SSSS44S5      $ )	z:
NLST will just pass the non-Unicode data to lower level.
r  r  r   r   r  r  r   r  r  r:   s    r+   test_NLSTNonASCIIBytes7FTPServerPasvDataConnectionTests.test_NLSTNonASCIIBytes  sD     ###Ax++E2Aq&'J $
 	
r2   c                    ^  T R                  5       nT R                  R                  S5      R                  5         T R	                  SUS9  U 4S jnUR                  U5      $ )z>
NLST on an existent file returns only the path to that file.
r  zNLST test.txtr   c                 T   > U S S R                  S5      nTR                  S/U5        g )Nr  r  r  )r  r   r  s     r+   r  MFTPServerPasvDataConnectionTests.test_NLSTOnPathToFile.<locals>.checkDownload  s+     "++G4Ik]I6r2   )r   r   r  r  rp  r   r  s   `  r+   test_NLSTOnPathToFile6FTPServerPasvDataConnectionTests.test_NLSTOnPathToFile  sV    
   " 	:&,,.a8	7 }}]++r2   rO   r7   )rR   rS   rT   rU   r   rg  rp  rw  r  r  r  r  r  r  r  r  r  r  r  r  rW   rO   r2   r+   r`  r`  6  sU    &078),.3,j/,b

","H,,,

,r2   r`  c                       \ rS rSrSrSrSrg)*FTPServerIPv4MappedPasvDataConnectionTestsi  z
The C{PASV} command doesn't work for IPv6 connections (that's why
C{EPSV} was invented).  However, it's possible to use it from an IPv4
client connecting to a dual-stack server using IPv4-mapped addresses, if
the system's IPv6 stack supports that.
r   rO   N)rR   rS   rT   rU   r   r   rW   rO   r2   r+   r  r    s     Kr2   r  c                   "    \ rS rSrSrSS jrSrg) FTPServerEpsvDataConnectionTestsi  z
EPSV data connection.
Nc                 h   ^  T R                   R                  S5      nU 4S jnUR                  U5      $ )rb  r  c                    > TR                  U S   SS  5      u    p[        R                  " [        [        5      nUR                  SU5      $ )Nr  r  r  )r   r   r   r   rY   r   )r   rz  ro   r   r;   s       r+   gotEPSVEFTPServerEpsvDataConnectionTests._makeDataConnection.<locals>.gotEPSV  sG    77b8I!"8MNJAq''1CDB==--r2   r   )r;   r   r_   r  s   `   r+   rg  4FTPServerEpsvDataConnectionTests._makeDataConnection  s/     KK**62	.
 }}W%%r2   rO   r7   )rR   rS   rT   rU   r   rg  rW   rO   r2   r+   r  r    s    &r2   r  c                   :    \ rS rSrSrS rS
S jrS rS rS r	S	r
g) FTPServerPortDataConnectionTestsi  zV
Test the C{PORT} command.

This opens a data connection to a given address and port.
c                 :    / U l         [        R                  U 5      $ r7   	dataPortsr`  r   r:   s    r+   r   &FTPServerPortDataConnectionTests.setUp      /55d;;r2   Nc                 p  ^ [         R                  " 5       m " U4S jS[        R                  5      n[        R
                  " SU" 5       SS9nU R                  R                  U5        S[        R                  " SUR                  5       R                  5      -   nU R                  R                  U5        T$ )Nc                   &   > \ rS rSr\rU 4S jrSrg)IFTPServerPortDataConnectionTests._makeDataConnection.<locals>.DataFactoryi  c                    > [         R                  R                  X5      n[        R                  " STR
                  U5        U$ r   r   ServerFactoryr   r   	callLaterrf   r;   r   r   r  s      r+   r   WFTPServerPortDataConnectionTests._makeDataConnection.<locals>.DataFactory.buildProtocol  6    **88D!!!X%6%6:r2   rO   NrR   rS   rT   rU   rY   r   r   rW   r  s   r+   DataFactoryr        )H r2   r  r   r   rz   r  )r   r^   r   r  r   r   r  rC   r   rk   r   ro   r)   r   r;   r   r  dataPortcmdr  s        @r+   rg  4FTPServerPortDataConnectionTests._makeDataConnection  s     >>#	(00 	 $$QMh'**;8H8H8J8O8OPP&&s+r2   c                    U R                    Vs/ s H#  n[        R                  " UR                  5      PM%     nn[        R                  " [        R
                  U 5      nUR                  U5        [        R                  " USS9$ s  snf zw
Tear down the connection.

@return: a L{defer.DeferredList} that fires when all open data ports
    have been closed.
Tr  r  r   maybeDeferredr   r`  tearDownrC   r  )r;   ro   lr_   s       r+   r  )FTPServerPortDataConnectionTests.tearDown  sl     BFPU  !3!34P @ I I4P	!!!d;; Q   *Bc                 z   ^  T R                  5       nS nUR                  U5        U 4S jnUR                  U5      $ )zQ
When C{PORT} is asked to connect to a closed port, it returns a
suitable error.
c                    ^ [         R                  " S[        R                  " 5       SS9nUR	                  5       R
                  mUR                  5       nUR                  U4S j5        U$ )Nr   r   rz   c                    > T$ r7   rO   rz  r   s    r+   r{  [FTPServerPortDataConnectionTests.test_PORTCannotConnect.<locals>.loggedIn.<locals>.<lambda>      Gr2   r   r   r   r  r   ro   r   r   r   ro   r_   r   s      @r+   r  IFTPServerPortDataConnectionTests.test_PORTCannotConnect.<locals>.loggedIn  S     $$Q(8(8(:kRDlln))G""$AMM+,Hr2   c                 Z   > TR                  S[        R                  " SU 5      -   S/5      $ )Nr  r   425 Can't open data connection.)r   r   rk   r   r;   s    r+   
gotPortNumKFTPServerPortDataConnectionTests.test_PORTCannotConnect.<locals>.gotPortNum	  s1    ++#,,['BB23 r2   r  r;   r_   r  r#  s   `   r+   test_PORTCannotConnect7FTPServerPortDataConnectionTests.test_PORTCannotConnect  s<       "	 	
h	 }}Z((r2   c                 h  ^  T R                   R                  S5      R                  5         T R                   R                  S5      R                  5         T R                   R                  S5      R                  5         T R                  5       nT R	                  SUS9  U 4S jnUR                  U5      $ )z^
When Unix shell globbing is used with NLST only files matching the
pattern will be returned.
r  zceva.txtzno.matchz
NLST *.txtr   c                 v   > U S S R                  S5      nUR                  5         TR                  SS/U5        g )Nr  r  s   ceva.txtr  r  r  s     r+   r  IFTPServerPortDataConnectionTests.test_nlstGlobbing.<locals>.checkDownload  s8     "++G4INNk;7Cr2   )r   r  r  r   rp  r   r  s   `  r+   test_nlstGlobbing2FTPServerPortDataConnectionTests.test_nlstGlobbing  s    
 	:&,,.:&,,.:&,,.  "|15	D
 }}]++r2   r  r7   )rR   rS   rT   rU   r   r   rg  r  r&  r+  rW   rO   r2   r+   r  r    s     <&
<):,r2   r  c                   F    \ rS rSrSrS rSS jrS rS rS r	S	 r
S
 rSrg) FTPServerEprtDataConnectionTestsi%  z
Test the C{EPRT} command.

This opens a data connection to a given protocol, address, and port, in
a format compatible with both IPv4 and IPv6.
c                 :    / U l         [        R                  U 5      $ r7   r  r:   s    r+   r   &FTPServerEprtDataConnectionTests.setUp-  r  r2   Nc                 F  ^ [         R                  " 5       m " U4S jS[        R                  5      n[        R
                  " SU" 5       SS9nU R                  R                  U5        SUR                  5       R                  -  nU R                  R                  U5        T$ )Nc                   &   > \ rS rSr\rU 4S jrSrg)IFTPServerEprtDataConnectionTests._makeDataConnection.<locals>.DataFactoryi6  c                    > [         R                  R                  X5      n[        R                  " STR
                  U5        U$ r   r   r  s      r+   r   WFTPServerEprtDataConnectionTests._makeDataConnection.<locals>.DataFactory.buildProtocol9  r  r2   rO   Nr  r  s   r+   r  r4  6  r	  r2   r  r   r   rz   EPRT |1|127.0.0.1|%s|)r   r^   r   r  r   r   r  rC   r   ro   r)   r   r
  s        @r+   rg  4FTPServerEprtDataConnectionTests._makeDataConnection1  s}     >>#	(00 	 $$QMh'%(8(8(:(?(??&&s+r2   c                    U R                    Vs/ s H#  n[        R                  " UR                  5      PM%     nn[        R                  " [        R
                  U 5      nUR                  U5        [        R                  " USS9$ s  snf r  r  )r;   ro   dlr_   s       r+   r  )FTPServerEprtDataConnectionTests.tearDownD  sl     CG..Q.$e!!$"4"45.Q @ I I4P
		!!!"t<< Rr  c                 z   ^  T R                  5       nS nUR                  U5        U 4S jnUR                  U5      $ )zQ
When C{EPRT} is asked to connect to a closed port, it returns a
suitable error.
c                    ^ [         R                  " S[        R                  " 5       SS9nUR	                  5       R
                  mUR                  5       nUR                  U4S j5        U$ )Nr   r   rz   c                    > T$ r7   rO   r  s    r+   r{  [FTPServerEprtDataConnectionTests.test_EPRTCannotConnect.<locals>.loggedIn.<locals>.<lambda>^  r  r2   r  r  s      @r+   r  IFTPServerEprtDataConnectionTests.test_EPRTCannotConnect.<locals>.loggedInX  r  r2   c                 0   > TR                  SU -  S/5      $ )Nr7  r!  r#  r"  s    r+   r#  KFTPServerEprtDataConnectionTests.test_EPRTCannotConnect.<locals>.gotPortNume  s$    ++''14U3V r2   r  r%  s   `   r+   test_EPRTCannotConnect7FTPServerEprtDataConnectionTests.test_EPRTCannotConnectP  s<       "	 	
h	
 }}Z((r2   c                 F    U R                  5       nU R                  SS/US9$ )z@
C{EPRT} returns a syntax error if it can't decode the address.
zEPRT nonsenser  r   rS  r   s     r+   test_EPRTBadAddress4FTPServerEprtDataConnectionTests.test_EPRTBadAddressl  s6       "''89 ( 
 	
r2   c                 F    U R                  5       nU R                  SS/US9$ )zG
C{EPRT} returns a syntax error if the network protocol is ill-formed.
z%EPRT |not-a-protocol|127.0.0.1|12345|z/501 syntax error in argument(s) not-a-protocol.r   rS  r   s     r+   test_EPRTInvalidNetworkProtocol@FTPServerEprtDataConnectionTests.test_EPRTInvalidNetworkProtocolw  s6       "''3>? ( 
 	
r2   c                 F    U R                  5       nU R                  SS/US9$ )zB
C{EPRT} returns an error if the network protocol is unsupported.
zEPRT |3|127.0.0.1|12345|r  r   rS  r   s     r+   #test_EPRTUnsupportedNetworkProtocolDFTPServerEprtDataConnectionTests.test_EPRTUnsupportedNetworkProtocol  s6       "''&<= ( 
 	
r2   r-  r7   )rR   rS   rT   rU   r   r   rg  r  rC  rF  rI  rL  rW   rO   r2   r+   r/  r/  %  s*    <&
=)8	
	
	
r2   r/  c                   B    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
rg)DTPFactoryTestsi  z
Tests for L{ftp.DTPFactory}.
c                     [         R                  " 5       U l         " S S5      nU" 5       U l        [        R
                  " U R                  SU R                  5      U l        g)zN
Create a fake protocol interpreter and a L{ftp.DTPFactory} instance to
test.
c                       \ rS rSrSrSrg)2DTPFactoryTests.setUp.<locals>.ProtocolInterpreteri  NrO   rR   rS   rT   rU   r  rW   rO   r2   r+   ProtocolInterpreterrR        Kr2   rT  N)r   Clockr   protocolInterpreterr   
DTPFactoryr?   r;   rT  s     r+   r   DTPFactoryTests.setUp  sF    
 zz|	 	 $7#8 ~~d&>&>dllSr2   c                    / nU R                  U R                  R                  [        R                  5      nUR                  UR                  5        U R                  R                  S5        U R                  R                  S5        U R                  U5        U R                  R                  S5        U R                  U5        U R                  U R                  R                  5        g)z
L{ftp.DTPFactory.setTimeout} uses the reactor passed to its initializer
to set up a timed event to time out the DTP setup after the specified
number of seconds.
rf     r   N)r   r?   r  r   PortConnectionErrorr   rC   
setTimeoutr   advancer  r  callsr;   finishedr_   s      r+   test_setTimeoutDTPFactoryTests.test_setTimeout  s     t||44c6M6MN	hoo&" 	Q 	" 	Q 	! 	++,r2   c                     U R                   R                  S5      nU R                  U[        R                  5        U R                  U R                   R                  S5      5        g)zj
A L{ftp.DTPFactory} instance's C{buildProtocol} method can be used once
to create a L{ftp.DTP} instance.
N)r?   r   r;  r   DTPassertIsNone)r;   r   s     r+   test_buildProtocolOnce&DTPFactoryTests.test_buildProtocolOnce  sK    
 <<--d3h0 	$,,44T:;r2   c                     U R                   R                  S5        U R                   R                  S5        U R                  U R                  R
                  5        g)zv
If a timeout has been set up using L{ftp.DTPFactory.setTimeout}, it is
cancelled by L{ftp.DTPFactory.buildProtocol}.

   N)r?   r^  r   r  r   r`  r:   s    r+   test_timeoutAfterConnection+DTPFactoryTests.test_timeoutAfterConnection  s@    
 	#""4(++,r2   c                 .   U R                  U R                  R                  [        R                  5      nU R                  R                  S5        U R                  R                  S5        U R                  U R                  R                  S5      5        U$ )z
If L{ftp.DTPFactory.buildProtocol} is called after the timeout
specified by L{ftp.DTPFactory.setTimeout} has elapsed, L{None} is
returned.
rk  N)
r   r?   r  r   r]  r^  r   r_  rg  r   r   s     r+   test_connectionAfterTimeout+DTPFactoryTests.test_connectionAfterTimeout  sr     t||44c6M6MN 	#R  	$,,44T:; r2   c                    / nU R                  U R                  R                  [        R                  5      nUR                  UR                  5        U R                  R                  S5        U R                  U5        U R                  R                  SS5        U R                  U5        U R                  R                  S5        U$ )z
L{ftp.DTPFactory.deferred} fails with L{PortConnectionError} when
L{ftp.DTPFactory.clientConnectionFailed} is called.  If the timeout
specified with L{ftp.DTPFactory.setTimeout} expires after that, nothing
additional happens.
rk  N)r   r?   r  r   r]  r   rC   r^  r  clientConnectionFailedr  r   r_  ra  s      r+   !test_timeoutAfterConnectionFailed1DTPFactoryTests.test_timeoutAfterConnectionFailed  s     t||44c6M6MN	hoo&#"++D$7!R r2   c                 :   U R                  U R                  R                  [        R                  5      nU R                  R                  S5        U R                  R                  S5        U R                  R                  S[        R                  " S5      5        U$ )z
If L{ftp.DTPFactory.clientConnectionFailed} is called after the timeout
specified by L{ftp.DTPFactory.setTimeout} has elapsed, nothing beyond
the normal timeout before happens.
rk  Nr  )r   r?   r  r   r]  r^  r   r_  rr  r   TimeoutErrorr   s     r+   !test_connectionFailedAfterTimeout1DTPFactoryTests.test_connectionFailedAfterTimeout  st     t||44c6M6MN 	#R  	++D%2D2DU2KL r2   )r?   rW  r   N)rR   rS   rT   rU   r   r   rc  rh  rl  ro  rs  rw  rW   rO   r2   r+   rO  rO    s+    T-:	<-($r2   rO  c                   $    \ rS rSrSrS rS rSrg)DTPTestsi  zh
Tests for L{ftp.DTP}.

The DTP instances in these tests are generated using
DTPFactory.buildProtocol()
c                     [         R                  " 5       U l         " S S5      nU" 5       U l        [        R
                  " U R                  SU R                  5      U l        [        R                  " 5       U l	        g)zk
Create a fake protocol interpreter, a L{ftp.DTPFactory} instance,
and dummy transport to help with tests.
c                       \ rS rSrSrSrg)+DTPTests.setUp.<locals>.ProtocolInterpreteri  NrO   rS  rO   r2   r+   rT  r}    rU  r2   rT  N)
r   rV  r   rW  r   rX  r?   r    StringTransportWithDisconnectionr   rY  s     r+   r   DTPTests.setUp  sV    
 zz|	 	 $7#8 ~~d&>&>dllS&GGIr2   c                     U R                   R                  S5      nUR                  U R                  5        SnUR	                  U5        U R                  R                  5       nU R                  US-   U5        g)zZ
L{ftp.DTP.sendLine} writes the line passed to it plus a line delimiter
to its transport.
Ns   line contentr  )r?   r   makeConnectionr   sendLiner<  r   )r;   r  lineContentdataSents       r+   test_sendLineNewlineDTPTests.test_sendLineNewline%  sd    
 ll006""4>>2%[)>>'')w.9r2   )r?   rW  r   r   N)rR   rS   rT   rU   r   r   r  rW   rO   r2   r+   rz  rz    s    J:r2   rz  c                   $    \ rS rSrSrS rS rSrg)
PrintLinesi7  z+
Helper class used by FTPFileListingTests.
c                     Xl         g r7   _lines)r;   r8   s     r+   r<   PrintLines.__init__<  s    r2   c                     U R                    H0  nU R                  R                  UR                  S5      S-   5        M2     U R                  R	                  5         g )Nzlatin-1r  )r  r   r  rl   r   rD   s     r+   r@   PrintLines.connectionMade?  s@    KKDNN  Y!7'!AB  %%'r2   r  N)rR   rS   rT   rU   r   r<   r@   rW   rO   r2   r+   r  r  7  s    (r2   r  c                        \ rS rSrS rS rSrg)MyFTPFileListProtocoliE  c                 P    / U l         [        R                  R                  U 5        g r7   )otherr   FTPFileListProtocolr<   r:   s    r+   r<   MyFTPFileListProtocol.__init__F  s    
((.r2   c                 :    U R                   R                  U5        g r7   )r  rC   rD   s     r+   unknownLine!MyFTPFileListProtocol.unknownLineJ  rH   r2   )r  N)rR   rS   rT   rU   r<   r  rW   rO   r2   r+   r  r  E  s    / r2   r  c                   >    \ rS rSrS rS rS rS rS rS r	S r
S	rg
)FTPFileListingTestsiN  c                    ^ [        5       m[        R                  " [        U5      T5      nUR	                  U4S j5        U$ )Nc                 4   > TR                   TR                  4$ r7   )filesr  )rz  fileLists    r+   r{  6FTPFileListingTests.getFilesForLines.<locals>.<lambda>R  s     @r2   )r  r   loopbackAsyncr  r   )r;   r8   r_   r  s      @r+   getFilesForLines$FTPFileListingTests.getFilesForLinesO  s4    (*"":e#4h?	@Ar2   c                 V   ^  SnU 4S jnT R                  U/5      R                  U5      $ )zn
This example line taken from the docstring for FTPFileListProtocol

@return: L{Deferred} of command response
z<-rw-r--r--   1 root     other        531 Jan 29 03:26 READMEc                   > U u  u  pTR                  US[        U5       35        TR                  US   S:H  S5        TR                  US   S:H  S5        TR                  US   S	:H  S5        TR                  US
   S:H  S5        TR                  US   S:H  S5        TR                  US   S:H  S5        TR                  US   S:H  S5        TR                  US   S:H  S5        TR                  US   S5        g )Nzunexpect unparsable lines: filetype-misparsed fileitemperms	rw-r--r--misparsed permsownerrootr   r  r    dateJan 29 03:26filenameREADMEnlinksr   misparsed nlinks
linktargetmisparsed linktarget)r  reprr  )	fileOtherfiler  r;   s      r+   check/FTPFileListingTests.test_OneLine.<locals>.check]  s   (WdU&A$u+$OPOOD,35IJOODM[8:KLOODMV35IJOODMW46JKOODLC/1EFOODLN:<PQOOD,8:NOOODNa/1CDT,/1GHr2   r  r   )r;   rE   r  s   `  r+   test_OneLine FTPFileListingTests.test_OneLineU  s1     N	I $$dV,88??r2   c                 `   ^  SnSnSnU 4S jnT R                  XU/5      R                  U5      $ )z
Variant lines.
z7drw-r--r--   2 root     other        531 Jan  9  2003 Az<lrw-r--r--   1 root     other          1 Jan 29 03:26 B -> Azwoohoo! c                   > U u  u  pu  nTR                  US:H  S5        TR                  US   S:H  S5        TR                  US   S:H  S5        TR                  US	   S
:H  S5        TR                  US   S:H  S5        TR                  US   S:H  S5        TR                  US   S:H  S5        TR                  US   S:H  S5        TR                  US   S:H  S5        TR                  US   S5        TR                  US   S:H  S5        TR                  US   S:H  S5        TR                  US	   S
:H  S5        TR                  US   S:H  S5        TR                  US   S:H  S5        TR                  US   S:H  S5        TR                  US   S :H  S5        TR                  US   S:H  S5        TR                  US   S:H  S5        g )!Nz	woohoo! zincorrect other liner  r_   r  r  r  r  r  r  zmisparsed ownerr   r  zmisparsed groupr  r  zmisparsed sizer  zJan  9  2003zmisparsed dater  Amisparsed filenamer  r|  r  r  r  r  r   r  B)r  r  )r  file1file2r  r;   s       r+   r  4FTPFileListingTests.test_VariantLines.<locals>.checkt  s   )/&^eXeOOE\13IJOOE*-46JKOOE'Nk9;LMOOE'Nf46GHOOE'Ng57HIOOE&MS02BCOOE&M^;=MNOOE*-46JKOOE(Oq02DEU<02HIOOE*-46JKOOE'Nk9;LMOOE'Nf46GHOOE'Ng57HIOOE&MQ.0@AOOE&M^;=MNOOE*-46JKOOE(Oq02DEOOE,/368NOr2   r  )r;   line1line2line3r  s   `    r+   test_VariantLines%FTPFileListingTests.test_VariantLinesl  s>     JN	P0 $$eE%:;GGNNr2   c                 T   ^  U 4S jnT R                  SS/5      R                  U5      $ )z
Unknown lines.
c                 x   > U u  pTR                  US5        TR                  USS/:H  S[        U5      -  5        g )Nzunexpected file entrieszABCznot a filezincorrect unparsable lines: %s)r  r  r  r  r  othersr;   s      r+   r  3FTPFileListingTests.test_UnknownLine.<locals>.check  s@    $OUU$=>OO7N3304<?r2   ABCz
not a filer  )r;   r  s   ` r+   test_UnknownLine$FTPFileListingTests.test_UnknownLine  s+    
	 $$e\%:;GGNNr2   c                 Z   ^  SnSnU 4S jnT R                  X/5      R                  U5      $ )zM
Will parse filenames and linktargets containing unescaped
space characters.
z9drw-r--r--   2 root     other        531 Jan  9  2003 A BzDlrw-r--r--   1 root     other          1 Jan 29 03:26 B A -> D C/A Bc                    > U u  pTR                  / US5        TR                  SUS   S   S5        TR                  SUS   S   S5        TR                  SUS   S	   S
5        g Nzunexpected others entrieszA Br   r  r  zB Ar   zD C/A Br  r  r   r  s      r+   r  BFTPFileListingTests.test_filenameWithUnescapedSpace.<locals>.check  q    $OUR)DEUE!HZ$8:NOUE!HZ$8:NOYa(>@VWr2   r  r;   r  r  r  s   `   r+   test_filenameWithUnescapedSpace3FTPFileListingTests.test_filenameWithUnescapedSpace  s9    
 LU 		X $$e^4@@GGr2   c                 Z   ^  SnSnU 4S jnT R                  X/5      R                  U5      $ )zK
Will parse filenames and linktargets containing escaped
space characters.
z:drw-r--r--   2 root     other        531 Jan  9  2003 A\ BzElrw-r--r--   1 root     other          1 Jan 29 03:26 B A -> D\ C/A Bc                    > U u  pTR                  / US5        TR                  SUS   S   S5        TR                  SUS   S   S5        TR                  SUS   S	   S
5        g r  r   r  s      r+   r  @FTPFileListingTests.test_filenameWithEscapedSpace.<locals>.check  r  r2   r  r  s   `   r+   test_filenameWithEscapedSpace1FTPFileListingTests.test_filenameWithEscapedSpace  s9    
 NW 		X $$e^4@@GGr2   c                    ^ ^^ [         R                  " 5       mSm " U4S jS[        R                  5      nUU 4S jn[        R
                  " U" 5       T5      nUR                  U5      $ )zc
This example derived from bug description in issue 514.

@return: L{Deferred} of command response
s<   -rw-r--r--   1 root     other        531 Jan 29 2003 README
c                   "   > \ rS rSrU 4S jrSrg)0FTPFileListingTests.test_Year.<locals>.PrintLinei  c                 p   > U R                   R                  T5        U R                   R                  5         g r7   )r   r  r   )r;   exampleLines    r+   r@   ?FTPFileListingTests.test_Year.<locals>.PrintLine.connectionMade  s%    $$[1--/r2   rO   N)rR   rS   rT   rU   r@   rW   )r  s   r+   	PrintLiner    s    0 0r2   r  c                    > TR                   S   nTR                  US   S:H  S5        TR                  US   S:H  S5        TR                  US   S:H  S5        g )	Nr   r  r  r  r  zJan 29 2003r  r  )r  r  )r   r  r  r;   s     r+   r  ,FTPFileListingTests.test_Year.<locals>.check  sZ    >>!$DOODLC/1EFOODLM9;OPOOD,8:NOr2   )r   r  r   Protocolr   r  r   )r;   r  r  r_   r  r  s   `   @@r+   	test_YearFTPFileListingTests.test_Year  sU     **,V	0)) 	0
	P ""9;9}}U##r2   rO   N)rR   rS   rT   rU   r  r  r  r  r  r  r  rW   rO   r2   r+   r  r  N  s+    @. ODOH&H&$r2   r  c                   $    \ rS rSrSrS rS rSrg)1FTPClientFailedRETRAndErrbacksUponDisconnectTestsi  z2
FTP client fails and RETR fails and disconnects.
c                   ^ [         R                  " 5       nSUl        [        R                  " SUSS9nU R                  UR                  5        UR                  5       R                  nSSSSSUS	-	  US
-  4-  S/mU4S jUl	        [         R                  " [        [        R                  SS9nUR                  SU5      nS nUR                  U5        U R                  U[        R                   5      $ )z
RETR fails.
r   r   rz   z1220 ready, dude (vsFTPd 1.0.0: beat me, break me)z 331 Please specify the password.z230 Login successful. Have fun.z200 Binary it is, then.z+227 Entering Passive Mode (127,0,0,1,%d,%d)      z550 Failed to open file.c                    > [        T5      $ r7   )r  )r   	responsess    r+   r{  SFTPClientFailedRETRAndErrbacksUponDisconnectTests.test_FailedRETR.<locals>.<lambda>  s
    z)'<r2   r   )passivec                 P    [         R                  " 5       nU R                  SU5      $ )Nz/file/that/doesnt/exist)r   r  r[  )r)   r   s     r+   r   TFTPClientFailedRETRAndErrbacksUponDisconnectTests.test_FailedRETR.<locals>.gotClient  s$    !!#A&&'@!DDr2   )r   r  noisyr   r   r   r   r   ro   r   r   r   r^  r   r   r   r   )r;   r0   ro   r   r   r_   r   r  s          @r+   test_FailedRETRAFTPClientFailedRETRAndErrbacksUponDisconnectTests.test_FailedRETR  s       A=**+,,.%% @.-%9!|Wt^,- '
	 =##GS]]AFMM+w/	E 	
i !!!S%6%677r2   c                 j  ^ [         R                  " 5       n[        R                  " 5       nUR	                  U5        Xl        UR                  S[        5       5      n/ mU4S jnUR                  U5        SSK	J
n  UR                  [        R                  " U5      5        U R                  TT5        U$ )zT
Test the ftp command errbacks when a connection lost happens during
the operation.
z	some pathc                 (   > TR                  U 5        g r7   rC   )r   ms    r+   _ebZFTPClientFailedRETRAndErrbacksUponDisconnectTests.test_errbacksUponDisconnect.<locals>._eb  s    HHWr2   r   )CONNECTION_LOST)r   r^  r   r~  r  r   rk  r4   r  twisted.internet.mainr  rh   r   Failurer  )r;   	ftpClienttrr_   r  r  r  s         @r+   test_errbacksUponDisconnectMFTPClientFailedRETRAndErrbacksUponDisconnectTests.test_errbacksUponDisconnect  s    
 MMO	;;=  $NN;0	 	
S9  !AB1r2   rO   N)rR   rS   rT   rU   r   r  r  rW   rO   r2   r+   r  r    s    "8Hr2   r  c                      \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS r S r!S  r"S! r#S" r$S# r%S$ r&S% r'S& r(S' r)S( r*S) r+S* r,S+ r-S,r.g-).FTPClientTestsi  z$
Test advanced FTP client commands.
c                     [         R                  " 5       U l        [        R                  " 5       U l        U R                  R                  U R
                  5        U R                  U R
                  l        g)z7
Create a FTP client and connect it to fake transport.
N)r   r^  r)   r   r~  r   r  r   r:   s    r+   r   FTPClientTests.setUp!  sG     mmo&GGI""4>>2"&++r2   c                 `    U R                   R                  [        R                  " 5       5        g)zl
Deliver disconnection notification to the client so that it can
perform any cleanup which may be required.
N)r)   rh   r   ConnectionLostr:   s    r+   r  FTPClientTests.tearDown*  s    
 	""5#7#7#9:r2   c                 
   U R                  U R                  R                  5       S5        U R                  R	                  S5        U R                  U R                  R                  5       S5        U R                  R                  5         U R                  R	                  S5        U R                  U R                  R                  5       S5        U R                  R                  5         U R                  R	                  S5        g)z
Test the login part.
r2   s8   331 Guest login ok, type your email address as password.s   USER anonymous
s2   230 Anonymous login ok, access restrictions apply.s   TYPE I
s   200 Type set to I.N)r   r   r<  r)   rF   clearr:   s    r+   
_testLoginFTPClientTests._testLogin1  s     	--/5  G	
 	--/1FG  !VW--/?  !67r2   c                 *   U R                  U R                  R                  5       S5        U R                  R	                  S5        U R                  U R                  R                  5       S5        U R                  R	                  S5        U R                  U R                  R                  5       S5        U R                  R                  5         U R                  R	                  S5        U R                  U R                  R                  5       S5        g)z%
Test encoding behaviour of sendLine
r2   N r     és   
)r   r   r<  r)   r  r  r:   s    r+   test_sendLineFTPClientTests.test_sendLine@  s     	--/5T"--/5R --/9V$--/=r2   c                 D  ^  U 4S jnT R                  5         T R                  R                  5       R                  U5      nT R	                  T R
                  R                  5       S5        T R
                  R                  5         T R                  R                  S5        U$ )z
Test the CDUP command.

L{ftp.FTPClient.cdup} should return a Deferred which fires with a
sequence of one element which is the string the server sent
indicating that the command was executed successfully.

(XXX - This is a bad API)
c                 0   > TR                  U S   S5        g Nr   r  r   r  s    r+   cbCdup(FTPClientTests.test_CDUP.<locals>.cbCdupX      SV%MNr2      CDUP
&   250 Requested File Action Completed OK)	r  r)   cdupr   r   r   r<  r  rF   )r;   r  r_   s   `  r+   	test_CDUPFTPClientTests.test_CDUPM  sw    	O 	KK**62--/=  !JKr2   c                 X   U R                  5         U R                  R                  5       nU R                  U[        R
                  5        U R                  U R                  R                  5       S5        U R                  R                  5         U R                  R                  S5        U$ )z
Test L{ftp.FTPClient.cdup}'s handling of a failed CDUP command.

When the CDUP command fails, the returned Deferred should errback
with L{ftp.CommandFailed}.
r  s!   550 ..: No such file or directory)r  r)   r  r   r   r   r   r   r<  r  rF   r   s     r+   test_failedCDUPFTPClientTests.test_failedCDUPb  s{     	KK1c//0--/=  !EFr2   c                   ^  U 4S jnT R                  5         T R                  R                  5       R                  U5      nT R	                  T R
                  R                  5       S5        T R                  R                  S5        U$ )z
Test the PWD command.

L{ftp.FTPClient.pwd} should return a Deferred which fires with a
sequence of one element which is a string representing the current
working directory on the server.

(XXX - This is a bad API)
c                 X   > TR                  [        R                  " U S   5      S5        g )Nr   /bar/baz)r   r   parsePWDResponser  s    r+   cbPwd&FTPClientTests.test_PWD.<locals>.cbPwd|  s"    S11#a&9:Fr2      PWD
   257 "/bar/baz")r  r)   pwdr   r   r   r<  rF   )r;   r(  r_   s   `  r+   test_PWDFTPClientTests.test_PWDq  se    	G 	KKOO))%0--/<  !23r2   c                 $   U R                  5         U R                  R                  5       nU R                  U[        R
                  5        U R                  U R                  R                  5       S5        U R                  R                  S5        U$ )z}
Test a failure in PWD command.

When the PWD command fails, the returned Deferred should errback
with L{ftp.CommandFailed}.
r*  '   550 /bar/baz: No such file or directory)
r  r)   r,  r   r   r   r   r   r<  rF   r   s     r+   test_failedPWDFTPClientTests.test_failedPWD  si     	KKOO1c//0--/<  !KLr2   c                   ^  U 4S jnT R                  5         T R                  R                  S5      R                  U5      nT R	                  T R
                  R                  5       S5        T R                  R                  S5        U$ )z
Test the CWD command.

L{ftp.FTPClient.cwd} should return a Deferred which fires with a
sequence of one element which is the string the server sent
indicating that the command was executed successfully.

(XXX - This is a bad API)
c                 0   > TR                  U S   S5        g r  r   r  s    r+   cbCwd&FTPClientTests.test_CWD.<locals>.cbCwd  r  r2   bar/foo   CWD bar/foo
r  )r  r)   cwdr   r   r   r<  rF   )r;   r5  r_   s   `  r+   test_CWDFTPClientTests.test_CWD  sh    	O 	KKOOI&2259--/1CD  !JKr2   c                 &   U R                  5         U R                  R                  S5      nU R                  U[        R
                  5        U R                  U R                  R                  5       S5        U R                  R                  S5        U$ )z}
Test a failure in CWD command.

When the PWD command fails, the returned Deferred should errback
with L{ftp.CommandFailed}.
r7  r8  s&   550 bar/foo: No such file or directory)
r  r)   r9  r   r   r   r   r   r<  rF   r   s     r+   test_failedCWDFTPClientTests.test_failedCWD  sl     	KKOOI&1c//0--/1CD  !JKr2   c                 r  ^  U 4S jnU 4S jnUT R                   l        T R                  5         [        5       nT R                   R	                  SU5      nUR                  X5        T R                  T R                  R                  5       S5        T R                  R                  5         T R                   R                  [        T R                   5      5        T R                  T R                  R                  5       S5        T R                  R                  5         T R                   R                  S5        U$ )a  
Test the RETR command in passive mode: get a file and verify its
content.

L{ftp.FTPClient.retrieveFile} should return a Deferred which fires
with the protocol instance passed to it after the download has
completed.

(XXX - This API should be based on producers and consumers)
c                 >   > TR                  UR                  S5        g N  xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxr   r  r   r;   s     r+   cbRetr/FTPClientTests.test_passiveRETR.<locals>.cbRetr      U\\;7r2   c                   > TR                  U S5        TR                  US5        UR                  X45      nUR                  [        R                  " 5       5        TR
                  R                  S5        UR                  S5        UR                  [        R                  " [        R                  " S5      5      5        g )Nr   90  4   150 File status okay; about to open data connection.rB  r  r   r   r  r   StringTransportr)   rF   rc   rh   r   r  r   ConnectionDonern   ro   r?   r   r;   s       r+   	cbConnect2FTPClientTests.test_passiveRETR.<locals>.cbConnect  s    T;/T5)))4,7E  !>!>!@AKK$$G {+  1E1Eb1I!JKr2   spam   PASV
   RETR spam
   226 Transfer Complete.)r)   connectFactoryr  rY   r[  r   r   r   r<  r  rF   rq   )r;   rD  rN  r   r_   s   `    r+   test_passiveRETRFTPClientTests.test_passiveRETR  s    	8		L &/""$KK$$VU3	f$--/=  !=>--/1AB  !:;r2   c           	        ^  ST R                   l        S nU 4S jnUT R                   l        T R                  5         [	        5       nT R                   R                  SU5      nUR                  X#5        T R                  T R                  R                  5       SR                  [        R                  " SS5      5      R                  T R                   R                  5      5        T R                  R                  5         T R                   R!                  S5        T R                  T R                  R                  5       S	5        T R                  R                  5         T R                   R!                  S
5        U$ )z
Test the RETR command in non-passive mode.

Like L{test_passiveRETR} but in the configuration where the server
establishes the data connection to the client, rather than the other
way around.
Fc                 r   SR                  [        R                  " SS5      5      U l        U R                  R                  [        R                  " 5       5        U R                  R                  S5        U R                  R                  [        R                  " [        R                  " S5      5      5        g )NPORT {}r   &  rB  r  )formatr   rk   textr   r  r   rK  rc   rh   r   r  r   rL  )portCmds    r+   generatePort.FTPClientTests.test_RETR.<locals>.generatePort  s{    $++C,>,>{D,QRGL++M,I,I,KL))+6++GOOE<P<PQS<T,UVr2   c                 >   > TR                  UR                  S5        g rA  r   rC  s     r+   rD  (FTPClientTests.test_RETR.<locals>.cbRetr  rF  r2   rP  	PORT {}
r   rZ     200 PORT OKrR  rS  )r)   r  generatePortCommandr  rY   r[  r   r   r   r<  r[  r   rk   rl   rm   r  rF   )r;   r^  rD  r   r_   s   `    r+   	test_RETRFTPClientTests.test_RETR  s    $	W	8 +7'"$KK$$VU3	f$NN  "!!#"4"4[$"GHPP%%	
 	  0--/1AB  !:;r2   c                   ^  U 4S jnUT R                   l        T R                  5         [        5       nT R                   R	                  SU5      nT R                  U[        R                  5        T R                  T R                  R                  5       S5        T R                  R                  5         T R                   R                  [        T R                   5      5        T R                  T R                  R                  5       S5        T R                  R                  5         T R                   R                  S5        U$ )z
Try to RETR an unexisting file.

L{ftp.FTPClient.retrieveFile} should return a Deferred which
errbacks with L{ftp.CommandFailed} if the server indicates the file
cannot be transferred for some reason.
c                 b  > TR                  U S5        TR                  US5        UR                  X45      nUR                  [        R                  " 5       5        TR
                  R                  S5        UR                  [        R                  " [        R                  " S5      5      5        g Nr   rH  rI  r  r   r   r  r   rK  r)   rF   rh   r   r  r   rL  rM  s       r+   rN  1FTPClientTests.test_failedRETR.<locals>.cbConnect
	      T;/T5)))4,7E  !>!>!@AKK$$G   1E1Eb1I!JKr2   rP  rQ  rR  s#   550 spam: No such file or directory)r)   rT  r  rY   r[  r   r   r   r   r   r<  r  rF   rq   )r;   rN  r   r_   s   `   r+   test_failedRETRFTPClientTests.test_failedRETR	  s    	L &/""$KK$$VU31c//0--/=  !=>--/1AB  !GHr2   c           	      "  ^ SU R                   l        / mU4S jnXR                   l        U R                  5         [	        5       nU R                   R                  SU5      nU R                  U R                  R                  5       SR                  [        R                  " SS5      5      R                  U R                   R                  5      5        U R                  R                  5         U R                   R                  S5        U R                  U R                  R                  5       S5        U R!                  T5        TS	   R#                  5         U R                  R#                  5         U R%                  U[        R&                  5        U$ )
z
Try a RETR, but disconnect during the transfer.
L{ftp.FTPClient.retrieveFile} should return a Deferred which
errbacks with L{ftp.ConnectionLost)
Fc                 6  > SR                  [        R                  " SS5      5      U l        [        R
                  " 5       nU R                  R                  U5        U R                  Ul        U R                  R                  S5        TR                  U5        g )NrY  r   rZ  s  xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx)
r[  r   rk   r\  r   r~  r   r  rc   rC   )r]  r  r  s     r+   r^  2FTPClientTests.test_lostRETR.<locals>.generatePort+	  sp    $++C,>,>{D,QRGL??AB++B/!**BK))*5HHRLr2   rP  rb  r   rZ  rc  rR  r   )r)   r  rd  r  rY   r[  r   r   r<  r[  r   rk   rl   rm   r  rF   r  r   r   r  )r;   r^  r   r_   r  s       @r+   test_lostRETRFTPClientTests.test_lostRETR!	  s)    $	 +7'"$KK$$VU3NN  "!!#"4"4[$"GHPP%%	
 	  0--/1AB	!%%'1c001r2   c                   ^ ^ [         R                  " 5       mU 4S jnU U4S jnU U4S jnUT R                  l        T R	                  5         T R                  R                  S5      u  pEUR                  U5        UR                  U5        T R                  T R                  R                  5       S5        T R                  R                  5         T R                  R                  [        T R                  5      5        T R                  T R                  R                  5       S5        T R                  R                  5         T R                  R                  S5        [        R                  " XE/5      $ )aL  
Test the STOR command: send a file and verify its content.

L{ftp.FTPClient.storeFile} should return a two-tuple of Deferreds.
The first of which should fire with a protocol instance when the
data connection has been established and is responsible for sending
the contents of the file.  The second of which should fire when the
upload has completed, the data connection has been closed, and the
server has acknowledged receipt of the file.

(XXX - storeFile should take a producer as an argument, instead, and
only return a Deferred which fires when the upload has succeeded or
failed).
c                   > TR                   R                  S5        U R                  R                  S5        U R	                  5         U R                  [        R                  " [        R                  " S5      5      5        g NrI  rB  r  
r)   rF   r   r  finishrh   r   r  r   rL  senderr;   s    r+   cbStore0FTPClientTests.test_passiveSTOR.<locals>.cbStoreX	  Y    KK$$G "";/MMO!!'//%2F2Fr2J"KLr2   c                 F   > TR                  TR                  5       S5        g rA  r   r<  ignr;   r  s    r+   cbFinish1FTPClientTests.test_passiveSTOR.<locals>.cbFinish`	      RXXZ5r2   c                    > TR                  U S5        TR                  US5        UR                  X45      nUR                  T5        g Nr   rH  r   r   r  rn   ro   r?   r   r;   r  s       r+   rN  2FTPClientTests.test_passiveSTOR.<locals>.cbConnectc	  C    T;/T5)))4,7E  $r2   rP  rQ     STOR spam
rS  )r   rK  r)   rT  r  r  r   r   r   r<  r  rF   rq   r   r   )r;   r{  r  rN  r   r   r  s   `     @r+   test_passiveSTORFTPClientTests.test_passiveSTORG	  s    **,	M	6	% &/"&&v.
w
x --/=  !=>--/1AB  !:;""B8,,r2   c                   ^ ^ [         R                  " 5       mU 4S jnU U4S jnUT R                  l        T R	                  5         T R                  R                  S5      u  p4UR                  U5        T R                  U[        R                  5        T R                  T R                  R                  5       S5        T R                  R                  5         T R                  R                  [        T R                  5      5        T R                  T R                  R                  5       S5        T R                  R                  5         T R                  R                  S5        [         R"                  " X4/5      $ )z
Test a failure in the STOR command.

If the server does not acknowledge successful receipt of the
uploaded file, the second Deferred returned by
L{ftp.FTPClient.storeFile} should errback with L{ftp.CommandFailed}.
c                   > TR                   R                  S5        U R                  R                  S5        U R	                  5         U R                  [        R                  " [        R                  " S5      5      5        g rv  rw  ry  s    r+   r{  /FTPClientTests.test_failedSTOR.<locals>.cbStore	  r}  r2   c                    > TR                  U S5        TR                  US5        UR                  X45      nUR                  T5        g r  r  r  s       r+   rN  1FTPClientTests.test_failedSTOR.<locals>.cbConnect	  r  r2   rP  rQ  r  s.   426 Transfer aborted.  Data connection closed.)r   rK  r)   rT  r  r  r   r   r   r   r   r   r<  r  rF   rq   r   r   )r;   r{  rN  r   r   r  s   `    @r+   test_failedSTORFTPClientTests.test_failedSTORv	  s
    **,	M	% &/"&&v.
w2s001--/=  !=>--/1AB  !RS""B8,,r2   c                 f  ^ ^ [         R                  " 5       mST R                  l        U4S jnU 4S jnU U4S jnUT R                  l        T R                  5         T R                  R                  S5      u  pEUR                  U5        UR                  U5        [        R                  " XE/5      $ )z
Test the STOR command in non-passive mode.

Like L{test_passiveSTOR} but in the configuration where the server
establishes the data connection to the client, rather than the other
way around.
Fc                 z   > S[         R                  " SS5      -   U l        U R                  R	                  T5        g )Nr  r   rZ  )r   rk   r\  r   r  )r]  r  s    r+   r^  .FTPClientTests.test_STOR.<locals>.generatePort	  s0    "S%7%7T%JJGL++B/r2   c           	        > TR                  TR                  R                  5       SR                  [        R
                  " SS5      5      R                  TR                  R                  5      5        TR                  R                  5         TR                  R                  S5        TR                  TR                  R                  5       S5        TR                  R                  5         TR                  R                  S5        U R                  R                  S5        U R                  5         U R                  [        R                  " [         R"                  " S5      5      5        TR                  R                  S	5        g )
Nrb  r   rZ  rc  r  rI  rB  r  rS  )r   r   r<  r[  r   rk   rl   r)   rm   r  rF   r  rx  rh   r   r  r   rL  ry  s    r+   r{  )FTPClientTests.test_STOR.<locals>.cbStore	  s   $$&%%c&8&8d&KLTTKK)) NN  "KK$$^4T^^1135EFNN  "KK$$G "";/MMO!!'//%2F2Fr2J"KLKK$$%>?r2   c                 F   > TR                  TR                  5       S5        g rA  r  r  s    r+   r  *FTPClientTests.test_STOR.<locals>.cbFinish	  r  r2   rP  )
r   rK  r)   r  rd  r  r  r   r   r   )r;   r^  r{  r  r   r   r  s   `     @r+   	test_STORFTPClientTests.test_STOR	  s     **,#	0	@&	6 +7'&&v.
w
x ""B8,,r2   c                 P  ^  U 4S jnU 4S jnUT R                   l        T R                  5         [        R                  " 5       nT R                   R                  SU5      R                  X5      nT R                  T R                  R                  5       S5        T R                  R                  5         T R                   R                  [        T R                   5      5        T R                  T R                  R                  5       S5        T R                   R                  S5        U$ )a  
Test the LIST command.

L{ftp.FTPClient.list} should return a Deferred which fires with a
protocol instance which was passed to list after the command has
succeeded.

(XXX - This is a very unfortunate API; if my understanding is
correct, the results are always at least line-oriented, so allowing
a per-line parser function to be specified would make this simpler,
but a default implementation should really be provided which knows
how to deal with all the formats used in real servers, so
application developers never have to care about this insanity.  It
would also be nice to either get back a Deferred of a list of
filenames or to be able to consume the files as they are received
(which the current API does allow, but in a somewhat inconvenient
fashion) -exarkun)
c                    > UR                    Vs/ s H  o"S   PM	     nn/ SQnUR                  5         UR                  5         TR                  X45        g s  snf Nr  r  r  bazr  r  r   r  r  r0   flsexpectedr;   s        r+   cbList/FTPClientTests.test_passiveLIST.<locals>.cbList	  G    *2..9.QZ=.C9,HMMOHHJS+	 :   Ac                   > TR                  U S5        TR                  US5        UR                  X45      nUR                  [        R                  " 5       5        TR
                  R                  S5        / SQnU H  nUR                  U5        M     UR                  [        R                  " [        R                  " S5      5      5        g )Nr   rH  rI  s8   -rw-r--r--    0 spam      egg      100 Oct 10 2006 foo
s8   -rw-r--r--    3 spam      egg      100 Oct 10 2006 bar
s8   -rw-r--r--    4 spam      egg      100 Oct 10 2006 baz
r  rJ  )rn   ro   r?   r   sendingrr  r;   s         r+   rN  2FTPClientTests.test_passiveLIST.<locals>.cbConnect	  s    T;/T5)))4,7E  !>!>!@AKK$$GG
 ""1%   1E1Eb1I!JKr2   foo/barrQ     LIST foo/bar
rS  )r)   rT  r  r   r  rk  r   r   r   r<  r  rF   rq   )r;   r  rN  r  r_   s   `    r+   test_passiveLISTFTPClientTests.test_passiveLIST	  s    (	,	L" &/"**,KKY1==fO--/=  !=>--/1DE  !:;r2   c           	        ^  ST R                   l        U 4S jnU 4S jnUT R                   l        T R                  5         [        R
                  " 5       nT R                   R                  SU5      R                  X#5      nT R                  T R                  R                  5       SR                  [        R                  " SS5      5      R                  T R                   R                  5      5        T R                  R                  5         T R                   R!                  S5        T R                  T R                  R                  5       S	5        T R                  R                  5         T R                   R!                  S
5        U$ )z
Test the LIST command in non-passive mode.

Like L{test_passiveLIST} but in the configuration where the server
establishes the data connection to the client, rather than the other
way around.
Fc                   > SR                  [        R                  " SS5      5      U l        U R                  R                  [        R                  " 5       5        TR                  R                  S5        / SQnU H  nU R                  R                  U5        M      U R                  R                  [        R                  " [        R                  " S5      5      5        g )NrY  r   rZ  rI  r  r  r[  r   rk   r\  r   r  r   rK  r)   rF   rc   rh   r   r  r   rL  )r]  r  rr  r;   s      r+   r^  .FTPClientTests.test_LIST.<locals>.generatePort
  s    $++C,>,>{D,QRGL++M,I,I,KLKK$$GG
   --a0 ++GOOE<P<PQS<T,UVr2   c                    > UR                    Vs/ s H  o"S   PM	     nn/ SQnUR                  5         UR                  5         TR                  X45        g s  snf r  r  r  s        r+   r  (FTPClientTests.test_LIST.<locals>.cbList
  r  r  r  rb  r   rZ  rc  r  rS  )r)   r  rd  r  r   r  rk  r   r   r   r<  r[  rk   rl   rm   r  rF   )r;   r^  r  r  r_   s   `    r+   	test_LISTFTPClientTests.test_LIST	  s    $	W	, +7'**,KKY1==fONN  "!!#"4"4[$"GHPP%%	
 	  0--/1DE  !:;r2   c                 f  ^  U 4S jnUT R                   l        T R                  5         [        R                  " 5       nT R                   R                  SU5      nT R                  U[        R                  5        T R                  T R                  R                  5       S5        T R                  R                  5         T R                   R                  [        T R                   5      5        T R                  T R                  R                  5       S5        T R                   R                  S5        U$ )z
Test a failure in LIST command.

L{ftp.FTPClient.list} should return a Deferred which fails with
L{ftp.CommandFailed} if the server indicates the indicated path is
invalid for some reason.
c                 b  > TR                  U S5        TR                  US5        UR                  X45      nUR                  [        R                  " 5       5        TR
                  R                  S5        UR                  [        R                  " [        R                  " S5      5      5        g ri  rj  rM  s       r+   rN  1FTPClientTests.test_failedLIST.<locals>.cbConnect8
  rl  r2   r  rQ  r  &   550 foo/bar: No such file or directory)r)   rT  r  r   r  rk  r   r   r   r   r<  r  rF   rq   )r;   rN  r  r_   s   `   r+   test_failedLISTFTPClientTests.test_failedLIST/
  s    	L &/"**,KKY11c//0--/=  !=>--/1DE  !JKr2   c           	        ^  ST R                   l        U 4S jnU 4S jnUT R                   l        T R                  5         [	        5       nT R                   R                  SU5      R                  X#5      nT R                  T R                  R                  5       SR                  [        R                  " SS5      5      R                  T R                   R                  5      5        T R                  R                  5         T R                   R!                  S5        T R                  T R                  R                  5       S	5        T R                   R!                  S
5        U$ )z
Test the NLST command in non-passive mode.

L{ftp.FTPClient.nlst} should return a Deferred which fires with a
list of filenames when the list command has completed.
Fc                   > SR                  [        R                  " SS5      5      U l        U R                  R                  [        R                  " 5       5        TR                  R                  S5        U R                  R                  S5        U R                  R                  S5        U R                  R                  S5        U R                  R                  [        R                  " [        R                  " S5      5      5        g )	NrY  r   rZ  rI     foo
   bar
   baz
r  r  )r]  r;   s    r+   r^  .FTPClientTests.test_NLST.<locals>.generatePortW
  s    $++C,>,>{D,QRGL++M,I,I,KLKK$$G ))*5))*5))*5++GOOE<P<PQS<T,UVr2   c                    > UR                   R                  TR                  R                  5      R	                  5       n/ SQnUR                  5         UR                  5         TR                  X#5        g )Nr  )r]   decoder)   rm   r  r  r   r  r   r  r  r;   s       r+   r  (FTPClientTests.test_NLST.<locals>.cbListb
  sO    ,,%%dkk&;&;<GGIC,HMMOHHJS+r2   r  rb  r   rZ  rc     NLST foo/bar
rS  )r)   r  rd  r  rY   nlstr   r   r   r<  r[  r   rk   rl   rm   r  rF   )r;   r^  r  lstprotor_   s   `    r+   	test_NLSTFTPClientTests.test_NLSTN
  s    $		W	, +7'%'KKY1==fONN  "!!#"4"4[$"GHPP%%	
 	  0--/1DE  !:;r2   c                 :  ^  U 4S jnU 4S jnUT R                   l        T R                  5         [        5       nT R                   R	                  SU5      R                  X5      nT R                  T R                  R                  5       S5        T R                  R                  5         T R                   R                  [        T R                   5      5        T R                  T R                  R                  5       S5        T R                   R                  S5        U$ )z
Test the NLST command.

Like L{test_passiveNLST} but in the configuration where the server
establishes the data connection to the client, rather than the other
way around.
c                    > UR                   R                  5       n/ SQnUR                  5         UR                  5         TR                  X#5        g )N)r}  r~  s   baz)r]   r  r  r   r  s       r+   r  /FTPClientTests.test_passiveNLST.<locals>.cbList
  s:    ,,))+C/HMMOHHJS+r2   c                   > TR                  U S5        TR                  US5        UR                  X45      nUR                  [        R                  " 5       5        TR
                  R                  S5        UR                  S5        UR                  S5        UR                  S5        UR                  [        R                  " [        R                  " S5      5      5        g )Nr   rH  rI  r  r  r  r  rJ  rM  s       r+   rN  2FTPClientTests.test_passiveNLST.<locals>.cbConnect
  s    T;/T5)))4,7E  !>!>!@AKK$$G z*z*z*  1E1Eb1I!JKr2   r  rQ  r  rS  )r)   rT  r  rY   r  r   r   r   r<  r  rF   rq   )r;   r  rN  r  r_   s   `    r+   test_passiveNLSTFTPClientTests.test_passiveNLSTy
  s    	,	L &/"%'KKY1==fO--/=  !=>--/1DE  !:;r2   c                 ~  ^ ^ [         R                  " 5       mU U4S jnUT R                  l        T R	                  5         [        5       nT R                  R                  SU5      nT R                  U[        R                  5        T R                  T R                  R                  5       S5        T R                  R                  5         T R                  R                  [        T R                  5      5        T R                  T R                  R                  5       S5        T R                  R                  S5        U$ )z
Test a failure in NLST command.

L{ftp.FTPClient.nlst} should return a Deferred which fails with
L{ftp.CommandFailed} if the server indicates the indicated path is
invalid for some reason.
c                 <  > TR                  U S5        TR                  US5        UR                  X45      nUR                  T5        TR                  R	                  S5        UR                  [        R                  " [        R                  " S5      5      5        g ri  )
r   r   r  r)   rF   rh   r   r  r   rL  r  s       r+   rN  1FTPClientTests.test_failedNLST.<locals>.cbConnect
  s|    T;/T5)))4,7E  $KK$$G   1E1Eb1I!JKr2   r  rQ  r  r  )r   rK  r)   rT  r  rY   r  r   r   r   r   r   r<  r  rF   rq   )r;   rN  r  r_   r  s   `   @r+   test_failedNLSTFTPClientTests.test_failedNLST
  s     **,	L &/"%'KKY11c//0--/=  !=>--/1DE  !JKr2   c                 z   U R                  5         U R                  R                  SS5      nU R                  U R                  R                  5       S5        U R                  R                  5         SnU R                  R                  UR                  U R                  R                  5      5        U R                  U R                  R                  5       S5        SnU R                  R                  UR                  U R                  R                  5      5        UR                  U R                  U/U/45        U$ )z
L{ftp.FTPClient.rename} issues I{RNTO} and I{RNFR} commands and returns
a L{Deferred} which fires when a file has successfully been renamed.
/spam/ham   RNFR /spam
z8350 Requested file action pending further information.
   RNTO /ham
r  )r  r)   renamer   r   r<  r  rF   rl   rm   r   )r;   r_   fromResponse
toResponses       r+   test_renameFromTo FTPClientTests.test_renameFromTo
  s    
 	KKw/--/1BCS  !4!4T[[5J5J!KL--/1AB=
  !2!24;;3H3H!IJ	d&&,*(FGr2   c                 "   U R                  5         SnSnU R                  R                  X5        U R                  R                  S5        U R                  R                  S5        U R	                  U R
                  R                  5       S5        g)z
L{ftp.FTPClient.rename} issues I{RNTO} and I{RNFR} commands with paths
escaped according to U{http://cr.yp.to/ftp/filesystem.html}.
z/foo/ba
r/bazz/qu
uxs   350 s   250 s!   RNFR /foo/ba r/baz
RNTO /qu ux
N)r  r)   r  rF   r   r   r<  )r;   fromFiletoFiles      r+   test_renameFromToEscapesPaths,FTPClientTests.test_renameFromToEscapesPaths
  so    
 	#8,  )  )NN  "$V	
r2   c                    U R                  5         U R                  R                  SS5      nU R                  U R                  R                  5       S5        U R                  R                  5         U R                  R                  S5        U R                  U R                  R                  5       S5        U R                  U[        R                  5      $ )z
The L{Deferred} returned by L{ftp.FTPClient.rename} is errbacked with
L{CommandFailed} if the I{RNFR} command receives an error response code
(for example, because the file does not exist).
r  r  r  !   550 Requested file unavailable.
r2   r  r)   r  r   r   r<  r  rF   r   r   r   r   s     r+   $test_renameFromToFailingOnFirstError3FTPClientTests.test_renameFromToFailingOnFirstError
  s     	KKw/--/1BC  !GH--/5!!!S%6%677r2   c                    U R                  5         U R                  R                  SS5      nU R                  U R                  R                  5       S5        U R                  R                  5         U R                  R                  S5        U R                  U R                  R                  5       S5        U R                  R                  S5        U R                  U[        R                  5      $ )z
The L{Deferred} returned by L{ftp.FTPClient.rename} is errbacked with
L{CommandFailed} if the I{RNTO} command receives an error response code
(for example, because the destination directory does not exist).
r  r  r  s8   350 Requested file action pending further information.
r  r  r  r   s     r+   "test_renameFromToFailingOnRenameTo1FTPClientTests.test_renameFromToFailingOnRenameTo
  s     	KKw/--/1BC  I	
 	--/1AB  !GH!!!S%6%677r2   c                    U R                  5         U R                  R                  S5      nU R                  U R                  R                  5       S5        U R                  R                  S5        UR                  U R                  S/5      $ )z
L{ftp.FTPClient.makeDirectory} issues a I{MKD} command and returns a
L{Deferred} which is called back with the server's response if the
directory is created.
r     MKD /spam
s   257 "/spam" created.z257 "/spam" created.)r  r)   makeDirectoryr   r   r<  rF   r   r   s     r+   test_makeDirectory!FTPClientTests.test_makeDirectory
  sn     	KK%%g.--/1AB  !89}}T--0F/GHHr2   c                     U R                  5         U R                  R                  S5      nU R                  U R                  R                  5       S5        U R                  R                  S5        U$ )zt
L{ftp.FTPClient.makeDirectory} escapes the path name it sends according
to U{http://cr.yp.to/ftp/filesystem.html}.
z/sp
ams   MKD /sp am
s   257 win)r  r)   r  r   r   r<  rF   r   s     r+   test_makeDirectoryPathEscape+FTPClientTests.test_makeDirectoryPathEscape  sY    
 	KK%%i0--/1EF 	  ,r2   c                 "   U R                  5         U R                  R                  S5      nU R                  U R                  R                  5       S5        U R                  R                  S5        U R                  U[        R                  5      $ )z
L{ftp.FTPClient.makeDirectory} returns a L{Deferred} which is errbacked
with L{CommandFailed} if the server returns an error response code.
r  r  s   550 PERMISSION DENIED)
r  r)   r  r   r   r<  rF   r   r   r   r   s     r+   test_failedMakeDirectory'FTPClientTests.test_failedMakeDirectory%  sl    
 	KK%%g.--/1AB  !9:!!!S%6%677r2   c                   ^  U 4S jnT R                  5         T R                  R                  5       R                  U5      nT R	                  T R
                  R                  5       S5        T R                  R                  S5        U$ )z
Test the getDirectory method.

L{ftp.FTPClient.getDirectory} should return a Deferred which fires with
the current directory on the server. It wraps PWD command.
c                 *   > TR                  U S5        g )Nr&  r   r  s    r+   cbGet/FTPClientTests.test_getDirectory.<locals>.cbGet9  s    S*-r2   r*  r+  )r  r)   getDirectoryr   r   r   r<  rF   )r;   r   r_   s   `  r+   test_getDirectory FTPClientTests.test_getDirectory1  sf    	. 	KK$$&2259--/<  !23r2   c                 $   U R                  5         U R                  R                  5       nU R                  U[        R
                  5        U R                  U R                  R                  5       S5        U R                  R                  S5        U$ )zR
Test a failure in getDirectory method.

The behaviour should be the same as PWD.
r*  r0  
r  r)   r  r   r   r   r   r   r<  rF   r   s     r+   test_failedGetDirectory&FTPClientTests.test_failedGetDirectoryB  sk     	KK$$&1c//0--/<  !KLr2   c                 $   U R                  5         U R                  R                  5       nU R                  U[        R
                  5        U R                  U R                  R                  5       S5        U R                  R                  S5        U$ )z
Test a different failure in getDirectory method.

The response should be quoted to be parsed, so it returns an error
otherwise.
r*  s   257 /bar/bazr  r   s     r+   test_anotherFailedGetDirectory-FTPClientTests.test_anotherFailedGetDirectoryO  sj     	KK$$&1c//0--/<  1r2   c                 f   U R                  5         U R                  R                  S5      nU R                  U R                  R                  5       S5        SnU R                  R                  UR                  U R                  R                  5      5        UR                  U R                  U/5      $ )z
L{ftp.FTPClient.removeFile} sends a I{DELE} command to the server for
the indicated file and returns a Deferred which fires after the server
sends a 250 response code.
	/tmp/test   DELE /tmp/test
*250 Requested file action okay, completed.)
r  r)   
removeFiler   r   r<  rF   rl   rm   r   r;   r_   responses      r+   test_removeFileFTPClientTests.test_removeFile]  s     	KK"";/--/1FG?  1F1F!GH}}T--z::r2   c                   ^ ^ T R                  5         T R                  R                  S5      nT R                  T R                  R                  5       S5        SmT R                  R                  TR                  T R                  R                  5      5        T R                  U[        R                  5      nUR                  UU 4S j5        U$ )z
If the server returns a response code other than 250 in response to a
I{DELE} sent by L{ftp.FTPClient.removeFile}, the L{Deferred} returned
by C{removeFile} is errbacked with a L{Failure} wrapping a
L{CommandFailed}.
r  r  ,501 Syntax error in parameters or arguments.c                 @   > TR                  U R                  T/45      $ r7   r   excr  r;   s    r+   r{  6FTPClientTests.test_failedRemoveFile.<locals>.<lambda>w      $"2"2388xj]"Kr2   )r  r)   r  r   r   r<  rF   rl   rm   r   r   r   r   r  s   ` @r+   test_failedRemoveFile$FTPClientTests.test_failedRemoveFilej  s     	KK"";/--/1FGA  1F1F!GHq#"3"34	KLr2   c                 L  ^ ^ T R                  5         T R                  R                  S5      nSmT R                  R                  TR	                  T R                  R
                  5      5        T R                  U[        R                  5      nUR                  UU 4S j5        U$ )z
If the server returns a response line which cannot be parsed, the
L{Deferred} returned by L{ftp.FTPClient.removeFile} is errbacked with a
L{BadResponse} containing the response.
r  765 blah blah blahc                 @   > TR                  U R                  T/45      $ r7   r   r  s    r+   r{  BFTPClientTests.test_unparsableRemoveFileResponse.<locals>.<lambda>  r  r2   )
r  r)   r  rF   rl   rm   r   r   BadResponser   r  s   ` @r+   !test_unparsableRemoveFileResponse0FTPClientTests.test_unparsableRemoveFileResponsez  su     	KK"";/'  1F1F!GHq#//2	KLr2   c                     U R                  5         U R                  R                  S5      nU R                  R                  S5        U R                  R                  S5        UR	                  U R
                  5      $ )z
If the server returns multiple response lines, the L{Deferred} returned
by L{ftp.FTPClient.removeFile} is still fired with a true value if the
ultimate response code is 250.
r     250-perhaps a progress report   250 okay)r  r)   r  rF   r   r  r   s     r+    test_multilineRemoveFileResponse/FTPClientTests.test_multilineRemoveFileResponse  sZ     	KK"";/  !AB  -}}T__--r2   c                 f   U R                  5         U R                  R                  S5      nU R                  U R                  R                  5       S5        SnU R                  R                  UR                  U R                  R                  5      5        UR                  U R                  U/5      $ )z
L{ftp.FTPClient.removeDirectory} sends a I{RMD} command to the server
for the indicated directory and returns a Deferred which fires after
the server sends a 250 response code.
r     RMD /tmp/test
r  )
r  r)   removeDirectoryr   r   r<  rF   rl   rm   r   r  s      r+   test_removeDirectory#FTPClientTests.test_removeDirectory  s     	KK''4--/1EF?  1F1F!GH}}T--z::r2   c                   ^ ^ T R                  5         T R                  R                  S5      nT R                  T R                  R                  5       S5        SmT R                  R                  TR                  T R                  R                  5      5        T R                  U[        R                  5      nUR                  UU 4S j5        U$ )z
If the server returns a response code other than 250 in response to a
I{RMD} sent by L{ftp.FTPClient.removeDirectory}, the L{Deferred}
returned by C{removeDirectory} is errbacked with a L{Failure} wrapping
a L{CommandFailed}.
r  r+  r  c                 @   > TR                  U R                  T/45      $ r7   r   r  s    r+   r{  ;FTPClientTests.test_failedRemoveDirectory.<locals>.<lambda>  r  r2   )r  r)   r,  r   r   r<  rF   rl   rm   r   r   r   r   r  s   ` @r+   test_failedRemoveDirectory)FTPClientTests.test_failedRemoveDirectory  s     	KK''4--/1EFA  1F1F!GHq#"3"34	KLr2   c                 L  ^ ^ T R                  5         T R                  R                  S5      nSmT R                  R                  TR	                  T R                  R
                  5      5        T R                  U[        R                  5      nUR                  UU 4S j5        U$ )z
If the server returns a response line which cannot be parsed, the
L{Deferred} returned by L{ftp.FTPClient.removeDirectory} is errbacked
with a L{BadResponse} containing the response.
r  r  c                 @   > TR                  U R                  T/45      $ r7   r   r  s    r+   r{  GFTPClientTests.test_unparsableRemoveDirectoryResponse.<locals>.<lambda>  r  r2   )
r  r)   r,  rF   rl   rm   r   r   r"  r   r  s   ` @r+   &test_unparsableRemoveDirectoryResponse5FTPClientTests.test_unparsableRemoveDirectoryResponse  su     	KK''4'  1F1F!GHq#//2	KLr2   c                     U R                  5         U R                  R                  S5      nU R                  R                  S5        U R                  R                  S5        UR	                  U R
                  5      $ )z
If the server returns multiple response lines, the L{Deferred} returned
by L{ftp.FTPClient.removeDirectory} is still fired with a true value
 if the ultimate response code is 250.
r  r&  r'  )r  r)   r,  rF   r   r  r   s     r+   %test_multilineRemoveDirectoryResponse4FTPClientTests.test_multilineRemoveDirectoryResponse  sZ     	KK''4  !AB  -}}T__--r2   )r)   r   N)/rR   rS   rT   rU   r   r   r  r  r  r  r"  r-  r1  r:  r=  rU  re  rm  rr  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r
  r  r  r#  r(  r-  r2  r7  r:  rW   rO   r2   r+   r  r    s    .;8>*((%N#J@$L--^#-J*-X5n/b>)V&P@(
 8$8&I
8"; 
.; 
.r2   r  c                   6    \ rS rSrSrS rS rS rS rS r	Sr
g	)
FTPClientBasicTestsi  z
FTP client
c                     [         R                  " 5       nUR                  S5        U R                  S/UR                  5        g)z/
The first response is captured as a greeting.
   220 Imaginary FTP.z220 Imaginary FTP.Nr   r   rF   r   greetingr;   r  s     r+   test_greeting!FTPClientBasicTests.test_greeting  s;     &&(	45./1C1CDr2   c                     [         R                  " 5       nUR                  S5        U R                  S/UR                  5        g)zh
Responses with no message are still valid, i.e. three digits
followed by a space is complete response.
s   220 z220 Nr@  rB  s     r+   test_responseWithNoMessage.FTPClientBasicTests.test_responseWithNoMessage  s8    
 &&(	w'&9#5#56r2   c                 
   [         R                  " 5       n[        R                  " 5       Ul        UR                  S5        UR                  S5      n/ nUR                  UR                  5        UR                  U R                  5        UR                  S5        U R                  / U5        UR                  S5        U R                  / U5        UR                  S5        U R                  / U5        UR                  S5        U R                  / U5        UR                  S5        U R                  / U5        UR                  S5        U R                  / U5        UR                  S	5        U R                  / S
QUS   5        g)z
Multiline response
r?  BLAHs   210-First line.s   123-Second line.s   Just some text.s   Hir2   s   321s	   210 Done.)z210-First line.z123-Second line.zJust some text.Hir  321z	210 Done.r   N)r   r   r   rK  r   rF   r   r   rC   r  r2  r   )r;   r  r  r  s       r+   test_MultilineResponse*FTPClientBasicTests.test_MultilineResponse  s\    &&(	+;;=	45 //7V]]+DII& 	12V$ 	23V$ 	12V$ 	u%V$ 	s#V$ 	v&V$ 	|, 1I	
r2   c                    [         R                  " 5       n[        R                  " 5       Ul        UR                  S5        UR                  SS5        U R                  SUR                  R                  5       5        UR                  R                  5         UR                  S5        U R                  SUR                  R                  5       5        g)z?
Passing None as the password avoids sending the PASS command.
   220 Welcome to Imaginary FTP.bobN
   USER bob
s   200 Hello bob.r2   
r   r   r   rK  r   rF   
queueLoginr   r<  r  rB  s     r+   test_noPasswordGiven(FTPClientBasicTests.test_noPasswordGiven  s    
 &&(	+;;=	?@ 	UD))*=*=*C*C*EF 	!!#01 	i11779:r2   c                    [         R                  " 5       n[        R                  " 5       Ul        UR                  S5        UR                  SS5        U R                  SUR                  R                  5       5        UR                  R                  5         UR                  S5        U R                  SUR                  R                  5       5        g)zA
Receiving a 230 response to USER prevents PASS from being sent.
rO  rP  secretrQ  s#   230 Hello bob.  No password needed.r2   NrR  rB  s     r+   test_noPasswordNeeded)FTPClientBasicTests.test_noPasswordNeeded-  s    
 &&(	+;;=	?@ 	UH-)*=*=*C*C*EF 	!!#EF 	i11779:r2   rO   N)rR   rS   rT   rU   r   rC  rF  rL  rT  rX  rW   rO   r2   r+   r=  r=    s"    E74
l;*;r2   r=  c                       \ rS rSrSrS rSrg)PathHandlingTestsiD  z
Handling paths.
c                    SS/4SS/4S/ 4S/ SQ4S/ SQ4SS/4SS/44 H,  u  pU R                  [        R                  " / U5      U5        M.     S	SS	/4S
SS	/4SS	/4SS	/4S/ SQ4S/ SQ4SS	S/4SS	S/44 H-  u  pU R                  [        R                  " S/U5      U5        M/     S/ 4SS/4SS/4SSS	/44 H,  u  pU R                  [        R                  " / U5      U5        M.     S/ 4SS	/4S/ SQ44 H-  u  pU R                  [        R                  " S/U5      U5        M/     S/ 4S/ 4SS/4S/ 4SS/4SS/4SSS/4S SS/4S!S/4S"S/4S#/ 4S$/ 44 H-  u  pU R                  [        R                  " S/U5      U5        M/     S% H3  nU R                  [        R                  [        R                  / U5        M5     S& H4  nU R                  [        R                  [        R                  S/U5        M6     g')(z
Normalize paths.
r0  z/a/za/b/c)r0  r1  cz/a/b/cz/a/za/r1  zb/z/bz/b/zb/czb/c/z/b/cr^  z/b/c/z//z//aza//za//bz//bzb//c..../za/..xz/a/..z/a/b/..z/a/b/../z	/a/b/../cz
/a/b/../c/z/a/b/../../cz/a/b/../../c/z/a/b/../../c/..z/a/b/../../c/../)	r_  r`  za/../..za/../../z/..z/../z/a/../..z	/a/../../z/a/b/../../..)z../..z../../z
../a/../..N)r   r   
toSegmentsro  InvalidPath)r;   inpoutps      r+   test_Normalizer!PathHandlingTests.test_NormalizerI  sp   
 3%LC5M"Io&'SENC5M
IC S^^B4d;
 3*C:C5MSENO$_%c3Z sCj!	
IC S^^SE37>	
 2JSENSENc3Z 	
IC S^^B4d;
  *usenv6OPICS^^SE37> Q 2JBKcUObM#3*%C:&cU#se$#$
IC S^^SE37>
 

C coos~~r3G

 5Ccoos~~ucJ 5r2   rO   N)rR   rS   rT   rU   r   rf  rW   rO   r2   r+   r[  r[  D  s    DKr2   r[  c                   *    \ rS rSrSrS rS rS rSrg)IsGlobbingExpressionTestsi  z3
Tests for _isGlobbingExpression utility function.
c                     U R                  [        R                  " 5       5        U R                  [        R                  " / 5      5        U R                  [        R                  " S5      5        g)zF
_isGlobbingExpression will return False for None, or empty
segments.
Nr  r   _isGlobbingExpressionr:   s    r+   &test_isGlobbingExpressionEmptySegments@IsGlobbingExpressionTests.test_isGlobbingExpressionEmptySegments  sM    
 	22452226722489r2   c                     U R                  [        R                  " SS/5      5        U R                  [        R                  " SS/5      5        g)z
_isGlobbingExpression will return False for plain segments.

Also, it only checks the last segment part (filename) and will not
check the path name.
r  expr*.txtNrk  r:   s    r+   test_isGlobbingExpressionNoGlob9IsGlobbingExpressionTests.test_isGlobbingExpressionNoGlob  s@     	22Hf3EFG22GV3DEFr2   c                     U R                  [        R                  " SS/5      5        U R                  [        R                  " SS/5      5        U R                  [        R                  " SS/5      5        g)z}
_isGlobbingExpression will return True for segments which contains
globbing characters in the last segment part (filename).
r  rq  z	[a-b].txtzfil?.txtN)r  r   rl  r:   s    r+   test_isGlobbingExpressionGlob7IsGlobbingExpressionTests.test_isGlobbingExpressionGlob  sX    
 	118W2EFG118[2IJK118Z2HIJr2   rO   N)	rR   rS   rT   rU   r   rm  rr  ru  rW   rO   r2   r+   ri  ri    s    :GKr2   ri  c                   0    \ rS rSrSrS rS rS rS rSr	g)	BaseFTPRealmTestsi  z}
Tests for L{ftp.BaseFTPRealm}, a base class to help define L{IFTPShell}
realms with different user home directory policies.
c                 ^    U R                  [        [        [        R                  5      5        g)z+
L{ftp.BaseFTPRealm} implements L{IRealm}.
N)r  r   r
   r   BaseFTPRealmr:   s    r+   test_interface BaseFTPRealmTests.test_interface  s     	FC,<,<=>r2   c                 z  ^^ [         R                  " U R                  5       5      m/ m " UU4S jS[        R                  5      nU" U R                  5       5      nUR                  SS[        R                  5      u  p4nU R                  U[        R                  5        U R                  UR                  T5        g)z
L{ftp.BaseFTPRealm} calls its C{getHomeDirectory} method with the
avatarId being requested to determine the home directory for that
avatar.
c                   $   > \ rS rSrU U4S jrSrg):BaseFTPRealmTests.test_getHomeDirectory.<locals>.TestRealmi  c                 *   > TR                  U5        T$ r7   r  )r;   avatarIdavatarsr  s     r+   getHomeDirectoryKBaseFTPRealmTests.test_getHomeDirectory.<locals>.TestRealm.getHomeDirectory  s    x(r2   rO   N)rR   rS   rT   rU   r  rW   )r  r  s   r+   	TestRealmr    s     r2   r  alice@example.comN)r   r   r   r   rz  requestAvatar	IFTPShellr;  FTPShellr   filesystemRoot)r;   r  realmifaceavatarlogoutr  r  s         @@r+   test_getHomeDirectory'BaseFTPRealmTests.test_getHomeDirectory  s     ""4;;=1	 	(( 	
 $++-( % 3 3s}}!
v 	fcll3..7r2   c                 T   U R                  5       n[        R                  " U5      nUR                  [        R
                  S[        R                  5      u  p4nU R                  U[        R                  5        U R                  UR                  [        R                  " U5      5        g)za
L{ftp.BaseFTPRealm} returns an L{ftp.FTPAnonymousShell} instance for
anonymous avatar requests.
N)r   r   rz  r  r   	ANONYMOUSr  r;  r;  r   r  r   r   )r;   ru   r  r  r  r  s         r+   test_anonymous BaseFTPRealmTests.test_anonymous  s~    
 KKM	  + % 3 3cmm!
v 	fc&;&;<..0A0A)0LMr2   c                     [         R                  " U R                  5       5      nU R                  [        UR
                  [        5       5        g)zy
L{ftp.BaseFTPRealm.getHomeDirectory} should be overridden by a subclass
and raises L{NotImplementedError} if it is not.
N)r   rz  r   ro  NotImplementedErrorr  r   )r;   r  s     r+   test_notImplemented%BaseFTPRealmTests.test_notImplemented  s5    
   /-u/E/EvxPr2   rO   N)
rR   rS   rT   rU   r   r{  r  r  r  rW   rO   r2   r+   rx  rx    s    
?8*NQr2   rx  c                   $    \ rS rSrSrS rS rSrg)FTPRealmTestsi  z
Tests for L{ftp.FTPRealm}.
c                     Sn[         R                  " U R                  5       U5      nUR                  S5      nU R	                  [
        R                  " U5      R                  S5      U5        g)z
L{ftp.FTPRealm} accepts an extra directory to its initializer and treats
the avatarId passed to L{ftp.FTPRealm.getHomeDirectory} as a single path
segment to construct a child of that directory.
z/path/to/homer  N)r   r   r   r  r   r   r   r  )r;   baser  homes       r+   r  #FTPRealmTests.test_getHomeDirectory  sW     T[[]D1%%&9:**40667JKTRr2   c                     [         R                  " U R                  5       5      nUR                  S5      nU R	                  [
        R                  " S5      U5        g)z
If no extra directory is passed to L{ftp.FTPRealm}, it uses C{"/home"}
as the base directory containing all user home directories.
r  z/home/alice@example.comN)r   r   r   r  r   r   r   )r;   r  r  s      r+   test_defaultHomeDirectory'FTPRealmTests.test_defaultHomeDirectory  sE    
 T[[]+%%&9:**+DEtLr2   rO   N)rR   rS   rT   rU   r   r  r  rW   rO   r2   r+   r  r    s    	SMr2   r  c                   (    \ rS rSrSr\rS rS rSr	g)SystemFTPRealmTestsi  z"
Tests for L{ftp.SystemFTPRealm}.
c                 "   [         R                  " 5       nSSKnUR                  U5      R                  n[
        R                  " U R                  5       5      nUR                  U5      nU R                  U[        R                  " U5      5        g)z
L{ftp.SystemFTPRealm.getHomeDirectory} treats the avatarId passed to it
as a username in the underlying platform and returns that account's home
directory.
r   N)getpassgetuserr,  getpwnampw_dirr   SystemFTPRealmr   r  r   r   r   )r;   r  r,  r  r  r  s         r+   r  )SystemFTPRealmTests.test_getHomeDirectory
  sj      
 	<<%,,""4;;=1%%d+x00:;r2   c                    [         R                  " [        R                  5      SR	                  S [        S5       5       5      -   n[        R                  " U R                  5       5      nU R                  [        UR                  U5        g)z
L{ftp.SystemFTPRealm.getHomeDirectory} raises L{UnauthorizedLogin} when
passed a username which has no corresponding home directory in the
system's accounts database.
r  c              3      #    U  H:  n[         R                  " [        R                  [        R                  -   5      v   M<     g 7fr7   )randomchoicestringascii_lettersdigits).0rz  s     r+   	<genexpr>6SystemFTPRealmTests.test_noSuchUser.<locals>.<genexpr>%  s.      =
IQAFMM&..>??s   AAr  N)r  r  r  r  rl  rj  r   r  r   ro  r	   r  )r;   r  r  s      r+   test_noSuchUser#SystemFTPRealmTests.test_noSuchUser  sj     }}V112RWW =
INq=
 6
 
 ""4;;=1+U-C-CTJr2   rO   N)
rR   rS   rT   rU   r   nonPOSIXSkipr/   r  r  rW   rO   r2   r+   r  r    s     D<(Kr2   r  c                   B    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
rg)ErrnoToFailureTestsi,  z1
Tests for L{ftp.errnoToFailure} errno checking.
c                     [         R                  " [        R                  S5      nU R	                  U[         R
                  5      $ )zC
C{errno.ENOENT} should be translated to L{ftp.FileNotFoundError}.
r  )r   errnoToFailureerrnoENOENTr   FileNotFoundErrorr   s     r+   test_notFound!ErrnoToFailureTests.test_notFound1  3     u||U3!!!S%:%:;;r2   c                     [         R                  " [        R                  S5      nU R	                  U[         R
                  5      $ )zF
C{errno.EPERM} should be translated to L{ftp.PermissionDeniedError}.
r  )r   r  r  EPERMr   PermissionDeniedErrorr   s     r+   test_permissionDenied)ErrnoToFailureTests.test_permissionDenied8  s3     u{{E2!!!S%>%>??r2   c                     [         R                  " [        R                  S5      nU R	                  U[         R
                  5      $ )zG
C{errno.EACCES} should be translated to L{ftp.PermissionDeniedError}.
r  )r   r  r  EACCESr   r  r   s     r+   test_accessDenied%ErrnoToFailureTests.test_accessDenied?  s3     u||U3!!!S%>%>??r2   c                     [         R                  " [        R                  S5      nU R	                  U[         R
                  5      $ )zG
C{errno.ENOTDIR} should be translated to L{ftp.IsNotADirectoryError}.
r  )r   r  r  ENOTDIRr   IsNotADirectoryErrorr   s     r+   test_notDirectory%ErrnoToFailureTests.test_notDirectoryF  s3     u}}e4!!!S%=%=>>r2   c                     [         R                  " [        R                  S5      nU R	                  U[         R
                  5      $ )zA
C{errno.EEXIST} should be translated to L{ftp.FileExistsError}.
r  )r   r  r  EEXISTr   FileExistsErrorr   s     r+   test_fileExists#ErrnoToFailureTests.test_fileExistsM  s3     u||U3!!!S%8%899r2   c                     [         R                  " [        R                  S5      nU R	                  U[         R
                  5      $ )zC
C{errno.EISDIR} should be translated to L{ftp.IsADirectoryError}.
r  )r   r  r  EISDIRr   r(  r   s     r+   test_isDirectory$ErrnoToFailureTests.test_isDirectoryT  r  r2   c                      [        S5      e! [         a0    [        R                  " SS5      nU R	                  U[         5      s $ f = f)zo
If an unknown errno is passed to L{ftp.errnoToFailure}, it should let
the originating exception pass through.
r  r  r  )r  BaseExceptionr   r  r   r   s     r+   test_passThrough$ErrnoToFailureTests.test_passThrough[  sF    
	7u%% 	7""2u-A%%a66	7s    7AArO   N)rR   rS   rT   rU   r   r  r  r  r  r  r  r  rW   rO   r2   r+   r  r  ,  s,    <@@?:<	7r2   r  c                       \ rS rSrSrS rSrg)AnonymousFTPShellTestsig  z"
Test anonymous shell properties.
c                     [         R                  " S5      nUR                  S5      nU R                  U[         R                  5        U$ )z\
Check that L{ftp.FTPAnonymousShell} returns an error when trying to
open it in write mode.
r  r  )r   r;  r  r   r  )r;   r  r_   s      r+   test_anonymousWrite*AnonymousFTPShellTests.test_anonymousWritel  s?    
 %%b)  *1c778r2   rO   N)rR   rS   rT   rU   r   r  rW   rO   r2   r+   r  r  g  s    r2   r  c                       \ rS rSrSrS rS rS rS)S jrS r	S r
S	 rS
 rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS r S r!S  r"S! r#S" r$S# r%S$ r&S% r'S& r(S'r)g()*IFTPShellTestsMixiniw  z/
Generic tests for the C{IFTPShell} interface.
c                     [        5       e)z
Test if the directory exists at C{path}.

@param path: the relative path to check.
@type path: C{str}.

@return: C{True} if C{path} exists and is a directory, C{False} if
    it's not the case
@rtype: C{bool}
r  r;   r  s     r+   directoryExists#IFTPShellTestsMixin.directoryExists|       "##r2   c                     [        5       e)z
Create a directory in C{path}.

@param path: the relative path of the directory to create, with one
    segment.
@type path: C{str}
r  r  s     r+   r  #IFTPShellTestsMixin.createDirectory  s     "##r2   c                     [        5       e)z
Test if the file exists at C{path}.

@param path: the relative path to check.
@type path: C{str}.

@return: C{True} if C{path} exists and is a file, C{False} if it's not
    the case.
@rtype: C{bool}
r  r  s     r+   
fileExistsIFTPShellTestsMixin.fileExists  r  r2   c                     [        5       e)z
Create a file named C{path} with some content.

@param path: the relative path of the file to create, without
    directory.
@type path: C{str}

@param fileContent: the content of the file.
@type fileContent: C{str}
r  r;   r  fileContents      r+   
createFileIFTPShellTestsMixin.createFile  r  r2   c                     U R                  U R                  S5      5        U R                  S5        U R                  U R                  S5      5        g)z
C{directoryExists} should report correctly about directory existence,
and C{createDirectory} should create a directory detectable by
C{directoryExists}.
r  N)r  r  r  r  r:   s    r+   test_createDirectory(IFTPShellTestsMixin.test_createDirectory  sB     	--e45U#,,U34r2   c                     U R                  U R                  S5      5        U R                  S5        U R                  U R                  S5      5        g)z
C{fileExists} should report correctly about file existence, and
C{createFile} should create a file detectable by C{fileExists}.
file.txtN)r  r  r  r  r:   s    r+   test_createFile#IFTPShellTestsMixin.test_createFile  s<    
 	45
#
34r2   c                 h   ^  T R                   R                  S5      nU 4S jnUR                  U5      $ )z9
Create a directory and check it ends in the filesystem.
r  c                 F   > TR                  TR                  S5      5        g )Nr  )r  r  r  s    r+   r  2IFTPShellTestsMixin.test_makeDirectory.<locals>.cb  s    OOD0078r2   )r  r  r   r  s   `  r+   r  &IFTPShellTestsMixin.test_makeDirectory  s/     JJ$$X.	9 }}R  r2   c                     U R                  S5        U R                  R                  S5      nU R                  U[        R
                  5      $ )zU
Creating a directory that already exists should fail with a
C{ftp.FileExistsError}.
r  r  )r  r  r  r   r   r  r   s     r+   test_makeDirectoryError+IFTPShellTestsMixin.test_makeDirectoryError  s?    
 	U#JJ$$X.!!!S%8%899r2   c                    ^  T R                  S5        T R                  R                  S5      nU 4S jnUR                  U5      $ )zG
Try to remove a directory and check it's removed from the filesystem.
r  r  c                 F   > TR                  TR                  S5      5        g r  )r  r  r  s    r+   r  4IFTPShellTestsMixin.test_removeDirectory.<locals>.cb  s    T11%89r2   )r  r  r,  r   r  s   `  r+   r-  (IFTPShellTestsMixin.test_removeDirectory  s=     	U#JJ&&x0	: }}R  r2   c                     U R                  S5        U R                  R                  S5      nU R                  U[        R
                  5      $ )zV
removeDirectory should not work in file and fail with a
C{ftp.IsNotADirectoryError}.
r  r  )r  r  r,  r   r   r  r   s     r+   test_removeDirectoryOnFile.IFTPShellTestsMixin.test_removeDirectoryOnFile  s=    
 	
#JJ&&}5!!!S%=%=>>r2   c                 x    U R                   R                  S5      nU R                  U[        R                  5      $ )zT
Removing directory that doesn't exist should fail with a
C{ftp.FileNotFoundError}.
r  )r  r,  r   r   r  r   s     r+   test_removeNotExistingDirectory3IFTPShellTestsMixin.test_removeNotExistingDirectory  s1    
 JJ&&x0!!!S%:%:;;r2   c                    ^  T R                  S5        T R                  R                  S5      nU 4S jnUR                  U5        U$ )zB
Try to remove a file and check it's removed from the filesystem.
r  r	  c                 F   > TR                  TR                  S5      5        g Nr  )r  r  r  s    r+   r  /IFTPShellTestsMixin.test_removeFile.<locals>.cb  s    T__Z89r2   )r  r  r  r   r  s   `  r+   r  #IFTPShellTestsMixin.test_removeFile  s=     	
#JJ!!-0	: 	
br2   c                     U R                  S5        U R                  R                  S5      nU R                  U[        R
                  5      $ )z*
removeFile should not work on directory.
nedr  )r  r  r  r   r   r(  r   s     r+   test_removeFileOnDirectory.IFTPShellTestsMixin.test_removeFileOnDirectory  s?     	U#JJ!!(+!!!S%:%:;;r2   c                 x    U R                   R                  S5      nU R                  U[        R                  5      $ )zT
Try to remove a non existent file, and check it raises a
L{ftp.FileNotFoundError}.
r  )r  r  r   r   r  r   s     r+   test_removeNotExistingFile.IFTPShellTestsMixin.test_removeNotExistingFile  s1    
 JJ!!(+!!!S%:%:;;r2   c                    ^  T R                  S5        T R                  S5        T R                  R                  S5      nU 4S jnUR	                  U5      $ )z&
Check the output of the list method.
r  r  .c                 V   > U R                  5         TR                  U S/ 4S/ 4/5        g )Nr  r  r  r   r  r;   s    r+   r  )IFTPShellTestsMixin.test_list.<locals>.cb  s*    FFHQ*b!1E2; ?@r2   r  r  r  rk  r   r  s   `  r+   	test_listIFTPShellTestsMixin.test_list  sH     	U#
#JJOOF#	A }}R  r2   c                    ^  T R                  S5        T R                  S5        T R                  R                  SS5      nU 4S jnUR	                  U5      $ )z,
Check the output of list with asked stats.
r  r  r  )r  permissionsc                 @  > U R                  5         TR                  [        U 5      S5        TR                  U S   S   S5        TR                  U S   S   S5        TR                  [        U S   S   5      S5        TR                  [        U S   S   5      S5        g )Nr|  r   r  r   r  )r  r   r:  r!  s    r+   r  1IFTPShellTestsMixin.test_listWithStat.<locals>.cb*  s    FFHSVQ'QqT!Wj1QqT!We, S1a\1-S1a\1-r2   r#  r  s   `  r+   test_listWithStat%IFTPShellTestsMixin.test_listWithStat  sO     	U#
#JJOO
	. }}R  r2   c                     U R                  S5        U R                  R                  SS5      nU R                  U[        5      $ )@
Querying an invalid stat should result to a C{AttributeError}.
r  r  r  whateverstat)r  r  rk  r   AttributeErrorr   s     r+   test_listWithInvalidStat,IFTPShellTestsMixin.test_listWithInvalidStat6  sA     	U#JJOO
 !!!^44r2   c                    ^  T R                  S5        T R                  R                  S5      nU 4S jnUR                  U5      $ )z0
Check the output of the list method on a file.
r  r	  c                 P   > U R                  5         TR                  U S/ 4/5        g r  r   r!  s    r+   r  -IFTPShellTestsMixin.test_listFile.<locals>.cbK  s$    FFHQ*b!1 23r2   )r  r  rk  r   r  s   `  r+   test_listFile!IFTPShellTestsMixin.test_listFileD  s9     	
#JJOOM*	4 }}R  r2   c                 x    U R                   R                  S5      nU R                  U[        R                  5      $ )zU
list on a directory that doesn't exist should fail with a
L{ftp.FileNotFoundError}.
r  )r  rk  r   r   r  r   s     r+   test_listNotExistingDirectory1IFTPShellTestsMixin.test_listNotExistingDirectoryQ  s/    
 JJOOH%!!!S%:%:;;r2   c                 ^    U R                  S5        U R                  R                  S5      nU$ )z
Try to access a resource.
r  r  )r  r  accessr   s     r+   test_accessIFTPShellTestsMixin.test_accessY  s+     	U#JJh'r2   c                 x    U R                   R                  S5      nU R                  U[        R                  5      $ )z6
access should fail on a resource that doesn't exist.
r  )r  r<  r   r   r  r   s     r+   test_accessNotFound'IFTPShellTestsMixin.test_accessNotFounda  s1     JJh'!!!S%:%:;;r2   c                    ^  T R                  S5        T R                  R                  S5      nU 4S jnUR                  U5        U$ )zI
Check that openForReading returns an object providing C{ftp.IReadFile}.
r  r	  c                 b   > TR                  [        R                  R                  U 5      5        g r7   )r  r   	IReadFile
providedByr  s    r+   r  3IFTPShellTestsMixin.test_openForReading.<locals>.cbo  s    OOCMM44S9:r2   )r  r  rV  r   r  s   `  r+   test_openForReading'IFTPShellTestsMixin.test_openForReadingh  s=     	
#JJ%%m4	; 	
br2   c                 x    U R                   R                  S5      nU R                  U[        R                  5      $ )zZ
openForReading should fail with a C{ftp.FileNotFoundError} on a file
that doesn't exist.
r  )r  rV  r   r   r  r   s     r+   test_openForReadingNotFound/IFTPShellTestsMixin.test_openForReadingNotFoundu  s1    
 JJ%%h/!!!S%:%:;;r2   c                     U R                  S5        U R                  R                  S5      nU R                  U[        R
                  5      $ )z.
openForReading should not work on directory.
r  r  )r  r  rV  r   r   r(  r   s     r+   test_openForReadingOnDirectory2IFTPShellTestsMixin.test_openForReadingOnDirectory}  s?     	U#JJ%%h/!!!S%:%:;;r2   c                 |   ^ ^ T R                   R                  S5      nUU 4S jnU 4S jmUR                  U5        U$ )zJ
Check that openForWriting returns an object providing C{ftp.IWriteFile}.
r  c                    > TR                  [        R                  R                  U 5      5        U R	                  5       R                  T5      $ r7   )r  r   
IWriteFilerE  r)  r   )r  cb2r;   s    r+   cb14IFTPShellTestsMixin.test_openForWriting.<locals>.cb1  s5    OOCNN55c:;;;=,,S11r2   c                 P   > TR                  [        R                  " U 5      5        g r7   )r  r   rE  r  s    r+   rR  4IFTPShellTestsMixin.test_openForWriting.<locals>.cb2  s    OOI0056r2   )r  r  r   )r;   r_   rS  rR  s   `  @r+   test_openForWriting'IFTPShellTestsMixin.test_openForWriting  s6     JJ%%h/	2	7 	
cr2   c                     U R                  S5        U R                  R                  S5      nU R                  U[        R
                  5      $ )zL
openForWriting should not be able to open a directory that already
exists.
r  r  )r  r  r  r   r   r(  r   s     r+   $test_openForWritingExistingDirectory8IFTPShellTestsMixin.test_openForWritingExistingDirectory  s?    
 	U#JJ%%h/!!!S%:%:;;r2   c                     U R                  S5        U R                  R                  S5      nU R                  U[        R
                  5      $ )zs
openForWring should fail with a L{ftp.FileNotFoundError} if you specify
a file in a directory that doesn't exist.
r  )r  idonotexistr  )r  r  r  r   r   r  r   s     r+   )test_openForWritingInNotExistingDirectory=IFTPShellTestsMixin.test_openForWritingInNotExistingDirectory  s@    
 	U#JJ%%&CD!!!S%:%:;;r2   c                    ^ ^ SmT R                  ST5        T R                  R                  SS5      nUU 4S jnUR                  U5        U$ )z0
Check the output of the stat method on a file.
   wobble
r  r	  r  r   c                 j   > TR                  U S   [        T5      5        TR                  U S   5        g )Nr   r   )r   r:  r  )r  r  r;   s    r+   r  -IFTPShellTestsMixin.test_statFile.<locals>.cb  s.    SVS%56SV$r2   )r  r  statr   )r;   r_   r  r  s   `  @r+   test_statFile!IFTPShellTestsMixin.test_statFile  sE     "
K0JJOOM+@A	% 	
br2   c                    ^  T R                  S5        T R                  R                  SS5      nU 4S jnUR                  U5        U$ )z5
Check the output of the stat method on a directory.
r  r  rb  c                 .   > TR                  U S   5        g )Nr   )r  r  s    r+   r  2IFTPShellTestsMixin.test_statDirectory.<locals>.cb  s    OOCF#r2   r  r  re  r   r  s   `  r+   test_statDirectory&IFTPShellTestsMixin.test_statDirectory  s@     	U#JJOOH&;<	$ 	
br2   c                    ^  T R                  S5        T R                  R                  SS5      nU 4S jnUR                  U5        U$ )z#
Check the owner and groups stats.
r  r  r  r   c                 <   > TR                  [        U 5      S5        g )Nr|  r  r  s    r+   r  3IFTPShellTestsMixin.test_statOwnerGroup.<locals>.cb  s    SXq)r2   rk  r  s   `  r+   test_statOwnerGroup'IFTPShellTestsMixin.test_statOwnerGroup  s@     	U#JJOOH&89	* 	
br2   c                   ^^ U R                   R                  mS mUU4S jnXR                   l        U R                  S5        U R                   R                  SS5      nU R	                  U R                  U5      S/5        g)zj
If L{twisted.python.filepath.FilePath.getNumberOfHardLinks} is not
implemented, the number returned is 0
c                      [         er7   r  rO   r2   r+   raiseNotImplementedQIFTPShellTestsMixin.test_statHardlinksNotImplemented.<locals>.raiseNotImplemented      %%r2   c                 &   > T" U 5      nTUl         U$ r7   )getNumberOfHardLinksr  r0   pathFuncrv  s     r+   notImplementedFilePathTIFTPShellTestsMixin.test_statHardlinksNotImplemented.<locals>.notImplementedFilePath  s    A%8A"Hr2   r  r  )	hardlinksr   Nr  _pathr  re  r   successResultOfr;   r}  r_   r|  rv  s      @@r+    test_statHardlinksNotImplemented4IFTPShellTestsMixin.test_statHardlinksNotImplemented  si    
 ::##	&	
 2

U#JJOOHn5--a01#6r2   c                   ^^ U R                   R                  mS mUU4S jnXR                   l        U R                  S5        U R                   R                  SS5      nU R	                  U R                  U5      SS/5        g)z
If L{twisted.python.filepath.FilePath.getUserID} or
L{twisted.python.filepath.FilePath.getGroupID} are not implemented,
the owner returned is "0" and the group is returned as "0"
c                      [         er7   r  rO   r2   r+   rv  RIFTPShellTestsMixin.test_statOwnerGroupNotImplemented.<locals>.raiseNotImplemented  rx  r2   c                 4   > T" U 5      nTUl         TUl        U$ r7   )	getUserID
getGroupIDr{  s     r+   r}  UIFTPShellTestsMixin.test_statOwnerGroupNotImplemented.<locals>.notImplementedFilePath  s    A-AK.ALHr2   r  r  ro  0Nr  r  s      @@r+   !test_statOwnerGroupNotImplemented5IFTPShellTestsMixin.test_statOwnerGroupNotImplemented  sl     ::##	&	 2

U#JJOOH&89--a03*=r2   c                 z    U R                   R                  SS5      nU R                  U[        R                  5      $ )zN
stat should fail with L{ftp.FileNotFoundError} on a file that doesn't
exist.
r  rb  )r  re  r   r   r  r   s     r+   test_statNotExisting(IFTPShellTestsMixin.test_statNotExisting  s2    
 JJOOH&;<!!!S%:%:;;r2   c                     U R                  S5        U R                  R                  SS5      nU R                  U[        5      $ )r-  r  r  r.  )r  r  re  r   r0  r   s     r+   test_invalidStat$IFTPShellTestsMixin.test_invalidStat  s:     	U#JJOOH&>?!!!^44r2   c                    ^  T R                  S5        T R                  R                  SS5      nU 4S jnUR                  U5      $ )z
Try to rename a directory.
r  r  r  c                    > TR                  TR                  S5      5        TR                  TR                  S5      5        g )Nr  r  )r  r  r  r  s    r+   r  +IFTPShellTestsMixin.test_rename.<locals>.cb  s3    OOD0078T11%89r2   )r  r  r  r   r  s   `  r+   test_renameIFTPShellTestsMixin.test_rename  s?     	U#JJh1	: }}R  r2   c                 z    U R                   R                  SS5      nU R                  U[        R                  5      $ )zT
Renaming a directory that doesn't exist should fail with
L{ftp.FileNotFoundError}.
r  r  )r  r  r   r   r  r   s     r+   test_renameNotExisting*IFTPShellTestsMixin.test_renameNotExisting  s3    
 JJh1!!!S%:%:;;r2   rO   Nr2   )*rR   rS   rT   rU   r   r  r  r  r  r  r  r  r  r-  r
  r  r  r  r  r$  r*  r1  r6  r9  r=  r@  rG  rJ  rM  rW  rZ  r^  rf  rl  rr  r  r  r  r  r  r  rW   rO   r2   r+   r  r  w  s    $$$$55	!:
!?<<<!!45!<<<< <<7*>.<5!<r2   r  c                   :    \ rS rSrSrS rS rS rS rS
S jr	Sr
g	)FTPShellTestsi"  z'
Tests for the C{ftp.FTPShell} object.
c                     [         R                  " U R                  5       5      U l        U R                  R	                  5         [
        R                  " U R                  5      U l        g)z2
Create a root directory and instantiate a shell.
N)r   r   r   r  r  r   r  r  r:   s    r+   r   FTPShellTests.setUp'  s@     %%dkkm4			!!#\\$)),
r2   c                 T    U R                   R                  U5      R                  5       $ )z*
Test if the directory exists at C{path}.
)r  r  isdirr  s     r+   r  FTPShellTests.directoryExists/  s      yyt$**,,r2   c                 T    U R                   R                  U5      R                  5       $ )z 
Create a directory in C{path}.
)r  r  r  r  s     r+   r  FTPShellTests.createDirectory5  s      yyt$4466r2   c                 T    U R                   R                  U5      R                  5       $ )z%
Test if the file exists at C{path}.
)r  r  isfiler  s     r+   r  FTPShellTests.fileExists;  s      yyt$++--r2   c                 V    U R                   R                  U5      R                  U5      $ )z0
Create a file named C{path} with some content.
)r  r  
setContentr  s      r+   r  FTPShellTests.createFileA  s"     yyt$//<<r2   )r  r  Nr  )rR   rS   rT   rU   r   r   r  r  r  r  rW   rO   r2   r+   r  r  "  s     --7.=r2   r  c                   .    \ rS rSrSrSrS rS rS rSr	g)TestConsumeriH  z
A simple consumer for tests. It only works with non-streaming producers.

@ivar producer: an object providing
    L{twisted.internet.interfaces.IPullProducer}.
Nc                 p    U R                   b   e/ U l        Xl         U R                   R                  5         g)z
Simple register of producer, checks that no register has happened
before.

@param producer: pull producer to use
@param streaming: unused
N)producerr]   resumeProducing)r;   r  	streamings      r+   registerProducerTestConsumer.registerProducerS  s0     }}$$$ %%'r2   c                 0    U R                   c   eSU l         g)z>
Unregister the producer, it should be done after a register.
N)r  r:   s    r+   unregisterProducerTestConsumer.unregisterProducer`  s     }}(((r2   c                 n    U R                   R                  U5        U R                  R                  5         g)z6
Save the data received.

@param data: data to append
N)r]   rC   r  r  rJ   s     r+   r  TestConsumer.writeg  s&     	4 %%'r2   )r]   r  )
rR   rS   rT   rU   r   r  r  r  r  rW   rO   r2   r+   r  r  H  s     H((r2   r  c                   $    \ rS rSrSrS rS rSrg)TestProduceriq  z
A dumb producer.
c                     Xl         X l        g)z}
@param toProduce: data to write
@type toProduce: C{str}
@param consumer: the consumer of data.
@type consumer: C{IConsumer}
N)	toProducerO  )r;   r  rO  s      r+   r<   TestProducer.__init__v  s     # r2   c                 N    U R                   R                  U R                  5        g)z
Send the data to consume.
N)rO  r  r  r:   s    r+   startTestProducer.start  s     	DNN+r2   )rO  r  N)rR   rS   rT   rU   r   r<   r  rW   rO   r2   r+   r  r  q  s    !,r2   r  c                   6    \ rS rSrSrS rS rS rS rS r	Sr
g	)
IReadWriteTestsMixini  zB
Generic tests for the C{IReadFile} and C{IWriteFile} interfaces.
c                     [        5       e)zg
Return an object providing C{IReadFile}, ready to send data C{content}.

@param content: data to send
r  r;   contents     r+   getFileReader"IReadWriteTestsMixin.getFileReader  s     "##r2   c                     [        5       e)zB
Return an object providing C{IWriteFile}, ready to receive data.
r  r:   s    r+   getFileWriter"IReadWriteTestsMixin.getFileWriter       "##r2   c                     [        5       e)z&
Return the content of the file used.
r  r:   s    r+   getFileContent#IReadWriteTestsMixin.getFileContent  r  r2   c                    ^ ^^^ Sm[        5       mUU4S jnUUU 4S jmT R                  T5      R                  U5      $ )z
Test L{ftp.IReadFile}: the implementation should have a send method
returning a C{Deferred} which fires when all the data has been sent
to the consumer, and the data should be correctly send to the consumer.
ra  c                 D   > U R                  T5      R                  T5      $ r7   )rP  r   )readercbSendrO  s    r+   r   -IReadWriteTestsMixin.test_read.<locals>.cbGet  s    ;;x(44V<<r2   c                 \   > TR                  SR                  TR                  5      T5        g r\   )r   rl  r]   )r  rO  r  r;   s    r+   r  .IReadWriteTestsMixin.test_read.<locals>.cbSend  s     SXXhoo6@r2   )r  r  r   )r;   r   r  rO  r  s   ` @@@r+   	test_readIReadWriteTestsMixin.test_read  s:     >	=	A !!'*66u==r2   c                 t   ^ ^^^ SmU4S jnUU4S jmUU 4S jmT R                  5       R                  U5      $ )z
Test L{ftp.IWriteFile}: the implementation should have a receive
method returning a C{Deferred} which fires with a consumer ready to
receive data to be written. It should also have a close() method that
returns a Deferred.
s   elbbow
c                 D   > U R                  5       R                  TU 5      $ r7   )r)  r   )writer	cbReceives    r+   r   .IReadWriteTestsMixin.test_write.<locals>.cbGet  s    >>#//	6BBr2   c                    > [        TU 5      nU R                  S S5        UR                  5         U R                  5         UR	                  5       R                  T5      $ )NT)r  r  r  r  r'   r   )rO  r  r  cbCloser  s      r+   r  2IReadWriteTestsMixin.test_write.<locals>.cbReceive  sL    #GX6H%%dD1NN'')<<>--g66r2   c                 F   > TR                  TR                  5       T5        g r7   )r   r  )r   r  r;   s    r+   r  0IReadWriteTestsMixin.test_write.<locals>.cbClose  s    T002G<r2   )r  r   )r;   r   r  r  r  s   ` @@@r+   
test_writeIReadWriteTestsMixin.test_write  s6     	C	7	= !!#//66r2   rO   N)rR   rS   rT   rU   r   r  r  r  r  r  rW   rO   r2   r+   r  r    s     $$$>"7r2   r  c                   0    \ rS rSrSrS rS rS rS rSr	g)	FTPReadWriteTestsi  z
Tests for C{ftp._FileReader} and C{ftp._FileWriter}, the objects returned
by the shell in C{openForReading}/C{openForWriting}.
c                     [         R                  " U R                  5       5      U l        U R                  R	                  5         [
        R                  " U R                  5      U l        SU l        g)z%
Create a temporary file used later.
r  N)	r   r   r   r  r  r   r  r  r  r:   s    r+   r   FTPReadWriteTests.setUp  sG     %%dkkm4			!!#\\$)),
"r2   c                     U R                   R                  U R                  5      R                  U5        U R                  R                  U R                  45      $ )zF
Return a C{ftp._FileReader} instance with a file opened for reading.
)r  r  r  r  r  rV  r  s     r+   r  FTPReadWriteTests.getFileReader  s?     			&11':zz(($--)9::r2   c                 N    U R                   R                  U R                  45      $ )zF
Return a C{ftp._FileWriter} instance with a file opened for writing.
)r  r  r  r:   s    r+   r  FTPReadWriteTests.getFileWriter  s      zz(($--)9::r2   c                 h    U R                   R                  U R                  5      R                  5       $ )z+
Return the content of the temporary file.
)r  r  r  
getContentr:   s    r+   r   FTPReadWriteTests.getFileContent  s$     yyt}}-88::r2   )r  r  r  N)
rR   rS   rT   rU   r   r   r  r  r  rW   rO   r2   r+   r  r    s    
#;;;r2   r  c                   (    \ rS rSrSrSrS rS rSrg)CloseTestWriteri  z
Close writing to a file.
Fc                     [        5       U l        [        R                  " U R                  5      n[        R
                  " U5      $ )z&
Receive bytes.

@return: L{Deferred}
)r   r]   r   FileConsumerr   r   )r;   fcs     r+   r)  CloseTestWriter.receive  s0     idkk*}}R  r2   c                 (    SU l         U R                  $ )z$
Close bytes.

@return: L{Deferred}
T)closeStartedr_   r:   s    r+   r'   CloseTestWriter.close  s     !vvr2   )r]   r  N)	rR   rS   rT   rU   r   r  r)  r'   rW   rO   r2   r+   r  r    s     L!r2   r  c                       \ rS rSrSrS rSrg)CloseTestShelli	  z
Close writing shell.
c                 B    [         R                  " U R                  5      $ r7   )r   r   r  )r;   segss     r+   r  CloseTestShell.openForWriting  s    }}T[[))r2   rO   N)rR   rS   rT   rU   r   r  rW   rO   r2   r+   r  r  	  s    *r2   r  c                       \ rS rSrSrS rSrg)FTPCloseTestsi  z0
Tests that the server invokes IWriteFile.close
c                 d   [         R                  " 5       nS/Ul        [        5       Ul        [        5       UR                  l        [        R                  " 5       UR                  R                  l	        [         R                  " 5       Ul        SUR                  l        UR                  [        5       5        [         R                  " 5       n[         R                   " U5      Ul        X!l        UR                  S5        / nUR%                  S5      nUR'                  UR(                  5        U R+                  UR                  R                  R,                  S5        UR/                  S5        U R+                  UR                  R                  R,                  S5        UR1                  S5        U R3                  UR                  R                  R,                  S5        U R+                  U5        UR                  R                  R                  R5                  S5        U R3                  U5        U$ )	zn
Confirm that FTP uploads (i.e. ftp_STOR) correctly call and wait
upon the IWriteFile object's close() method
r  Nr  zclose() called earlys   some data herezreason is ignoredzclose() not calledzallow close() to finish)r   FTPworkingDirectoryr  r  r  r  r   r^   r_   r   r?   timeOutr  r   rf  rX  r  ftp_STORr   rC   r  r  rc   rh   r  rf   )r;   r0   di	stor_doner_   s        r+   r  FTPCloseTests.test_write  sx   
 GGI$X "(* >>+NN$	 			#WWY^^A&

$	JJv	i&&'446LM
)*446LM
-.335IJ#	!!";<	"r2   rO   N)rR   rS   rT   rU   r   r  rW   rO   r2   r+   r   r     s    !r2   r   c                       \ rS rSrSrS rSrg)FTPResponseCodeTestsi;  z,
Tests relating directly to response codes.
c           	         [        [        R                  5      n[        5       n[        [        5      R	                  5        H  u  p4[        U[        5      (       d  M  UR                  5       (       d  M3  U R                  UUSR                  X45      5        U R                  UUSU< SU< 35        UR                  U5        M     g)z
All of the response code globals (for example C{RESTART_MARKER_REPLY} or
C{USR_NAME_OK_NEED_PASS}) have unique values and are present in the
C{RESPONSE} dictionary.
z4Code {!r} with value {!r} missing from RESPONSE dictzDuplicate code z with value N)setr   RESPONSEvarsitems
isinstancern  isupperr  r[  assertNotInadd)r;   	allValues
seenValueskeyr<  s        r+   test_unique FTPResponseCodeTests.test_unique@  s     %	U
s)//+JC%%%#++--JQQ   %cWL	B
 u% ,r2   rO   N)rR   rS   rT   rU   r   r  rW   rO   r2   r+   r
  r
  ;  s    &r2   r
  )r   rH  )\r   r  r  r   r  r   r   r  ior   zope.interfacer   zope.interface.verifyr   twisted.credr   r   r   twisted.cred.errorr	   twisted.cred.portalr
   twisted.internetr   r   r   r   r   twisted.internet.interfacesr   twisted.protocolsr   r   r   twisted.pythonr   r   r   twisted.testr   twisted.test.testutilsr   r   twisted.trial.unittestr   platform	isWindowsr  r,   r.   r1   LineReceiverr4   r  rY   rq   rs   r   r   r  r`  r  r  r  r/  rO  rz  r  r  r  r  r  r  r=  r[  ri  rx  r  r  r  r  r  r  r  r  r  r  rQ  r  r  r   r
  rO   r2   r+   <module>r)     s     	  	    & - 6 6 0 & B B 1 2 2 5 5 & < +!!##L*L%2 45 E (	** 	
*Y9 Y9x
) 
2W
+ W
tp#4 pfm,'8 m,`  1Q    &'G & &.X,'G X,vf
'G f
R~h ~B":x ":P("" ( C33  J$( J$Z> >Bm.X m.`u;( u;pIK IKXK KD4Q 4QnMH M4&K( &KR87( 87vX  h< h<V#=H1 #=L Y%( %( %(P, ,,@7 @7F ;"6  ;F S^^  6* *&H &R&8 &r2   