+
    Dfj                         R t ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIH	t	H
t
 ^ RIHt ^ RIHt ^ RIHt ^ RIHt ^ RIHtHt ^ RIHt ^ R	IHtHtHtHtHt ^ R
IHt ^ RI H!t! ^ RI"H#t# ^ RI$H%t% ^ RI&H't' ^ RI(H)t) ^ RI*H+t+ ^ RI,H-t- ^ RI.H/t/ ]-! R4      t0]-! R4      t1]0'       d.    ^ RI2H3t3 ^ RI4H5t5 ^ RI6H7t7 ^ RI8H9t9 ^ RI:H;t;H<t< ^ RI=H>t> ^ RIH?t? RtAR]1]0]P                  ! ]R4      39   d   RtA]! ]AR4       ! R R ]/4      4       tC ! R! R"]/4      tD ! R# R$]!4      tE ! R% R&4      tF ! R' R(4      tG]! ]4       ! R) R*]	4      4       tH]! ]AR4       ! R+ R,]/4      4       tI ! R- R.4      tJ ! R/ R0]P                  4      tL ! R1 R2]4      tM]! ]AR4       ! R3 R4]M4      4       tN]! ]AR4       ! R5 R6]M4      4       tO]! ]AR4      ]! ]+! R74      '       * R84      ]! ]+! R94      '       * R:4       ! R; R<]M4      4       4       4       tPR#   ]@ d     EL6i ; i)=z*
Tests for L{twisted.conch.scripts.cftp}.
N)BytesIOTextIOWrapper)skipIf)implementer)ls)	ISFTPFile)FileTransferTestAvatarSFTPTestBase)portal)defererror
interfacesprotocolreactor)Clock)StringTransport)getProcessOutputAndValue)log)UserDatabase)FilePath)which)requireModule)TestCasecryptographyztwisted.conch.unix)cftp)
SSHSession)filetransfer)EXTENDED_DATA_STDERR)
test_conchtest_ssh)	FakeStdio)FileTransferForTestAvatarFTz*don't run w/o spawnProcess or cryptographyc                   Z   a  ] tR t^8t o RtV 3R lR ltV 3R lR ltV 3R lR ltRtV t	R	# )
SSHSessionTestsz5
Tests for L{twisted.conch.scripts.cftp.SSHSession}.
c                   < V ^8  d   QhRR/#    returnN )format__classdict__s   ">/usr/lib/python3/dist-packages/twisted/conch/test/test_cftp.py__annotate__SSHSessionTests.__annotate__>   s     * *t *    c                    \        4       V n        \        4       V n        V P                  V P                  n        \	        4       V n        \        V P
                  4      V n        V P                  V P                  n        R # N)r    stdior   channelr   stderrBufferr   stderrselfs   &r+   setUpSSHSessionTests.setUp>   sP    [
!|!ZZ#I#D$5$56"kkr.   c                   < V ^8  d   QhRR/# r%   r(   )r)   r*   s   "r+   r,   r-   F   s     2 2$ 2r.   c                    V P                   P                  4        V P                  V P                  P                  4       R# )zd
L{twisted.conch.scripts.cftp.SSHSession.eofReceived} loses the write
half of its stdio connection.
N)r2   eofReceived
assertTruer1   writeConnLostr5   s   &r+   test_eofReceived SSHSessionTests.test_eofReceivedF   s*    
 	  "

001r.   c                   < V ^8  d   QhRR/# r%   r(   )r)   r*   s   "r+   r,   r-   N   s     
 
 
r.   c                    RpVP                  R4      pV P                  P                  \        VR,           4       V P	                  V P
                  P                  4       VR,           4       R# )z
L{twisted.conch.scripts.cftp.SSHSession.extReceived} decodes
stderr data using UTF-8 with the "backslashescape" error handling and
writes the result to its own stderr.
u   ☃utf-8   s   \xffN)encoder2   extReceivedr   assertEqualr3   getvalue)r6   	errorText
errorBytess   &  r+   test_extReceivedStderr&SSHSessionTests.test_extReceivedStderrN   s`     "	%%g.
    	
 	&&(!	
r.   )r2   r4   r3   r1   N)
__name__
__module____qualname____firstlineno____doc__r7   r>   rJ   __static_attributes____classdictcell__r*   s   @r+   r#   r#   8   s(     * *2 2
 
r.   r#   c                     a  ] tR t^`t o Rt]! ]RR4      f   RtR tR t	R t
R tR	 t]P                  ! 4       t  ]P                   ! ]P"                  R
4       Rt]P                   ! ]P"                  ]4       ]! ]R4      R 4       tR tRtV tR#   ]P&                   d    Rt LJi ; i  ]P                   ! ]P"                  ]4       i ; i)ListingTestszw
Tests for L{lsLine}, the function which generates an entry for a file or
directory in an SFTP I{ls} command's output.
tzsetNz8Cannot test timestamp formatting code without time.tzsetc                n  a  RS n         V 3R lpS P                  \        RV4       R\        P                  9   dg   S P                  \        P                  \        P                  R\        P                  R,          4       S P                  \        P                  4       R# R pS P                  V4       R# )zW
Patch the L{ls} module's time function so the results of L{lsLine} are
deterministic.
i[c                     < S P                   # r0   nowr5   s   r+   fakeTime$ListingTests.setUp.<locals>.fakeTimep   s    88Or.   timeTZc                  v     \         P                  R  \        P                  ! 4        R#   \         d     L$i ; i)r^   N)osenvironKeyErrorr]   rV   r(   r.   r+   cleanup#ListingTests.setUp.<locals>.cleanup|   s2    

4( 

   s   * 88N)
rZ   patchr   r`   ra   
addCleanupoperatorsetitemr]   rV   )r6   r[   rc   s   f  r+   r7   ListingTests.setUpi   sy    
 	 	

2vx( 2::OOH,,bjj$

4@PQOODJJ' OOG$r.   c                    V\         P                  R&   \        P                  ! 4        \        P
                  ! RV4      # )zT
Call L{ls.lsLine} after setting the timezone to C{timezone} and return
the result.
r^   foo)r`   ra   r]   rV   r   lsLine)r6   timezonestats   &&&r+   _lsInTimezoneListingTests._lsInTimezone   s,     $

4

yy%%r.   c                    V P                   R,
          p\        P                  ! ^ ^ ^ ^ ^ ^ ^ ^ V^ 3
4      pV P                  V P	                  RV4      R4       V P                  V P	                  RV4      R4       R# )zy
A file with an mtime six months (approximately) or more in the past has
a listing including a low-resolution timestamp.
America/New_Yorkz;!---------    0 0        0               0 Apr 26  1973 fooPacific/Aucklandz;!---------    0 0        0               0 Apr 27  1973 fooNrZ   r`   stat_resultrF   ro   r6   thenrn   s   &  r+   test_oldFileListingTests.test_oldFile   |     xx01~~q!Q1aAtQ?@148I	
 	148I	
r.   c                   V P                   R,
          R,           p\        P                  ! ^ ^ ^ ^ ^ ^ ^ ^ V^ 3
4      pV P                  V P	                  RV4      R4       V P                  V P	                  RV4      R4       R# )
A file with a high-resolution timestamp which falls on a day of the
month which can be represented by one decimal digit is formatted with
one padding 0 to preserve the columns which come after it.
rr   z;!---------    0 0        0               0 May 01  1973 foors   z;!---------    0 0        0               0 May 02  1973 fooNrt   i ru   rw   s   &  r+   test_oldSingleDigitDayOfMonth*ListingTests.test_oldSingleDigitDayOfMonth        xx015EF~~q!Q1aAtQ?@148I	
 	148I	
r.   c                    V P                   R,
          p\        P                  ! ^ ^ ^ ^ ^ ^ ^ ^ V^ 3
4      pV P                  V P	                  RV4      R4       V P                  V P	                  RV4      R4       R# )z
A file with an mtime fewer than six months (approximately) in the past
has a listing including a high-resolution timestamp excluding the year.
rr   ;!---------    0 0        0               0 Aug 28 17:33 foors   ;!---------    0 0        0               0 Aug 29 09:33 fooN逛z ru   rw   s   &  r+   test_newFileListingTests.test_newFile   r{   r.   
es_AR.UTF8FTz'The es_AR.UTF8 locale is not installed.c                   V P                   R,
          p\        P                  ! ^ ^ ^ ^ ^ ^ ^ ^ V^ 3
4      p\        P                  ! 4       p\        P
                  ! \        P                  R4       V P                  \        P
                  \        P                  V4       V P                  V P                  RV4      R4       V P                  V P                  RV4      R4       R# )z3
The month name in the date is locale independent.
r   rr   r   rs   r   Nr   )
rZ   r`   rv   locale	getlocale	setlocaleLC_ALLrf   rF   ro   )r6   rx   rn   currentLocales   &   r+   test_localeIndependent#ListingTests.test_localeIndependent   s     xx01~~q!Q1aAtQ?@ ((*5((&--G148I	
 	148I	
r.   c                   V P                   R,
          R,           p\        P                  ! ^ ^ ^ ^ ^ ^ ^ ^ V^ 3
4      pV P                  V P	                  RV4      R4       V P                  V P	                  RV4      R4       R# )r}   rr   z;!---------    0 0        0               0 Sep 01 17:33 foors   z;!---------    0 0        0               0 Sep 02 09:33 fooNr   i F ru   rw   s   &  r+   test_newSingleDigitDayOfMonth*ListingTests.test_newSingleDigitDayOfMonth   r   r.   rY   )rL   rM   rN   rO   rP   getattrr]   skipr7   ro   ry   r~   r   r   r   r   r   r   
localeSkipErrorr   r   r   rQ   rR   rS   s   @r+   rU   rU   `   s     
 tWd#+I%:	&
$
(
( $$&M7	V]]L9 J6JAB
 C
,
 
= || 	J	
 	6s)   B B) B&#B) %B&&B) )CrU   c                   6   a a ] tR tRt oRtV 3R ltRtVtV ;t# )InMemorySSHChanneli  zd
Minimal implementation of a L{SSHChannel} like class which only reads and
writes data from memory.
c                >   < Wn         ^ V n        \        SV `  4        R# )z\
@param conn: The SSH connection associated with this channel.
@type conn: L{SSHConnection}
N)connlocalClosedsuper__init__)r6   r   	__class__s   &&r+   r   InMemorySSHChannel.__init__  s    
 	r.   )r   r   )	rL   rM   rN   rO   rP   r   rQ   rR   __classcell__)r   r*   s   @@r+   r   r     s     
 r.   r   c                   6   a  ] tR tRt o RtR tR tR tRtV t	R# )FilesystemAccessExpectationsi  z;
A test helper used to support expected filesystem access.
c                    / V n         R # r0   _cacher5   s   &r+   r   %FilesystemAccessExpectations.__init__  s	    r.   c                $    W0P                   W3&   R# )z

@param path: Path at which the stream is requested.
@type path: L{str}

@param path: Flags with which the stream is requested.
@type path: L{str}

@param stream: A stream.
@type stream: C{File}
Nr   )r6   pathflagsstreams   &&&&r+   put FilesystemAccessExpectations.put  s     &,TM"r.   c                :    V P                   P                  W34      # )z
Remove a stream from the memory.

@param path: Path at which the stream is requested.
@type path: L{str}

@param path: Flags with which the stream is requested.
@type path: L{str}

@return: A stream.
@rtype: C{File}
)r   pop)r6   r   r   s   &&&r+   r    FilesystemAccessExpectations.pop(  s     {{}--r.   r   N)
rL   rM   rN   rO   rP   r   r   r   rQ   rR   rS   s   @r+   r   r     s     ,. .r.   r   c                   0   a  ] tR tRt o RtR tR tRtV tR# )InMemorySFTPClienti8  a  
A L{filetransfer.FileTransferClient} which does filesystem operations in
memory, without touching the local disc or the network interface.

@ivar _availableFiles: File like objects which are available to the SFTP
    client.
@type _availableFiles: L{FilesystemRegister}
c                H    \        V 4      V n        R ^R^
/V n        Wn        R# )requests
buffersizeN)r   	transportoptions_availableFiles)r6   availableFiless   &&r+   r   InMemorySFTPClient.__init__B  s)    +D1"
  .r.   c                8    V P                   P                  W4      # )ze
@see: L{filetransfer.FileTransferClient.openFile}.

Retrieve and remove cached file based on flags.
)r   r   )r6   filenamer   attrss   &&&&r+   openFileInMemorySFTPClient.openFileJ  s     ##''88r.   )r   r   r   N)	rL   rM   rN   rO   rP   r   r   rQ   rR   rS   s   @r+   r   r   8  s     .9 9r.   r   c                   N   a  ] tR tRt o RtR tR tR tR tR t	R t
R	 tR
tV tR# )InMemoryRemoteFileiS  z3
An L{ISFTPFile} which handles all data in memory.
c                >    Wn         \        P                  ! V 4       R# )z4
@param name: Name of this file.
@type name: L{str}
N)namer   r   )r6   r   s   &&r+   r   InMemoryRemoteFile.__init__Y  s    
 	r.   c                r    V P                  V4       V P                  V4       \        P                  ! V 4      # )z
@see: L{ISFTPFile.writeChunk}
)seekwriter   succeed)r6   startdatas   &&&r+   
writeChunkInMemoryRemoteFile.writeChunka  s+     			%

4}}T""r.   c                    RV n         R# )zW
@see: L{ISFTPFile.writeChunk}

Keeps data after file was closed to help with testing.
TN)_closedr5   s   &r+   closeInMemoryRemoteFile.closei  s     r.   c                    R # r0   r(   r5   s   &r+   getAttrsInMemoryRemoteFile.getAttrsq      r.   c                    R # r0   r(   )r6   offsetlengths   &&&r+   	readChunkInMemoryRemoteFile.readChunku  r   r.   c                    R # r0   r(   )r6   r   s   &&r+   setAttrsInMemoryRemoteFile.setAttrsy  r   r.   c                .    \         P                  ! V 4      # )zJ
Get current data of file.

Allow reading data event when file is closed.
)r   rG   r5   s   &r+   rG   InMemoryRemoteFile.getvalue}  s     %%r.   )r   r   N)rL   rM   rN   rO   rP   r   r   r   r   r   r   rG   rQ   rR   rS   s   @r+   r   r   S  s2     #& &r.   r   c                      a  ] tR tRt o RtR tR tR tR tR t	R t
R	 tR
 tR tR tR tR tRR ltRR ltR tR tR tR tRtV tR# )StdioClientTestsi  z 
Tests for L{cftp.StdioClient}.
c                h   \        4       V n        \        V P                  4      p\        P                  ! V4      V n        RV P
                  n        \        4       ;V n        V P
                  n	        V P                  R^4       V P
                  P
                  P                  V P
                  n        R# )zU
Create a L{cftp.StdioClient} hooked up to dummy transport and a fake
user database.
/i  N)r   fakeFilesystemr   r   StdioClientclientcurrentDirectoryr   database_pwdsetKnownConsoleSizer   )r6   
sftpClients   & r+   r7   StdioClientTests.setUp  s    
 ;<'(;(;<
&&z2'*$+7>9(
 	  b) !% 2 2 < <r.   c           	        V P                   P                  \        P                  ! 4       R\        P
                  ! 4       RRR\        P                  4       V P                  P                  R4      pVP                  V P                  R4       V# )z[
The I{exec} command runs its arguments locally in a child process
using the user's shell.
secret  rk   barzexec print(1 + 2)s   3
)r   addUsergetpassgetuserr`   getuidsys
executabler   _dispatchCommandaddCallbackrF   r6   ds   & r+   	test_execStdioClientTests.test_exec  sf    
 	OOxdE5#..	
 KK(()<=	d&&/r.   c           	        V P                   P                  \        P                  ! 4       R\        P
                  ! 4       RRRR4       V P                  P                  R4      pVP                  V P                  R4       V# )zZ
If the local user has no shell, the I{exec} command runs its arguments
using I{/bin/sh}.
r   r   rk   r    zexec echo hello   hello

r   r   r   r   r`   r   r   r   r   rF   r   s   & r+   test_execWithoutShell&StdioClientTests.test_execWithoutShell  sb    
 	OOxdE5"	
 KK(():;	d&&
3r.   c           	        V P                   P                  \        P                  ! 4       R\        P
                  ! 4       RRRR4       V P                  P                  R4      pVP                  V P                  R4       V# )z?
The I{exec} command is run for lines which start with C{"!"}.
r   r   rk   r   z/bin/shz!echo hellor   r   r   s   & r+   	test_bangStdioClientTests.test_bang  sa     	OOxdE5)	
 KK((7	d&&
3r.   c                j   aaa ^ RI o ! VVV3R lR4      pV P                  \        RV! 4       4       R# )z
For the duration of this test, patch C{cftp}'s C{fcntl} module to return
a fixed width and height.

@param width: the width in characters
@type width: L{int}
@param height: the height in characters
@type height: L{int}
Nc                   2   <a  ] tR tRt o VVV3R ltRtV tR# )7StdioClientTests.setKnownConsoleSize.<locals>.FakeFcntli  c                |   < VSP                   8w  d   V P                  R 4       \        P                  ! RSS^ ^ 4      # )z#Only window-size queries supported.4H)
TIOCGWINSZfailstructpack)r6   fdoptmutateheightttywidths   &&&&r+   ioctl=StdioClientTests.setKnownConsoleSize.<locals>.FakeFcntl.ioctl  s3    #..(IICD{{41==r.   r(   N)rL   rM   rN   rO   r  rQ   rR   )r*   r  r  r  s   @r+   	FakeFcntlr    s     > >r.   r  fcntl)r  re   r   )r6   r  r  r  r  s   &ff @r+   r   $StdioClientTests.setKnownConsoleSize  s&     		> 	> 	

4)+.r.   c                   V P                  ^
^"4       \        4       ;qP                  n        \	        R4      pRVn        \        P                  ! V4      pRVn        VP                  4       pVP                  R4       V;P                  R,          un        V P                  P                  W44       RpV P                  V P                  P                  P                  4       V4       R# )a   
L{StdioClient._printProgressBar} prints a progress description,
including percent done, amount transferred, transfer rate, and time
remaining, all based the given start time, the given L{FileWrapper}'s
progress information and the reactor's current time.
   x   sampleg       @i   s#   b'sample' 40% 4.0kB 2.0kBps 00:03 Ni (  )r   r   r   r   r   r   r   FileWrappersizesecondsadvancetotal_printProgressBarrF   r   valuer6   clockwrappedwrapper	startTimeresults   &     r+   test_printProgressBarReporting/StdioClientTests.test_printProgressBarReporting  s     	  R(&+g-#$- ""7+ MMO	c%%g98..446?r.   c                p   V P                  ^
^"4       \        4       ;qP                  n        \	        R4      pRVn        \        P                  ! V4      pVP                  4       pV P                  P                  W44       RpV P                  V P                  P                  P                  4       V4       R# )z
L{StdioClient._printProgressBar} prints a progress description that
indicates 0 bytes transferred if no bytes have been transferred and no
time has passed.
r  r  s!   b'sample'  0% 0.0B 0.0Bps 00:00 N)r   r   r   r   r   r   r   r  r  r   rF   r   r!  r"  s   &     r+   test_printProgressBarNoProgress0StdioClientTests.test_printProgressBarNoProgress  s     	  R(&+g-#$- ""7+MMO	%%g96..446?r.   c                   V P                  ^
^"4       \        4       pRVn        \        P                  ! V4      pV P
                  P                  V^ 4       RpV P                  W0P
                  P                  P                  4       4       R# )z%
Print the progress for empty files.
s
   empty-files%   b'empty-file'100% 0.0B 0.0Bps 00:00 N)
r   r   r   r   r  r   r   rF   r   r!  )r6   r$  r%  r'  s   &   r+   test_printProgressBarEmptyFile/StdioClientTests.test_printProgressBarEmptyFile  sl     	  R()$""7+%%gq1:!6!6!<!<!>?r.   c                `    V P                   P                  R4      pV P                  RV4       R# )z;
Returns empty value for both filename and remaining data.
z  N)r   r   r   _getFilenamerF   r6   r'  s   & r+   test_getFilenameEmpty&StdioClientTests.test_getFilenameEmpty  s(     ))$/6*r.   c                `    V P                   P                  R4      pV P                  RV4       R# )zL
Returns empty value for remaining data when line contains
only a filename.

only-localN)r7  r   r1  r3  s   & r+   test_getFilenameOnlyLocal*StdioClientTests.test_getFilenameOnlyLocal  s)    
 )),7+V4r.   c                `    V P                   P                  R4      pV P                  RV4       R# )zM
Returns filename and remaining data striped of leading and trailing
spaces.
z local  remote file  N)localzremote filer1  r3  s   & r+   test_getFilenameNotQuoted*StdioClientTests.test_getFilenameNotQuoted#  s*    
 ))*AB16:r.   c                `    V P                   P                  R4      pV P                  RV4       R# )zq
Returns filename and remaining data not striped of leading and trailing
spaces when quoted paths are requested.
z" " local file "  " remote  file " N)z local file z" remote  file "r1  r3  s   & r+   test_getFilenameQuoted'StdioClientTests.test_getFilenameQuoted,  s*    
 ))*NO=vFr.   Nc                    Vf   V P                  4       p\        VR4      ;_uu_ 4       pVP                  V4       RRR4       V#   + '       g   i     T# ; i)a"  
Create a local file and return its path.

When `path` is L{None}, it will create a new temporary file.

@param path: Optional path for the new file.
@type path: L{str}

@param content: Content to be written in the new file.
@type content: L{bytes}

@return: Path to the newly create file.
Nwb)mktempopenr   )r6   r   contentfiles   &&& r+   makeFileStdioClientTests.makeFile5  sG     <;;=D$JJw  s   AA	c                4   V P                   P                  P                  4       pVP                  R4      pVP	                  R4      p. p. pV EFl  w  rgp. p	V F  p
V	P                  V RV
 24       K  	  V	P                  RV RV 24       VP                  V	4       VP                  ^ 4      P                  R4      P	                  R4      pVRR
 pVR
,          P                  R4      P	                  R4      pVP                  V4       . pVRR
  F|  p
V
P                  4       P                  R^4      ^ ,          p
V
P                  4       P	                  R^4      p
VP                  V
^ ,           RV
^,          P                  4        24       K~  	  VP                  VR
,          4       VP                  V4       EKo  	  V'       d&   V P                  \        V4      \        V4      4       MV P                  WE4       V P                  ^ \        V4      R	4       R# )z
Check output of cftp client for a put request.


@param transfers: List with tuple of (local, remote, progress).
@param randomOrder: When set to C{True}, it will ignore the order
    in which put reposes are received

rB   z
 zTransferred z to N
z5There are still put responses which were not checked.)r   r   r!  decodesplitappendr   stripextendrsplitrF   sortedlen)r6   	transfersrandomOrderoutputexpectedOutputactualOutputr;  remoteexpectedexpectedTransferlineprogressPartsactuallastactualTransfers   &&&            r+   checkPutMessage StdioClientTests.checkPutMessageI  s    &&,,.w'f%'0#E8  "  ''5'4&(9: !##l5'fX$FG!!"23"JJqM//5;;DAM"3B'F $**4066t<DMM$N s zz|**3215 zz|))#q1%%a	47==?2C&DE $ !!&*-/? (1B VN3VL5IJ^:KC	
r.   c                   RpV P                  VR7      p\        P                  \        P                  ,          \        P                  ,          p\
        P                  P                  R\
        P                  P                  V4      4      p\        V4      pV P                  P                  WC\        P                  ! V4      4       ^
V P                  P                  P                  R&   V P                  P!                  V4      pV P#                  V4       V P%                  WP'                  4       4       V P)                  VP*                  4       V P-                  W$. RO3.4       R# )z}
A name based on local path is used when remote path is not
provided.

The progress is updated while chunks are transferred.
s   Test
Content)rE  r   r   N)z	76% 10.0B
100% 13.0Brf  )rG  r   	FXF_WRITE	FXF_CREAT	FXF_TRUNCr`   r   joinbasenamer   r   r   r   r   r   r   cmd_PUTsuccessResultOfrF   rG   r<   r   rc  )r6   rE  	localPathr   
remoteName
remoteFiledeferreds   &      r+   test_cmd_PUTSingleNoRemotePath/StdioClientTests.test_cmd_PUTSingleNoRemotePath  s    %MM'M2	&&)?)??,BXBXXWW\\#rww'7'7	'BC
'
3

5==3LM35""<0;;&&y1X&"5"5"78
**+%NOP	
r.   c                   V P                  4       p\        P                  \        P                  ,          \        P                  ,          pRp\        V4      pV P                  P                  W2\        P                  ! V4      4       V P                  P                  V RV R24      pV P                  V4       V P                  WR.3.4       V P                  VP                  4       V P!                  RVP#                  4       4       R# )zh
Remote path is extracted from first filename after local file.

Any other data in the line is ignored.
z/remote-pathrJ  z ignored	100% 0.0Br.   N)rG  r   rg  rh  ri  r   r   r   r   r   r   rl  rm  rc  r<   r   rF   rG   )r6   rn  r   ro  rp  rq  s   &     r+   test_cmd_PUTSingleRemotePath-StdioClientTests.test_cmd_PUTSingleRemotePath  s     MMO	&&)?)??,BXBXX#
'
3

5==3LM;;&&)Aj\'JKX&y{mDEF
**+j1134r.   c                .   V P                  4       p\        P                  P                  V4      pRp\        P                  P	                  V4      pV P                  \        P                  P                  WC4      R7      p\        P                  \        P                  ,          \        P                  ,          pRV 2pRV 2p\        V4      p	\        V4      p
V P                  P                  Wv\        P                  ! V	4      4       V P                  P                  W\        P                  ! V
4      4       V P                  P!                  \        P                  P                  VR4      4      pV P#                  V4       V P%                  V	P&                  4       V P)                  RV	P+                  4       4       V P%                  V
P&                  4       V P)                  RV
P+                  4       4       V P-                  WR.3WXR.3.RR7       R	# )
zl
When a gobbing expression is used local files are transferred with
remote file names based on local names.
second-namer   r   *r.   ru  TrW  N)rG  r`   r   rk  dirnamerj  r   rg  rh  ri  r   r   r   r   r   r   rl  rm  r<   r   rF   rG   rc  )r6   first	firstName
secondNameparentsecondr   firstRemotePathsecondRemotePathfirstRemoteFilesecondRemoteFilerq  s   &           r+    test_cmd_PUTMultipleNoRemotePath1StdioClientTests.test_cmd_PUTMultipleNoRemotePath  s   
 GG$$U+	"
'BGGLL$DE&&)?)??,BXBXXi[/zl+,_=-.>?o8VWU]]3C%D	
 ;;&&rww||FC'@AX&//0o6689(001.779:+7K=9  	 	
r.   c                L   V P                  4       p\        P                  P                  V4      pRp\        P                  P	                  V4      pV P                  \        P                  P                  WC4      R7      p\        P                  \        P                  ,          \        P                  ,          p\        V4      p\        V4      pRV 2p	RV 2p
V P                  P                  W\        P                  ! V4      4       V P                  P                  W\        P                  ! V4      4       V P                  P!                  RP#                  \        P                  P                  VR4      4      4      pV P%                  V4       V P'                  VP(                  4       V P+                  RVP-                  4       4       V P'                  VP(                  4       V P+                  RVP-                  4       4       V P/                  WR.3WSR.3.RR	7       R
# )z
When a gobbing expression is used local files are transferred with
remote file names based on local names.
when a remote folder is requested remote paths are composed from
remote path and local filename.
ry  rz  z/remote/z	{} remoter{  r.   ru  Tr|  N)rG  r`   r   rk  r}  rj  r   rg  rh  ri  r   r   r   r   r   r   rl  r)   rm  r<   r   rF   rG   rc  )r6   r~  r  r  r  r  r   r  r  r  r  rq  s   &           r+   "test_cmd_PUTMultipleWithRemotePath3StdioClientTests.test_cmd_PUTMultipleWithRemotePath  s    GG$$U+	"
'BGGLL$DE&&)?)??,BXBXX,Y7-j9$YK0%j\2o8VWU]]3C%D	
 ;;&&{'9'9"'',,vs:S'TUX&//0o6689(001.779:K=1k]3  	 	
r.   )r   r   r   )Nr.   )F)rL   rM   rN   rO   rP   r7   r   r   r  r   r(  r+  r.  r4  r8  r<  r?  rG  rc  rr  rv  r  r  rQ   rR   rS   s   @r+   r   r     so     =&
/*@0@$@+5;G(;
z
05&!
F#
 #
r.   r   c                   ,   a  ] tR tRt o R tR tRtV tR# )FileTransferTestRealmi  c                    Wn         R # r0   testDir)r6   r  s   &&r+   r   FileTransferTestRealm.__init__  s    r.   c                F    \        V P                  4      pV^ ,          VR 3# )    c                      R # r0   r(   r(   r.   r+   <lambda>5FileTransferTestRealm.requestAvatar.<locals>.<lambda>   s    r.   )r   r  )r6   avatarIDmindr   as   &&&* r+   requestAvatar#FileTransferTestRealm.requestAvatar  s!    "4<<0!}a--r.   r  N)rL   rM   rN   rO   r   r  rQ   rR   rS   s   @r+   r  r    s     . .r.   r  c                   `   a  ] tR tRt o RtR tR tR tR tR t	R t
R	 tR
 tR tR tRtV tR# )SFTPTestProcessi  z
Protocol for testing cftp. Provides an interface between Python (where all
the tests are) and the cftp client process (which does the work that is
being tested).
c                \    V P                  4        Wn        RV n        RV n        RV n        R# )zZ
@param onOutReceived: A L{Deferred} to be fired as soon as data is
received from stdout.
NF)clearBufferonOutReceivedonProcessEnd_expectingCommand_processEnded)r6   r  s   &&r+   r   SFTPTestProcess.__init__
  s.    
 	* !%"r.   c                0    RV n         . V n        RV n        R# )zB
Clear any buffered data received from stdout. Should be private.
r.   N)buffer_linesReceived_lineBufferr5   s   &r+   r  SFTPTestProcess.clearBuffer  s      r.   c                   \         P                  ! RV,          4       V P                  V,           P                  R4      pVP	                  R4      V n        V P
                  P                  V4       V P                  e%   V P                  Ruq0n        VP                  V4       V ;P                  V,          un	        V P                  4        R# )z?
Called by Twisted when the cftp client prints data to stdout.
zgot %r   
NrM  )r   msgr  rO  r   r  rR  r  callbackr  _checkForCommand)r6   r   linesr   s   &&  r+   outReceivedSFTPTestProcess.outReceived  s     	4 !!D(//6 99R=""5) )$($6$6!A!JJttr.   c                @   R pV P                   '       d   V P                  V8X  dw   RP                  V P                  4      pVP	                  V4      '       d   V\        V4      R pV P                  4        V P                   Ruq0n         VP                  V4       R# R# R# )s   cftp> r  N)r  r  rj  r  
startswithrU  r  r  )r6   promptbufr   s   &   r+   r   SFTPTestProcess._checkForCommand.  s    !!!d&6&6&&@**T001C~~f%%#f+-((,(>(>%A%JJsO 'A!r.   c                @    \         P                  ! RV,          4       R# )z?
Called by Twisted when the cftp client prints data to stderr.
zerr: %sN)r   r  )r6   r   s   &&r+   errReceivedSFTPTestProcess.errReceived8  s     		D !r.   c                    V P                   # )zA
Return the contents of the buffer of data received from stdout.
)r  r5   s   &r+   	getBufferSFTPTestProcess.getBuffer>  s     {{r.   c                    \         P                  ! 4       V n        V P                  4        \	        V\
        4      '       d   VP                  R4      pV P                  P                  VR,           4       V P                  # )at  
Issue the given command via the cftp client. Return a C{Deferred} that
fires when the server returns a result. Note that the C{Deferred} will
callback even if the server returns some kind of error.

@param command: A string containing an sftp command.

@return: A C{Deferred} that fires when the sftp server returns a
result. The payload is the server's response string.
rB   r  )	r   Deferredr  r  
isinstancestrrD   r   r   r6   commands   &&r+   
runCommandSFTPTestProcess.runCommandD  s\     "'!1gs##nnW-GWu_-%%%r.   c                    \         P                  ! ^4      pV Uu. uF  q2P                  V P                  V4      NK   	  pp\         P                  ! V4      # u upi )a@  
Run each command in sequence and return a Deferred that fires when all
commands are completed.

@param commands: A list of strings containing sftp commands.

@return: A C{Deferred} that fires when all commands are completed. The
payload is a list of response strings from the server, in the same
order as the commands.
)r   DeferredSemaphorerunr  gatherResults)r6   commandssemr  dls   &&   r+   	runScriptSFTPTestProcess.runScriptV  sL     %%a(?GHxGggdoow/xH""2&& Is   $Ac                    V P                   '       d   \        P                  ! R4      # \        P                  ! 4       V n        V P
                  P                  R4       V P                  # )z
Kill the process if it is still running.

If the process is still running, sends a KILL signal to the transport
and returns a C{Deferred} which fires when L{processEnded} is called.

@return: a C{Deferred}.
NKILL)r  r   r   r  r  r   signalProcessr5   s   &r+   killProcessSFTPTestProcess.killProcesse  sL     ==&&!NN,$$V,   r.   c                    RV n         V P                  '       d'   V P                  Ruq n        VP                  R4       R# R# )z6
Called by Twisted when the cftp client process ends.
TN)r  r  r  )r6   reasonr   s   && r+   processEndedSFTPTestProcess.processEndedt  s<     "#'#4#4d A JJt r.   )r  r  r  r  r  r  r  N)rL   rM   rN   rO   rP   r   r  r  r  r  r  r  r  r  r  rQ   rR   rS   s   @r+   r  r    sA     	# ""&$'! r.   r  c                   >   a  ] tR tRt o R tR tR tR tR tRt	V t
R# )	CFTPClientTestBasei~  c                D   \        R R4      ;_uu_ 4       pVP                  \        P                  4       RRR4       \        RR4      ;_uu_ 4       pVP                  \        P                  4       RRR4       \
        P                  ! RR4       \        RR4      ;_uu_ 4       pVP                  R\        P                  ,           4       RRR4       \        P                  ! V 4      #   + '       g   i     L; i  + '       g   i     L; i  + '       g   i     LL; i)rsa_test.pubrB  Nrsa_testi  kh_tests
   127.0.0.1 )	rD  r   r   publicRSA_opensshprivateRSA_opensshr`   chmodr	   r7   r6   fs   & r+   r7   CFTPClientTestBase.setUp  s    .$''1GGH../ (*d##qGGH//0 $
U#)T""aGGMH$>$>>? #!!$'' ('## #"s#    C) C<$'D)C9	<D	D	c                   \        V P                  4      p\        P                  ! V4      pVP	                  \
        P                  ! 4       4       \
        P                  ! 4       pW#n        \        P                  ! ^ VRR7      V n
        R# )r  z	127.0.0.1)	interfaceN)r  r  r
   PortalregisterCheckerr   conchTestPublicKeyCheckerConchTestServerFactoryr   	listenTCPserver)r6   realmpfacs   &   r+   startServerCFTPClientTestBase.startServer  s^    %dll3MM% 	(<<>?--/
''3+Fr.   c                   \        V P                  P                  R 4      '       g   V P                  R4      # ^V P                  P                  P                  n        \        P                  ! V P                  P                  P                  P                  P                  4      pVP                  V P                  4       V# )protoN)hasattrr  factory_cbStopServerr  expectedLoseConnectionr   maybeDeferredr   loseConnectionr   r   s   & r+   
stopServerCFTPClientTestBase.stopServer  s    t{{**G44%%d++;<!!8 3 3 9 9 C C R RS	d(()r.   c                V    \         P                  ! V P                  P                  4      # r0   )r   r  r  stopListeningr6   ignoreds   &&r+   r   CFTPClientTestBase._cbStopServer  s    ""4;;#<#<==r.   c                    R F  p \         P                  ! V4       K  	  \        P                  ! V 4      #   \         d     KB  i ; i)r  )r  r  r  )r`   removeBaseExceptionr	   tearDownr  s   & r+   r  CFTPClientTestBase.tearDown  sC    8A		! 9
 $$T** ! s   7AA)r  N)rL   rM   rN   rO   r7   r  r  r  r  rQ   rR   rS   s   @r+   r  r  ~  s$     (G>+ +r.   r  c                      a  ] tR tRt o RtR tR tR tR tR t	R t
R	 tR
 tR tRR ltR tR tR tR tR tR tR tR tR tR tR tRtV tR# )OurServerCmdLineClientTestsi  z
Functional tests which launch a SFTP server over TCP on localhost and check
cftp command line interface using a spawned process.

Due to the spawned process you can not add a debugger breakpoint for the
client code.
c                d  a  \         P                  S 4       S P                  4        R pS P                  P	                  4       P
                  p\        P                  ! W,          P                  4       RR7      p\        P                  ! R\        P                   RV 24       \        P                  ! 4       p\        V4      S n        VP#                  V 3R l4       \$        P&                  P)                  4       p\$        P*                  P-                  \        P.                  4      VR&   . p/ pV F;  p\1        V\2        4      '       d   VP5                  R4      pVP7                  V4       K=  	  V F]  pWH,          p	\1        V\2        4      '       d   VP5                  R4      p\1        V	\2        4      '       d   V	P5                  R4      p	WV&   K_  	  \        P                  ! V4       \        P                  ! V4       \8        P:                  ! S P                   \        P                  WVR7       V# )	z-p %i -l testuser --known-hosts kh_test --user-authentications publickey --host-key-algorithms ssh-rsa -i rsa_test -a -v 127.0.0.1r   modrunning rJ  c                 8   < SP                   P                  4       # r0   )processProtocolr  _r6   s   &r+   r  3OurServerCmdLineClientTests.setUp.<locals>.<lambda>       4 4 @ @ Br.   
PYTHONPATHrB   env)r  r7   r  r  getHostportr   	_makeArgsrO  r   r  r   r   r   r  r  r  r   r`   ra   copypathseprj  r   r  r  rD   rP  r   spawnProcess)
r6   cmdsr  r   r  encodedCmds
encodedEnvcmdvarvals
   f         r+   r7   !OurServerCmdLineClientTests.setUp  s     & 	 {{""$))##T[$7$7$9vF(3>>*!D623NN.q1	BCjjooJJOOCHH5L
C#s##jj)s#  C(C#s##jj)#s##jj)!sO  	
  #..+	
 r.   c                R   a  S P                  4       pVP                  V 3R  l4       V# )c                 8   < SP                   P                  4       # r0   )r  r  r  s   &r+   r  6OurServerCmdLineClientTests.tearDown.<locals>.<lambda>  r  r.   )r  r   r   s   f r+   r  $OurServerCmdLineClientTests.tearDown  s!    OO	BCr.   c                     V P                   P                  P                  R 4       R#   \        P                   d     R# i ; i)r  N)r  r   r  r   ProcessExitedAlreadyr  s   &&r+   _killProcess(OurServerCmdLineClientTests._killProcess  s9    	  **88@)) 		s   %) AAc                8    V P                   P                  V4      # )z
Run the given command with the cftp client. Return a C{Deferred} that
fires when the command is complete. Payload is the server's output for
that command.
)r  r  r  s   &&r+   r  &OurServerCmdLineClientTests.runCommand  s     ##..w77r.   c                8    V P                   P                  V4      # )z
Run the given commands with the cftp client. Returns a C{Deferred}
that fires when the commands are all complete. The C{Deferred}'s
payload is a list of output for each command.
)r  r  )r6   r  s   &*r+   r  %OurServerCmdLineClientTests.runScript  s     ##--h77r.   c                    V P                   pV P                  RRRRR4      pR pVP                  V4       VP                  V P                  VP                  \
        P                  ! 4       RVP                  .4       V# )z
Test that 'pwd' reports the current remote directory, that 'lpwd'
reports the current local directory, and that changing to a
subdirectory then changing to its parent leaves you in the original
remote directory.
pwdlpwdzcd testDirectorycd ..c                    . pV  F;  p\        V\        4      '       d   VP                  R4      pVP                  V4       K=  	  VR,          VR,          ,           # )z0
Callback function for handling command output.
rB   :N   N:   NN)r  bytesrN  rP  )rX  r  r  s   &  r+   	cmdOutput8OurServerCmdLineClientTests.testCdPwd.<locals>.cmdOutput  sO     Dc5))**W-CC   8d2h&&r.   r   )r  r  r   rF   r   r`   getcwd)r6   homeDirr   r4  s   &   r+   	testCdPwd%OurServerCmdLineClientTests.testCdPwd  sg     ,,NN5&*<guM		' 	
i 	d&&ryy{B(UVr.   c                Z   a  V 3R lpS P                  RRRR4      pVP                  V4      # )zt
Check that 'ls -l' output includes the access permissions and that
this output changes appropriately with 'chmod'.
c                 8  < SP                  4        SP                  V ^ ,          P                  R4      4       SP                  V ^,          R4       SP                  V ^,          P                  R4      V ^,          4       SP                  V ^,          R4       R# )r  s
   -rw-r--r--r.   s
   ----------N)flushLoggedErrorsr<   r  rF   resultsr6   s   &r+   _check7OurServerCmdLineClientTests.testChAttrs.<locals>._check  ss    ""$OOGAJ11-@AWQZ-OOGAJ11-@'!*MWQZ-r.   zls -l testfile1zchmod 0 testfile1zchmod 644 testfile1r  r   r6   r?  r   s   f  r+   testChAttrs'OurServerCmdLineClientTests.testChAttrs  s5    	. NN!	
 }}V$$r.   c                   a  V 3R lpS P                  RRS P                  P                  4       ,           RRR4      pVP                  R 4       VP                  V4      # )zv
Check 'ls' works as expected. Checks for wildcards, hidden files,
listing directories and listing empty directories.
c                   < SP                  V ^ ,          . RO4       SP                  V ^,          . RO4       SP                  V ^,          RR.4       SP                  V ^,          . RO4       SP                  V ^,          R.4       R# )r     testRemoveFile   testRenameFiler.   Ns   testDirectoryrG  rH  s	   testfile1)s   .testHiddenFilerG  rH  rF   r=  s   &r+   r?  4OurServerCmdLineClientTests.testList.<locals>._check*  s    
V 
V WQZ*;=N)OP
V WQZ#/r.   r   zls ../zls *Filezls -a *Filezls -l testDirectoryc                 L    V  Uu. uF  qP                  R 4      NK  	  up# u upi )r  )rO  )xsxs   & r+   r  6OurServerCmdLineClientTests.testList.<locals>.<lambda>@  s    "!="Q''%."!=!=s   !)r  r  rk  r   rB  s   f  r+   testList$OurServerCmdLineClientTests.testList$  sW    	0 NNt||,,..!
 	
=>}}V$$r.   c                   V P                  R4      p\        P                  ! R4      P                  R4      P	                  4       p\        V\        4      '       d   VP                  R4      pVP                  V P                  V4       V# )z2
Check that running the '?' command returns help.
?Nr   rB   )
r  r   r   cmd_HELPrQ  r  r  rD   r   rF   )r6   r   helpTexts   &  r+   testHelp$OurServerCmdLineClientTests.testHelpC  sj     OOC ##D)2226<<>h$$w/H	d&&1r.   Nc                d    V P                  VP                  4       VP                  4       V4       R# )zO
Assert that the files at C{name1} and C{name2} contain exactly the
same data.
N)rF   
getContent)r6   name1name2r  s   &&&&r+   assertFilesEqual,OurServerCmdLineClientTests.assertFilesEqualO  s(    
 	))+U-=-=-?Er.   c                x  a a RP                  S P                  P                  S P                  P                  4      o\        S\        4      '       d   SP                  R4      oVV 3R lpS P                  RS P                  P                   R24      pVP                  V4       VP                  V 3R l4       V# )z
Test that 'get' saves the remote file to the correct local location,
that the output of 'get' is correct and that 'rm' actually removes
the file.
z)Transferred {}/testfile1 to {}/test file2rB   c                    < SP                  V P                  S4      4       SP                  SP                  P	                  R 4      SP                  P	                  R4      R4       SP                  R4      # )	testfile1
test file2z
get failedzrm "test file2")r<   endswithr\  r  childr  r'  rY  r6   s   &r+   	_checkGet6OurServerCmdLineClientTests.testGet.<locals>._checkGetd  s_    OOFOON;<!!"";/""<0
 ??#455r.   zget testfile1 "z/test file2"c                 t   < SP                  SP                  P                  R 4      P                  4       4      # )ra  assertFalser  rc  existsr  s   &r+   r  5OurServerCmdLineClientTests.testGet.<locals>.<lambda>p  (    d&&t||'9'9,'G'N'N'PQr.   )r)   r  r   r  r  rD   r  r   )r6   re  r   rY  s   f  @r+   testGet#OurServerCmdLineClientTests.testGetV  s     EKKLLLL
 nc**+227;N	6 OOodll.?.?-@MN	i 	Q	
 r.   c                T   a  V 3R lpS P                  R4      pVP                  V4      # )zA
Test that 'get' works correctly when given wildcard parameters.
c                    < SP                  SP                  P                  R 4      \        R 4      R4       SP                  SP                  P                  R4      \        R4      R4       R# )testRemoveFiletestRemoveFile get failedtestRenameFiletestRenameFile get failedN)r\  r  rc  r   )r  r6   s   &r+   r?  ;OurServerCmdLineClientTests.testWildcardGet.<locals>._checky  s_    !!""#34)*+
 !!""#34)*+r.   z
get testR*)r  r   rB  s   f  r+   testWildcardGet+OurServerCmdLineClientTests.testWildcardGett  s'    

	 OOL)}}V$$r.   c                z  a a RS P                   P                  4       P                  ,           R,           S P                   P                  4       P                  ,           R,           oVV 3R lpS P                  RS P                   P                   R24      pVP	                  V4       VP	                  V 3R l4       V# )z
Check that 'put' uploads files correctly and that they can be
successfully removed. Also check the output of the put command.
s   Transferred s   /testfile1 to s   /test"file2c                    < SP                  SP                  P                  R 4      SP                  P                  R4      4       SP                  V P	                  S4      4       SP                  R4      # )r`  
test"file2zrm "test\"file2")r\  r  rc  r<   rb  r  rd  s   &r+   	_checkPut6OurServerCmdLineClientTests.testPut.<locals>._checkPut  s[    !!"";/1C1CL1Q OOFOON;<??#677r.   put z/testfile1 "test\"file2"c                 t   < SP                  SP                  P                  R 4      P                  4       4      # )rz  rh  r  s   &r+   r  5OurServerCmdLineClientTests.testPut.<locals>.<lambda>  rl  r.   )r  asBytesModer   r  r   )r6   r{  r   rY  s   f  @r+   testPut#OurServerCmdLineClientTests.testPut  s     ll&&(--.  ll&&(--. 	 		8 OOd4<<#4#4"55NOP	i 	Q	
 r.   c                  a  S P                   P                  R4      P                  RR7      ;_uu_ 4       pVP                  R4       RRR4       S P                   P                  R4      P                  RR7      ;_uu_ 4       pVP                  R4       RRR4       V 3R lpS P	                  R	S P                   P
                   R
24      pVP                  V4       V#   + '       g   i     L; i  + '       g   i     Le; i)zJ
Check that 'put' uploads files correctly when overwriting a longer
file.
shorterFilewmode   aN
longerFile   bbc                    < SP                  SP                  P                  R 4      SP                  P                  R4      4       R# )r  r  N)r\  r  rc  )r'  r6   s   &r+   r{  EOurServerCmdLineClientTests.test_putOverLongerFile.<locals>._checkPut  s4    !!""=14<<3E3El3Sr.   r}  z/shorterFile longerFile)r  rc  rD  r   r  r   r   )r6   r  r{  r   s   f   r+   test_putOverLongerFile2OurServerCmdLineClientTests.test_putOverLongerFile  s     \\.333==GGDM >\\-222<<GGEN =	
 OOd4<<#4#4"55LMN	i  >=<<s   CC1C.	1D	c                N  a a S P                   P                  R4      oSP                  4        SP                  R4      P                  RR7      ;_uu_ 4       pVP	                  R4       RRR4       S P                   P                  R4      P                  RR7      ;_uu_ 4       pVP	                  R4       RRR4       V V3R lpS P                  R	S P                   P                   R
24      pVP                  V4       V#   + '       g   i     L; i  + '       g   i     Lf; i)z
Check that 'put' uploads files correctly when overwriting a longer
file and you use a wildcard to specify the files to upload.
dirrF  r  r  r  Nr  c                 |   < SP                  SP                  R 4      SP                  P                  R 4      4       R# )rF  N)r\  rc  r  )r'  r6   someDirs   &r+   r{  MOurServerCmdLineClientTests.test_putMultipleOverLongerFile.<locals>._checkPut  s+    !!'--"79K9KF9STr.   r}  z/dir/*)r  rc  createDirectoryrD  r   r  r   r   )r6   r  r{  r   r  s   f   @r+   test_putMultipleOverLongerFile:OurServerCmdLineClientTests.test_putMultipleOverLongerFile  s     ,,$$U+!]]6"''S'11QGGDM 2\\',,#,66!GGEN 7	U OOd4<<#4#4"5V<=	i  2166s   D$DD	D$	c                   a  V 3R lpS P                  RRS P                  P                   R2RS P                  P                  4       ,          4      pVP	                  V4       V# )z
What happens if you issue a 'put' command and include a wildcard (i.e.
'*') in parameter? Check that all files matching the wildcard are
uploaded to the correct directory.
c                   < SP                  V ^ ,          R4       SP                  V ^,          R4       SP                  SP                  P                  R4      SP                  P	                  4       P                  R4      R4       SP                  SP                  P                  R4      SP                  P	                  4       P                  R4      R4       R# )r  r.   rq  rr  rs  rt  N)rF   r\  r  rc  r  r=  s   &r+   check:OurServerCmdLineClientTests.testWildcardPut.<locals>.check  s    WQZ-WQZ-!!""#34##%++,<=+
 !!""#34##%++,<=+r.   r/  r}  z/testR*zcd %s)r  r  r   rk  r   )r6   r  r   s   f  r+   testWildcardPut+OurServerCmdLineClientTests.testWildcardPut  sZ    	 NN4<<$$%W-dll++--

 	
er.   c                   a  V 3R lpS P                  RR4      pVP                  V4       VP                  S P                  R4       V# )z
Test that 'ln' creates a file which appears as a link in the output of
'ls'. Check that removing the new file succeeds without output.
c                    < SP                  4        SP                  V ^ ,          R4       SP                  V ^,          P                  R4      R4       SP	                  R4      # )r  r.      lzlink failedzrm testLink)r<  rF   r<   r  r  r=  s   &r+   r?  4OurServerCmdLineClientTests.testLink.<locals>._check  sO    ""$WQZ-OOGAJ11$7G??=11r.   zln testLink testfile1zls -l testLinkr.   r  r   rF   rB  s   f  r+   testLink$OurServerCmdLineClientTests.testLink  sA    	2 NN24DE	f	d&&,r.   c                   a  V 3R lpS P                  RR4      pVP                  V4       VP                  S P                  R4       V# )zF
Test that we can create and remove directories with the cftp client.
c                    < SP                  V ^ ,          R4       SP                  V ^,          P                  R4      4       SP                  R4      # )r  r.      dzrmdir testMakeDirectory)rF   r<   r  r  r=  s   &r+   r?  ?OurServerCmdLineClientTests.testRemoteDirectory.<locals>._check   sB    WQZ-OOGAJ11$78??#<==r.   mkdir testMakeDirectoryzls -l testMakeDirector?r.   r  rB  s   f  r+   testRemoteDirectory/OurServerCmdLineClientTests.testRemoteDirectory  sA    
	>
 NN46OP	f	d&&,r.   c                Z   a  V 3R lpS P                  RR4      pVP                  V4       V# )z
Test that a C{mkdir} on an existing directory fails with the
appropriate error, and doesn't log an useless error server side.
c                 l   < SP                  V ^ ,          R4       SP                  V ^,          R4       R# )r  r.   s   remote error 11: mkdir failedNrJ  r=  s   &r+   r?  HOurServerCmdLineClientTests.test_existingRemoteDirectory.<locals>._check  s,    WQZ-WQZ)IJr.   r  rA  rB  s   f  r+   test_existingRemoteDirectory8OurServerCmdLineClientTests.test_existingRemoteDirectory
  s.    	K NN46OP	fr.   c                   a  S P                  RS P                  P                   R24      pVP                  S P                  R4       VP                  V 3R l4       VP                  S P                  R4       V# )z
Test that we can create a directory locally and remove it with the
cftp client. This test works because the 'remote' server is running
out of a local directory.
zlmkdir z/testLocalDirectoryr.   c                 &   < SP                  R 4      # )zrmdir testLocalDirectory)r  r  s   &r+   r  @OurServerCmdLineClientTests.testLocalDirectory.<locals>.<lambda>   s    0J Kr.   )r  r  r   r   rF   r   s   f r+   testLocalDirectory.OurServerCmdLineClientTests.testLocalDirectory  sb     OOgdll&7&7%88KLM	d&&,	KL	d&&,r.   c                   a  V 3R lpS P                  RR4      pVP                  V4       VP                  S P                  R4       V# )z!
Test that we can rename a file.
c                    < SP                  V ^ ,          R4       SP                  V ^,          R4       SP                  R4      # )r  r.   s	   testfile2zrename testfile2 testfile1)rF   r  r=  s   &r+   r?  6OurServerCmdLineClientTests.testRename.<locals>._check)  s;    WQZ-WQZ6??#?@@r.   zrename testfile1 testfile2zls testfile?r.   r  rB  s   f  r+   
testRename&OurServerCmdLineClientTests.testRename$  sA    
	A
 NN7H	f	d&&,r.   )r  r0   )rL   rM   rN   rO   rP   r7   r  r&  r  r  r8  rC  rP  rV  r\  rm  rv  r  r  r  r  r  r  r  r  r  rQ   rR   rS   s   @r+   r  r    sz     (T
884%,%>
F<%(8((<"
 r.   r  c                   H   a  ] tR tRt o RtR tR tR tR tR t	R t
R	tV tR
# )OurServerBatchFileTestsi4  za
Functional tests which launch a SFTP server over localhost and checks csftp
in batch interface.
c                P    \         P                  V 4       V P                  4        R # r0   r  r7   r  r5   s   &r+   r7   OurServerBatchFileTests.setUp;  s      &r.   c                L    \         P                  V 4       V P                  4       # r0   )r  r  r  r5   s   &r+   r   OurServerBatchFileTests.tearDown?  s    ##D)  r.   c                  a V P                  4       o\        SR 4      ;_uu_ 4       pVP                  V4       RRR4       V P                  P	                  4       P
                  pRVS3,          p\        P                  ! VP                  4       RR7      R,          p\        P                  ! R\        P                   RV 24       \        P                  P                  4       p\        P                   P#                  \        P$                  4      VR&   ^V P                  P&                  n        \+        \        P                  WER	7      pV3R
 lpVP-                  R 4       VP/                  V4       V#   + '       g   i     ELF; i)r  Nz-p %i -l testuser --known-hosts kh_test --user-authentications publickey --host-key-algorithms ssh-rsa -i rsa_test -a -v -b %s 127.0.0.1r   r  :   NNr	  rJ  r  r  c                 4   < \         P                  ! S4       V # r0   )r`   r   )resfns   &r+   _cleanup9OurServerBatchFileTests._getBatchOutput.<locals>._cleanupZ  s    IIbMJr.   c                     V ^ ,          # )r  r(   )r  s   &r+   r  9OurServerBatchFileTests._getBatchOutput.<locals>.<lambda>^  s    #a&r.   )rC  rD  r   r  r  r  r   r  rO  r   r  r   r   r`   ra   r  r  rj  r   r  r  r   r   addBoth)	r6   r  fpr  r  r  r   r  r  s	   &&      @r+   _getBatchOutput'OurServerBatchFileTests._getBatchOutputC  s   [[]"c]]bHHQK {{""$))! 2J ##DJJLf=bA(3>>*!D623jjooJJOOCHH5L562$S^^TC	 	
()			(9 ]]s   E55F	c                \   a  RpV 3R lpS P                  V4      pVP                  V4       V# )z
Test whether batch file function of cftp ('cftp -b batchfile').
This works by treating the file as a list of commands to be run.
zpwd
ls
exit
c                   < V P                  R 4      p \        P                  ! R\        V 4      ,          4       SP	                  SP
                  P                  4       P                  V ^,          4       SP                  V ^R . RO4       R# )r  zRES %sNrI  )	rO  r   r  reprassertInr  r  r   rF   r  r6   s   &r+   _cbCheckResult=OurServerBatchFileTests.testBatchFile.<locals>._cbCheckResultm  se    ))E"CGGHtCy()MM$,,224993q6BAb	Vr.   r  r   r6   r  r  r   s   f   r+   testBatchFile%OurServerBatchFileTests.testBatchFilec  s2    

	   &	n%r.   c                \   a  RpV 3R lpS P                  V4      pVP                  V4       V# )z?
Test that an error in the batch file stops running the batch.
zchown 0 missingFile
pwd
exit
c                 p   < SP                  SP                  P                  4       P                  V 4       R # r0   )assertNotInr  r  r   r  s   &r+   r  9OurServerBatchFileTests.testError.<locals>._cbCheckResult  s&    T\\557<<cBr.   r  r  s   f   r+   	testError!OurServerBatchFileTests.testErrorz  s3    
	C   &	n%r.   c                \   a  RpV 3R lpS P                  V4      pVP                  V4       V# )zG
Test that a minus sign '-' at the front of a line ignores
any errors.
z-chown 0 missingFile
pwd
exit
c                 p   < SP                  SP                  P                  4       P                  V 4       R # r0   )r  r  r  r   r  s   &r+   r  @OurServerBatchFileTests.testIgnoredError.<locals>._cbCheckResult  s$    MM$,,224993?r.   r  r  s   f   r+   testIgnoredError(OurServerBatchFileTests.testIgnoredError  s3    

	@   &	n%r.   r(   N)rL   rM   rN   rO   rP   r7   r  r  r  r  r  rQ   rR   rS   s   @r+   r  r  4  s.     
!@.  r.   r  sshz$no ssh command-line client availablesftpz%no sftp command-line client availablec                   6   a  ] tR tRt o RtR tR tR tRtV t	R# )OurServerSftpClientTestsi  z8
Test the sftp server against sftp command line client.
c                L    \         P                  V 4       V P                  4       # r0   r  r5   s   &r+   r7   OurServerSftpClientTests.setUp  s      &!!r.   c                "    V P                  4       # r0   )r  r5   s   &r+   r  !OurServerSftpClientTests.tearDown  s      r.   c                *  a a	 \        \        P                  4      pS P                  4       p\	        VR4      ;_uu_ 4       pVP                  R4       RRR4       S P                  P                  4       P                  p\        P                  o	V	3R lpS P                  \        RV4       RS P                  P                  n        RRR	R
R	RR	RR	RR	RV3,          RVR3pV 3R lp\        RWa4      pVP                  V4      #   + '       g   i     L; i)z
Test the return of extended attributes by the server: the sftp client
should ignore them, but still be able to parse the response correctly.

This test is mainly here to check that
L{filetransfer.FILEXFER_ATTR_EXTENDED} has the correct value.
r  z	ls .
exitNc                 "   < S! W4      pR VR&   V# )r   ext_foor(   )r6   sr   
oldGetAttrs   && r+   	_getAttrsCOurServerSftpClientTests.test_extendedAttributes.<locals>._getAttrs  s    t'E$E)Lr.   r  Tz-Fz	/dev/nullz-ozIdentitiesOnly=yeszIdentityFile=rsa_testzUserKnownHostsFile=kh_testzHostKeyAlgorithms=ssh-rsazPort=%iz-bztestuser@127.0.0.1c                    < SP                  V ^,          ^ V ^,          P                  R4      4       R F  pSP                  W^ ,          4       K  	  R# )r&   asciiNrI  )rF   rN  r  )r'  ir6   s   & r+   r  ?OurServerSftpClientTests.test_extendedAttributes.<locals>.check  sF    VAY6!9+;+;G+DE a+r.   r  )dictr`   ra   rC  rD  r   r  r  r  r!   r  re   r  r  r   r   )
r6   r  r  r  r  r  argsr  r   r  s
   f        @r+   test_extendedAttributes0OurServerSftpClientTests.test_extendedAttributes  s     2::[[]"c]]aGGL! {{""$)).88
	
 	

,k9E592  #(' 
$	, %VT7}}U##] ]s    DD	r(   N)
rL   rM   rN   rO   rP   r7   r  r  rQ   rR   rS   s   @r+   r  r    s     "!;$ ;$r.   r  )QrP   r   r   rg   r`   r  r   r]   ior   r   unittestr   zope.interfacer   twisted.conchr   twisted.conch.interfacesr   $twisted.conch.test.test_filetransferr   r	   twisted.credr
   twisted.internetr   r   r   r   r   twisted.internet.taskr   twisted.internet.testingr   twisted.internet.utilsr   twisted.pythonr   twisted.python.fakepwdr   twisted.python.filepathr   twisted.python.procutilsr   twisted.python.reflectr   twisted.trial.unittestr   r   unixtwisted.conch.scriptsr   twisted.conch.scripts.cftpr   twisted.conch.sshr   twisted.conch.ssh.connectionr   twisted.conch.testr   r   twisted.conch.test.test_conchr    r!   ImportError	skipTestsIReactorProcessr#   rU   r   r   r   r   r   r  ProcessProtocolr  r  r  r  r  r(   r.   r+   <module>r     s:  
    	  
  %  &  . U  H H ' 4 ;  / , * 0 +^,)*	.92E;;R 	D,
 : :7D IJJI 	?@$
h $
 A$
N_
8 _
D  #. #.L9 96 Y/& /& /&d 	?@p
x p
 Ap
f. .xh.. xv$+ $+N 	?@K"4 K AK\ 	?@d0 d AdN 	?@E%L@AE&MBCG$1 G$ D B AG$_+  s   *,H HH