ó
    Ö›‘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	J
r
  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr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!  SSK"J#r#  SSK$J%r%  SSK&J'r'  SSK(J)r)  SSK*J+r+  SSK,J-r-  SSK.J/r/  \-" S5      r0\-" S5      r1\0(       a-   SSK2J3r3  SSK4J5r5  SSK6J7r7  SSK8J9r9  SSK:J;r;J<r<  SSK=J>r>  SSKJ?r?  SrAS\1\0\R„                  " \S5      4;   a  SrA\" \AS5       " S  S!\/5      5       rC " S" S#\/5      rD " S$ S%\!5      rE " S& S'5      rF " S( S)5      rG\" \5       " S* S+\	5      5       rH\" \AS5       " S, S-\/5      5       rI " S. S/5      rJ " S0 S1\R–                  5      rL " S2 S3\5      rM\" \AS5       " S4 S5\M5      5       rN\" \AS5       " S6 S7\M5      5       rO\" \AS5      \" \+" S85      (       + S95      \" \+" S:5      (       + S;5       " S< S=\M5      5       5       5       rPg! \@ a     GN3f = f)>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                   ó6   • \ rS rSrSrSS jrSS jrSS jrSrg)	ÚSSHSessionTestsé8   z5
Tests for L{twisted.conch.scripts.cftp.SSHSession}.
Nc                 óþ   • [        5       U l        [        5       U l        U R                  U R                  l        [	        5       U l        [        U R
                  5      U l        U R                  U R                  l        g ©N)r!   Ústdior   Úchannelr   ÚstderrBufferr   Ústderr©Úselfs    Ú`C:\Users\psant\Downloads\Noiseback\school\venv\Lib\site-packages\twisted/conch/test/test_cftp.pyÚsetUpÚSSHSessionTests.setUp>   sP   € Ü“[ˆŒ
Ü!“|ˆŒØ!ŸZ™Zˆ�‰ÔÜ#›IˆÔÜ# D×$5Ñ$5Ó6ˆŒØ"Ÿk™kˆ�‰Õó    c                 ó‚   • U R                   R                  5         U R                  U R                  R                  5        g)zd
L{twisted.conch.scripts.cftp.SSHSession.eofReceived} loses the write
half of its stdio connection.
N)r)   ÚeofReceivedÚ
assertTruer(   ÚwriteConnLostr,   s    r.   Útest_eofReceivedÚ SSHSessionTests.test_eofReceivedF   s*   € ð
 	�‰× Ñ Ô"Ø�‰˜Ÿ
™
×0Ñ0Õ1r1   c                 óÊ   • SnUR                  S5      nU R                  R                  [        US-   5        U R	                  U R
                  R                  5       US-   5        g)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)Úencoder)   ÚextReceivedr   ÚassertEqualr*   Úgetvalue)r-   Ú	errorTextÚ
errorBytess      r.   Útest_extReceivedStderrÚ&SSHSessionTests.test_extReceivedStderrN   s`   € ð "ˆ	Ø×%Ñ% gÓ.ˆ
Ø�‰× Ñ Ü Ø˜Ñ ô	
ð 	×ÑØ×Ñ×&Ñ&Ó(Ø˜Ñ!õ	
r1   )r)   r+   r*   r(   )ÚreturnN)	Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r/   r6   rA   Ú__static_attributes__© r1   r.   r$   r$   8   s   † ñô*ô2÷
r1   r$   c                   ó†  • \ rS rSrSr\" \SS5      c  SrS rS r	S r
S	 rS
 r\R                  " 5       r  \R                   " \R"                  S5        Sr\R                   " \R"                  \5        \" \S5      S 5       rS rSrg! \R&                   a    Sr NFf = f! \R                   " \R"                  \5        f = f)ÚListingTestsé`   zw
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                 ó`  ^ • ST l         U 4S jnT R                  [        SU5        S[        R                  ;   aa  T R                  [        R                  [        R                  S[        R                  S   5        T R                  [        R                  5        gS nT R                  U5        g)zW
Patch the L{ls} module's time function so the results of L{lsLine} are
deterministic.
iÍ[c                  ó   >• T R                   $ r'   ©Únowr,   s   €r.   ÚfakeTimeÚ$ListingTests.setUp.<locals>.fakeTimep   s   ø€ Ø—8‘8ˆOr1   ÚtimeÚTZc                  ór   •  [         R                  S	 [        R                  " 5         g ! [         a     N"f = f)NrV   )ÚosÚenvironÚKeyErrorrU   rN   rJ   r1   r.   ÚcleanupÚ#ListingTests.setUp.<locals>.cleanup|   s2   € ðÜŸ
™
 4Ð(ô —
’
•øô  ó Ùðús   ‚) ©
6µ6N)
rR   Úpatchr   rX   rY   Ú
addCleanupÚoperatorÚsetitemrU   rN   )r-   rS   r[   s   `  r.   r/   ÚListingTests.setUpi   sy   ø€ ð
 ˆŒõ	ð 	�
‰
”2�v˜xÔ(ð ”2—:‘:ÓØ�O‰OœH×,Ñ,¬b¯j©j¸$ÄÇ
Á
È4Ñ@PÔQØ�O‰OœDŸJ™JÕ'òð �O‰O˜GÕ$r1   c                 ó€   • U[         R                  S'   [        R                  " 5         [        R
                  " SU5      $ )zT
Call L{ls.lsLine} after setting the timezone to C{timezone} and return
the result.
rV   Úfoo)rX   rY   rU   rN   r   ÚlsLine)r-   ÚtimezoneÚstats      r.   Ú_lsInTimezoneÚListingTests._lsInTimezone†   s,   € ð $Œ�
‰
�4ÑÜ�
Š
ŒÜ�yŠy˜ Ó%Ð%r1   c                 óê   • U R                   S-
  n[        R                  " SSSSSSSSUS4
5      nU R                  U R	                  SU5      S5        U R                  U R	                  SU5      S5        g)zy
A file with an mtime six months (approximately) or more in the past has
a listing including a low-resolution timestamp.
é€r   úAmerica/New_Yorkz;!---------    0 0        0               0 Apr 26  1973 fooúPacific/Aucklandz;!---------    0 0        0               0 Apr 27  1973 fooN©rR   rX   Ústat_resultr=   rg   ©r-   Úthenrf   s      r.   Útest_oldFileÚListingTests.test_oldFile‘   ó|   € ð �x‰xÐ0Ñ1ˆÜ�~Š~˜q ! Q¨¨1¨a°°A°t¸QÐ?Ó@ˆà×ÑØ×ÑÐ1°4Ó8ØIô	
ð 	×ÑØ×ÑÐ1°4Ó8ØIõ	
r1   c                 óð   • U R                   S-
  S-   n[        R                  " SSSSSSSSUS4
5      nU R                  U R	                  SU5      S5        U R                  U R	                  SU5      S5        g)	úÆ
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.
rj   i€— r   rk   z;!---------    0 0        0               0 May 01  1973 foorl   z;!---------    0 0        0               0 May 02  1973 fooNrm   ro   s      r.   Útest_oldSingleDigitDayOfMonthÚ*ListingTests.test_oldSingleDigitDayOfMonth£   ó‚   € ð �x‰xÐ0Ñ1Ð5EÑFˆÜ�~Š~˜q ! Q¨¨1¨a°°A°t¸QÐ?Ó@ˆà×ÑØ×ÑÐ1°4Ó8ØIô	
ð 	×ÑØ×ÑÐ1°4Ó8ØIõ	
r1   c                 óê   • U R                   S-
  n[        R                  " SSSSSSSSUS4
5      nU R                  U R	                  SU5      S5        U R                  U R	                  SU5      S5        g)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.
é€›z r   rk   ú;!---------    0 0        0               0 Aug 28 17:33 foorl   ú;!---------    0 0        0               0 Aug 29 09:33 fooNrm   ro   s      r.   Útest_newFileÚListingTests.test_newFile·   rs   r1   ú
es_AR.UTF8FTz'The es_AR.UTF8 locale is not installed.c                 ó¼  • U R                   S-
  n[        R                  " SSSSSSSSUS4
5      n[        R                  " 5       n[        R
                  " [        R                  S5        U R                  [        R
                  [        R                  U5        U R                  U R                  SU5      S5        U R                  U R                  SU5      S5        g)	z3
The month name in the date is locale independent.
rz   r   r   rk   r{   rl   r|   N)
rR   rX   rn   ÚlocaleÚ	getlocaleÚ	setlocaleÚLC_ALLr^   r=   rg   )r-   rp   rf   ÚcurrentLocales       r.   Útest_localeIndependentÚ#ListingTests.test_localeIndependentÖ   sº   € ð �x‰xÐ0Ñ1ˆÜ�~Š~˜q ! Q¨¨1¨a°°A°t¸QÐ?Ó@ˆô ×(Ò(Ó*ˆÜ×ÒœŸ™¨Ô5Ø�‰œ×(Ñ(¬&¯-©-¸ÔGà×ÑØ×ÑÐ1°4Ó8ØIô	
ð 	×ÑØ×ÑÐ1°4Ó8ØIõ	
r1   c                 óð   • U R                   S-
  S-   n[        R                  " SSSSSSSSUS4
5      nU R                  U R	                  SU5      S5        U R                  U R	                  SU5      S5        g)	ru   rz   i F r   rk   z;!---------    0 0        0               0 Sep 01 17:33 foorl   z;!---------    0 0        0               0 Sep 02 09:33 fooNrm   ro   s      r.   Útest_newSingleDigitDayOfMonthÚ*ListingTests.test_newSingleDigitDayOfMonthí   rx   r1   rQ   )rD   rE   rF   rG   rH   ÚgetattrrU   Úskipr/   rg   rq   rv   r}   r�   r‚   r…   rƒ   r„   Ú
localeSkipÚErrorr   r†   r‰   rI   rJ   r1   r.   rL   rL   `   sÐ   † ññ
 ˆt�W˜dÓ#Ñ+ØIˆò%ò:	&ò
ò$
ò(
ð( ×$Ò$Ó&€Mð7ð	Ø×Ò˜VŸ]™]¨LÔ9ð ˆJà×Ò˜Ÿ™¨Ô6áˆJÐAÓBñ
ó Cð
õ,
øð= �|‰|ó 	ØŠJð	ûð
 	×Ò˜Ÿ™¨Õ6ús)   ¸B	 ÁB! Â	BÂB! ÂBÂB! Â!C rL   c                   ó,   ^ • \ rS rSrSrU 4S jrSrU =r$ )ÚInMemorySSHChanneli  zd
Minimal implementation of a L{SSHChannel} like class which only reads and
writes data from memory.
c                 ó<   >• Xl         SU l        [        TU ]  5         g)z\
@param conn: The SSH connection associated with this channel.
@type conn: L{SSHConnection}
r   N)ÚconnÚlocalClosedÚsuperÚ__init__)r-   r’   Ú	__class__s     €r.   r•   ÚInMemorySSHChannel.__init__  s   ø€ ð
 Œ	ØˆÔÜ‰ÑÕr1   )r’   r“   )rD   rE   rF   rG   rH   r•   rI   Ú__classcell__)r–   s   @r.   r�   r�     s   ø† ñ÷
ó r1   r�   c                   ó*   • \ rS rSrSrS rS rS rSrg)ÚFilesystemAccessExpectationsi  z;
A test helper used to support expected filesystem access.
c                 ó   • 0 U l         g r'   ©Ú_cacher,   s    r.   r•   Ú%FilesystemAccessExpectations.__init__  s	   € Øˆ�r1   c                 ó"   • X0R                   X4'   g)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œ   )r-   ÚpathÚflagsÚstreams       r.   ÚputÚ FilesystemAccessExpectations.put  s   € ð &,�‰�T�MÒ"r1   c                 ó:   • U R                   R                  X45      $ )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)r-   r    r¡   s      r.   r¦   Ú FilesystemAccessExpectations.pop(  s   € ð �{‰{�‰ ˜}Ó-Ð-r1   rœ   N)	rD   rE   rF   rG   rH   r•   r£   r¦   rI   rJ   r1   r.   rš   rš     s   † ñòò,õ.r1   rš   c                   ó$   • \ rS rSrSrS rS rSrg)Ú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                 óD   • [        U 5      U l        SSS.U l        Xl        g )Né   é
   )ÚrequestsÚ
buffersize)r�   Ú	transportÚoptionsÚ_availableFiles)r-   ÚavailableFiless     r.   r•   ÚInMemorySFTPClient.__init__B  s%   € Ü+¨DÓ1ˆŒàØñ
ˆŒð  .Õr1   c                 ó8   • U R                   R                  X5      $ )ze
@see: L{filetransfer.FileTransferClient.openFile}.

Retrieve and remove cached file based on flags.
)r±   r¦   )r-   Úfilenamer¡   Úattrss       r.   ÚopenFileÚInMemorySFTPClient.openFileJ  s   € ð ×#Ñ#×'Ñ'¨Ó8Ð8r1   )r±   r°   r¯   N)rD   rE   rF   rG   rH   r•   r·   rI   rJ   r1   r.   r©   r©   8  s   † ñò.õ9r1   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)ÚInMemoryRemoteFileiS  z3
An L{ISFTPFile} which handles all data in memory.
c                 ó<   • Xl         [        R                  " U 5        g)z4
@param name: Name of this file.
@type name: L{str}
N)Únamer   r•   )r-   r¼   s     r.   r•   ÚInMemoryRemoteFile.__init__Y  s   € ð
 Œ	Ü×Ò˜Õr1   c                 ór   • U R                  U5        U R                  U5        [        R                  " U 5      $ )z
@see: L{ISFTPFile.writeChunk}
)ÚseekÚwriter   Úsucceed)r-   ÚstartÚdatas      r.   Ú
writeChunkÚInMemoryRemoteFile.writeChunka  s+   € ð 	�	‰	�%ÔØ�
‰
�4ÔÜ�}Š}˜TÓ"Ð"r1   c                 ó   • SU l         g)zW
@see: L{ISFTPFile.writeChunk}

Keeps data after file was closed to help with testing.
TN)Ú_closedr,   s    r.   ÚcloseÚInMemoryRemoteFile.closei  s   € ð ˆ�r1   c                 ó   • g r'   rJ   r,   s    r.   ÚgetAttrsÚInMemoryRemoteFile.getAttrsq  ó   € àr1   c                 ó   • g r'   rJ   )r-   ÚoffsetÚlengths      r.   Ú	readChunkÚInMemoryRemoteFile.readChunku  rÍ   r1   c                 ó   • g r'   rJ   )r-   r¶   s     r.   ÚsetAttrsÚInMemoryRemoteFile.setAttrsy  rÍ   r1   c                 ó.   • [         R                  " U 5      $ )zJ
Get current data of file.

Allow reading data event when file is closed.
)r   r>   r,   s    r.   r>   ÚInMemoryRemoteFile.getvalue}  s   € ô ×Ò Ó%Ð%r1   )rÇ   r¼   N)rD   rE   rF   rG   rH   r•   rÄ   rÈ   rË   rÑ   rÔ   r>   rI   rJ   r1   r.   rº   rº   S  s*   † ñòò#òòòòõ&r1   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S jrSS jrS rS rS rS rSrg)ÚStdioClientTestsi†  z 
Tests for L{cftp.StdioClient}.
c                 óf  • [        5       U l        [        U R                  5      n[        R                  " U5      U l        SU R
                  l        [        5       =U l        U R
                  l	        U R                  SS5        U R
                  R
                  R                  U R
                  l        g)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¯   )r-   Ú
sftpClients     r.   r/   ÚStdioClientTests.setUpŒ  s‚   € ô
 ;Ó<ˆÔÜ'¨×(;Ñ(;Ó<ˆ
Ü×&Ò& zÓ2ˆŒØ'*ˆ�‰Ô$Ü+7«>Ð9ˆŒ˜Ÿ™Ô(ð
 	× Ñ   bÔ)ð !%§¡× 2Ñ 2× <Ñ <ˆ�‰Õr1   c           	      ó  • U R                   R                  [        R                  " 5       S[        R
                  " 5       SSS[        R                  5        U R                  R                  S5      nUR                  U R                  S5        U$ )z[
The I{exec} command runs its arguments locally in a child process
using the user's shell.
ÚsecretéÒ  rc   Úbarzexec print(1 + 2)s   3
)rá   ÚaddUserÚgetpassÚgetuserrX   ÚgetuidÚsysÚ
executablerß   Ú_dispatchCommandÚaddCallbackr=   ©r-   Úds     r.   Ú	test_execÚStdioClientTests.test_execŸ  sf   € ð
 	�‰×ÑÜ�OŠOÓ˜x¬¯ª«°d¸EÀ5Ì#Ï.É.ô	
ð �K‰K×(Ñ(Ð)<Ó=ˆØ	�‰�d×&Ñ&¨Ô/Øˆr1   c           	      ó  • U R                   R                  [        R                  " 5       S[        R
                  " 5       SSSS5        U R                  R                  S5      nUR                  U R                  S5        U$ )zZ
If the local user has no shell, the I{exec} command runs its arguments
using I{/bin/sh}.
rç   rè   rc   ré   Ú zexec echo helloó   hello
©
rá   rê   rë   rì   rX   rí   rß   rð   rñ   r=   rò   s     r.   Útest_execWithoutShellÚ&StdioClientTests.test_execWithoutShell¬  sb   € ð
 	�‰×ÑÜ�OŠOÓ˜x¬¯ª«°d¸EÀ5È"ô	
ð �K‰K×(Ñ(Ð):Ó;ˆØ	�‰�d×&Ñ&¨
Ô3Øˆr1   c           	      ó  • U R                   R                  [        R                  " 5       S[        R
                  " 5       SSSS5        U R                  R                  S5      nUR                  U R                  S5        U$ )z?
The I{exec} command is run for lines which start with C{"!"}.
rç   rè   rc   ré   z/bin/shz!echo hellorø   rù   rò   s     r.   Ú	test_bangÚStdioClientTests.test_bang¹  sa   € ð 	�‰×ÑÜ�OŠOÓ˜x¬¯ª«°d¸EÀ5È)ô	
ð �K‰K×(Ñ(¨Ó7ˆØ	�‰�d×&Ñ&¨
Ô3Øˆr1   c                 óh   ^^^• SSK m " UUU4S jS5      nU R                  [        SU" 5       5        g)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}
r   Nc                   ó&   >• \ rS rSrU UU4S jrSrg)Ú7StdioClientTests.setKnownConsoleSize.<locals>.FakeFcntliÒ  c                 óz   >• UTR                   :w  a  U R                  S5        [        R                  " STTSS5      $ )Nz#Only window-size queries supported.Ú4Hr   )Ú
TIOCGWINSZÚfailÚstructÚpack)r-   ÚfdÚoptÚmutateÚheightÚttyÚwidths       €€€r.   ÚioctlÚ=StdioClientTests.setKnownConsoleSize.<locals>.FakeFcntl.ioctlÓ  s3   ø€ Ø˜#Ÿ.™.Ó(Ø—I‘IÐCÔDÜ—{’{ 4¨°¸¸1Ó=Ð=r1   rJ   N)rD   rE   rF   rG   r  rI   )r  r  r  s   €€€r.   Ú	FakeFcntlr  Ò  s   ø† ÷>ò >r1   r  Úfcntl)r  r]   r   )r-   r  r  r  r  s    `` @r.   rã   Ú$StdioClientTests.setKnownConsoleSizeÅ  s&   ú€ ó 	÷	>ö 	>ð 	�
‰
”4˜¡)£+Õ.r1   c                 óÈ  • U R                  SS5        [        5       =oR                  l        [	        S5      nSUl        [        R                  " U5      nSUl        UR                  5       nUR                  S5        U=R                  S-  sl        U R                  R                  X45        SnU R                  U R                  R                  R                  5       U5        g	)
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.
r¬   é"   ó   xó   samplei (  g       @i   s#   b'sample' 40% 4.0kB 2.0kBps 00:03 N)rã   r   rß   r   r   r¼   r   ÚFileWrapperÚsizeÚsecondsÚadvanceÚtotalÚ_printProgressBarr=   r¯   Úvalue©r-   ÚclockÚwrappedÚwrapperÚ	startTimeÚresults         r.   Útest_printProgressBarReportingÚ/StdioClientTests.test_printProgressBarReportingÚ  s«   € ð 	× Ñ   RÔ(Ü&+£gÐ-ˆ—‘Ô#Ü˜$“-ˆØ ˆŒÜ×"Ò" 7Ó+ˆØ ˆŒØ—M‘M“Oˆ	Ø�‰�cÔØ�Š˜Ñ�à�‰×%Ñ% gÔ9à8ˆØ×Ñ˜Ÿ™×.Ñ.×4Ñ4Ó6¸Õ?r1   c                 ón  • U R                  SS5        [        5       =oR                  l        [	        S5      nSUl        [        R                  " U5      nUR                  5       nU R                  R                  X45        SnU R                  U R                  R                  R                  5       U5        g)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  r  r  s!   b'sample'  0% 0.0B 0.0Bps 00:00 N)rã   r   rß   r   r   r¼   r   r  r  r  r=   r¯   r  r  s         r.   Útest_printProgressBarNoProgressÚ0StdioClientTests.test_printProgressBarNoProgressò  sŠ   € ð 	× Ñ   RÔ(Ü&+£gÐ-ˆ—‘Ô#Ü˜$“-ˆØ ˆŒÜ×"Ò" 7Ó+ˆØ—M‘M“Oˆ	à�‰×%Ñ% gÔ9à6ˆØ×Ñ˜Ÿ™×.Ñ.×4Ñ4Ó6¸Õ?r1   c                 ó  • U R                  SS5        [        5       nSUl        [        R                  " U5      nU R
                  R                  US5        SnU R                  X0R
                  R                  R                  5       5        g)z%
Print the progress for empty files.
r¬   r  s
   empty-filer   s%   b'empty-file'100% 0.0B 0.0Bps 00:00 N)
rã   r   r¼   r   r  rß   r  r=   r¯   r  )r-   r   r!  r#  s       r.   Útest_printProgressBarEmptyFileÚ/StdioClientTests.test_printProgressBarEmptyFile  sl   € ð 	× Ñ   RÔ(Ü“)ˆØ$ˆŒÜ×"Ò" 7Ó+ˆà�‰×%Ñ% g¨qÔ1à:ˆØ×Ñ˜§¡×!6Ñ!6×!<Ñ!<Ó!>Õ?r1   c                 ó^   • U R                   R                  S5      nU R                  SU5        g)z;
Returns empty value for both filename and remaining data.
z  )r÷   r÷   N©rß   Ú_getFilenamer=   ©r-   r#  s     r.   Útest_getFilenameEmptyÚ&StdioClientTests.test_getFilenameEmpty  s(   € ð —‘×)Ñ)¨$Ó/ˆà×Ñ˜ 6Õ*r1   c                 ó^   • U R                   R                  S5      nU R                  SU5        g)zL
Returns empty value for remaining data when line contains
only a filename.
ú
only-local)r3  r÷   Nr-  r/  s     r.   Útest_getFilenameOnlyLocalÚ*StdioClientTests.test_getFilenameOnlyLocal  s)   € ð
 —‘×)Ñ)¨,Ó7ˆà×ÑÐ+¨VÕ4r1   c                 ó^   • U R                   R                  S5      nU R                  SU5        g)zM
Returns filename and remaining data striped of leading and trailing
spaces.
z local  remote file  )Úlocalzremote fileNr-  r/  s     r.   Útest_getFilenameNotQuotedÚ*StdioClientTests.test_getFilenameNotQuoted#  s*   € ð
 —‘×)Ñ)Ð*AÓBˆà×ÑÐ1°6Õ:r1   c                 ó^   • U R                   R                  S5      nU R                  SU5        g)zq
Returns filename and remaining data not striped of leading and trailing
spaces when quoted paths are requested.
z" " local file "  " remote  file " )z local file z" remote  file "Nr-  r/  s     r.   Útest_getFilenameQuotedÚ'StdioClientTests.test_getFilenameQuoted,  s*   € ð
 —‘×)Ñ)Ð*NÓOˆà×ÑÐ=¸vÕFr1   Nc                 óœ   • Uc  U R                  5       n[        US5       nUR                  U5        SSS5        U$ ! , (       d  f       U$ = f)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À   )r-   r    ÚcontentÚfiles       r.   ÚmakeFileÚStdioClientTests.makeFile5  sD   € ð ‰<Ø—;‘;“=ˆDÜ�$˜Ô Ø�J‰J�wÔ÷ àˆ÷ Ôàˆús	    <¼
Ac                 ó  • U R                   R                  R                  5       nUR                  S5      nUR	                  S5      n/ n/ nU GHX  u  pgn/ n	U H  n
U	R                  U SU
 35        M     U	R                  SU SU 35        UR                  U	5        UR                  S5      R                  S5      R	                  S5      nUSS	 nUS	   R                  S
5      R	                  S
5      nUR                  U5        / nUSS	  Hp  n
U
R                  5       R                  SS5      S   n
U
R                  5       R	                  SS5      n
UR                  U
S    SU
S   R                  5        35        Mr     UR                  US	   5        UR                  U5        GM[     U(       a%  U R                  [        U5      [        U5      5        OU R                  XE5        U R                  S[        U5      S5        g)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

r9   z
Ú zTransferred z to r   ÚNéÿÿÿÿÚ
é   r«   z5There are still put responses which were not checked.)rß   r¯   r  ÚdecodeÚsplitÚappendr¦   ÚstripÚextendÚrsplitr=   ÚsortedÚlen)r-   Ú	transfersÚrandomOrderÚoutputÚexpectedOutputÚactualOutputr7  ÚremoteÚexpectedÚexpectedTransferÚlineÚprogressPartsÚactualÚlastÚactualTransfers                  r.   ÚcheckPutMessageÚ StdioClientTests.checkPutMessageI  sä  € ð —‘×&Ñ&×,Ñ,Ó.ˆØ—‘˜wÓ'ˆØ—‘˜fÓ%ˆàˆØˆä'0Ñ#ˆE˜8ð  "ÐÛ �Ø ×'Ñ'¨5¨'°°4°&Ð(9Ö:ñ !à×#Ñ# l°5°'¸¸f¸XÐ$FÔGØ×!Ñ!Ð"2Ô3à"ŸJ™J q›M×/Ñ/°Ó5×;Ñ;¸DÓAˆMØ" 3 BÐ'ˆFà  Ñ$×*Ñ*¨4Ó0×6Ñ6°tÓ<ˆDØ�M‰M˜$ÔàˆNð ˜s ›�ð —z‘z“|×*Ñ*¨3°Ó2°1Ñ5�ð —z‘z“|×)Ñ)¨#¨qÓ1�Ø×%Ñ%¨¨a©¨	°°4¸±7·=±=³?Ð2CÐ&DÖEñ $ð ×!Ñ! &¨¡*Ô-Ø×Ñ ×/ñ? (1öB Ø×ÑœV NÓ3´V¸LÓ5IÕJà×Ñ˜^Ô:à×ÑØÜ�‹KØCõ	
r1   c                 ó¸  • SnU R                  US9n[        R                  [        R                  -  [        R                  -  n[
        R                  R                  S[
        R                  R                  U5      5      n[        U5      nU R                  R                  XC[        R                  " U5      5        SU R                  R                  R                  S'   U R                  R!                  U5      nU R#                  U5        U R%                  XR'                  5       5        U R)                  UR*                  5        U R-                  X$/ SQ4/5        g)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)rA  rÛ   r¬   r®   )z	76% 10.0Bú
100% 13.0Brc  N)rC  r   Ú	FXF_WRITEÚ	FXF_CREATÚ	FXF_TRUNCrX   r    ÚjoinÚbasenamerº   rÝ   r£   r   rÁ   rß   r°   Úcmd_PUTÚsuccessResultOfr=   r>   r4   rÇ   r`  )r-   rA  Ú	localPathr¡   Ú
remoteNameÚ
remoteFileÚdeferreds          r.   Útest_cmd_PUTSingleNoRemotePathÚ/StdioClientTests.test_cmd_PUTSingleNoRemotePath†  s  € ð %ˆØ—M‘M¨'�MÐ2ˆ	Ü×&Ñ&¬×)?Ñ)?Ñ?Ä,×BXÑBXÑXˆÜ—W‘W—\‘\ #¤r§w¡w×'7Ñ'7¸	Ó'BÓCˆ
Ü'¨
Ó3ˆ
Ø×Ñ×Ñ 
´5·=²=ÀÓ3LÔMØ35ˆ�‰×Ñ×"Ñ" <Ñ0à—;‘;×&Ñ& yÓ1ˆØ×Ñ˜XÔ&à×Ñ˜×"5Ñ"5Ó"7Ô8Ø�‰˜
×*Ñ*Ô+Ø×ÑØÒ%NÐOÐPõ	
r1   c                 ó  • U R                  5       n[        R                  [        R                  -  [        R                  -  nSn[        U5      nU R                  R                  X2[        R                  " U5      5        U R                  R                  U SU S35      nU R                  U5        U R                  XS/4/5        U R                  UR                  5        U R!                  SUR#                  5       5        g)zh
Remote path is extracted from first filename after local file.

Any other data in the line is ignored.
z/remote-pathrF  z ignoredú	100% 0.0Br1   N)rC  r   rd  re  rf  rº   rÝ   r£   r   rÁ   rß   ri  rj  r`  r4   rÇ   r=   r>   )r-   rk  r¡   rl  rm  rn  s         r.   Útest_cmd_PUTSingleRemotePathÚ-StdioClientTests.test_cmd_PUTSingleRemotePathž  sÐ   € ð —M‘M“Oˆ	Ü×&Ñ&¬×)?Ñ)?Ñ?Ä,×BXÑBXÑXˆØ#ˆ
Ü'¨
Ó3ˆ
Ø×Ñ×Ñ 
´5·=²=ÀÓ3LÔMà—;‘;×&Ñ&¨)¨°A°j°\ÀÐ'JÓKˆØ×Ñ˜XÔ&à×Ñ˜y°{°mÐDÐEÔFØ�‰˜
×*Ñ*Ô+Ø×Ñ˜˜j×1Ñ1Ó3Õ4r1   c                 ó  • U R                  5       n[        R                  R                  U5      nSn[        R                  R	                  U5      nU R                  [        R                  R                  XC5      S9n[        R                  [        R                  -  [        R                  -  nSU 3nSU 3n[        U5      n	[        U5      n
U R                  R                  Xv[        R                  " U	5      5        U R                  R                  X†[        R                  " U
5      5        U R                  R!                  [        R                  R                  US5      5      nU R#                  U5        U R%                  U	R&                  5        U R)                  SU	R+                  5       5        U R%                  U
R&                  5        U R)                  SU
R+                  5       5        U R-                  XS/4XXS/4/SS9  g	)
zl
When a gobbing expression is used local files are transferred with
remote file names based on local names.
úsecond-name©r    rÛ   Ú*r1   rr  T©rT  N)rC  rX   r    rh  Údirnamerg  r   rd  re  rf  rº   rÝ   r£   r   rÁ   rß   ri  rj  r4   rÇ   r=   r>   r`  )r-   ÚfirstÚ	firstNameÚ
secondNameÚparentÚsecondr¡   ÚfirstRemotePathÚsecondRemotePathÚfirstRemoteFileÚsecondRemoteFilern  s               r.   Ú test_cmd_PUTMultipleNoRemotePathÚ1StdioClientTests.test_cmd_PUTMultipleNoRemotePath±  s¤  € ð
 —‘“ˆÜ—G‘G×$Ñ$ UÓ+ˆ	Ø"ˆ
Ü—‘—‘ Ó'ˆØ—‘¤B§G¡G§L¡L°Ó$D�ÐEˆÜ×&Ñ&¬×)?Ñ)?Ñ?Ä,×BXÑBXÑXˆØ˜i˜[˜/ˆØ˜z˜lÐ+ÐÜ,¨_Ó=ˆÜ-Ð.>Ó?ÐØ×Ñ×Ñ ¼¿ºÀoÓ8VÔWØ×Ñ×ÑØ¤U§]¢]Ð3CÓ%Dô	
ð —;‘;×&Ñ&¤r§w¡w§|¡|°F¸CÓ'@ÓAˆØ×Ñ˜XÔ&à�‰˜×/Ñ/Ô0Ø×Ñ˜˜o×6Ñ6Ó8Ô9Ø�‰Ð(×0Ñ0Ô1Ø×Ñ˜Ð.×7Ñ7Ó9Ô:Ø×Ñà¨+¨Ð7Ø¨K¨=Ð9ðð ð 	ò 	
r1   c                 ó.  • U R                  5       n[        R                  R                  U5      nSn[        R                  R	                  U5      nU R                  [        R                  R                  XC5      S9n[        R                  [        R                  -  [        R                  -  n[        U5      n[        U5      nSU 3n	SU 3n
U R                  R                  X–[        R                  " U5      5        U R                  R                  X¦[        R                  " U5      5        U R                  R!                  SR#                  [        R                  R                  US5      5      5      nU R%                  U5        U R'                  UR(                  5        U R+                  SUR-                  5       5        U R'                  UR(                  5        U R+                  SUR-                  5       5        U R/                  XS/4XSS/4/SS	9  g
)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.
rv  rw  z/remote/z	{} remoterx  r1   rr  Try  N)rC  rX   r    rh  rz  rg  r   rd  re  rf  rº   rÝ   r£   r   rÁ   rß   ri  Úformatrj  r4   rÇ   r=   r>   r`  )r-   r{  r|  r}  r~  r  r¡   r‚  rƒ  r€  r�  rn  s               r.   Ú"test_cmd_PUTMultipleWithRemotePathÚ3StdioClientTests.test_cmd_PUTMultipleWithRemotePathÔ  s¯  € ð —‘“ˆÜ—G‘G×$Ñ$ UÓ+ˆ	Ø"ˆ
Ü—‘—‘ Ó'ˆØ—‘¤B§G¡G§L¡L°Ó$D�ÐEˆÜ×&Ñ&¬×)?Ñ)?Ñ?Ä,×BXÑBXÑXˆÜ,¨YÓ7ˆÜ-¨jÓ9ÐØ$ Y KÐ0ˆØ% j \Ð2ÐØ×Ñ×Ñ ¼¿ºÀoÓ8VÔWØ×Ñ×ÑØ¤U§]¢]Ð3CÓ%Dô	
ð —;‘;×&Ñ& {×'9Ñ'9¼"¿'¹'¿,¹,ÀvÈsÓ:SÓ'TÓUˆØ×Ñ˜XÔ&à�‰˜×/Ñ/Ô0Ø×Ñ˜˜o×6Ñ6Ó8Ô9Ø�‰Ð(×0Ñ0Ô1Ø×Ñ˜Ð.×7Ñ7Ó9Ô:Ø×Ñà K =Ð1Ø k ]Ð3ðð ð 	ò 	
r1   )rß   rá   rÝ   )Nr1   )F)rD   rE   rF   rG   rH   r/   rô   rú   rý   rã   r$  r'  r*  r0  r4  r8  r;  rC  r`  ro  rs  r„  rˆ  rI   rJ   r1   r.   rÙ   rÙ   †  sg   † ñò=ò&òò
ò/ò*@ò0@ò$@ò+ò5ò;òGôô(;
òz
ò05ò&!
õF#
r1   rÙ   c                   ó    • \ rS rSrS rS rSrg)ÚFileTransferTestRealmiú  c                 ó   • Xl         g r'   ©ÚtestDir)r-   rŽ  s     r.   r•   ÚFileTransferTestRealm.__init__û  s   € Ø�r1   c                 ó>   • [        U R                  5      nUS   US 4$ )Nr   c                  ó   • g r'   rJ   rJ   r1   r.   Ú<lambda>Ú5FileTransferTestRealm.requestAvatar.<locals>.<lambda>   s   € ¨r1   )r	   rŽ  )r-   ÚavatarIDÚmindr   Úas        r.   ÚrequestAvatarÚ#FileTransferTestRealm.requestAvatarþ  s!   € Ü" 4§<¡<Ó0ˆØ˜!‰}˜a¡Ð-Ð-r1   r�  N)rD   rE   rF   rG   r•   r—  rI   rJ   r1   r.   r‹  r‹  ú  s   † òõ.r1   r‹  c                   óT   • \ 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)Ú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                 óZ   • U R                  5         Xl        SU l        SU l        SU l        g)zZ
@param onOutReceived: A L{Deferred} to be fired as soon as data is
received from stdout.
NF)ÚclearBufferÚonOutReceivedÚonProcessEndÚ_expectingCommandÚ_processEnded)r-   r�  s     r.   r•   ÚSFTPTestProcess.__init__
  s.   € ð
 	×ÑÔØ*ÔØ ˆÔØ!%ˆÔØ"ˆÕr1   c                 ó.   • SU l         / U l        SU l        g)zB
Clear any buffered data received from stdout. Should be private.
r1   N)ÚbufferÚ_linesReceivedÚ_lineBufferr,   s    r.   rœ  ÚSFTPTestProcess.clearBuffer  s   € ð ˆŒØ ˆÔØˆÕr1   c                 ó€  • [         R                  " SU-  5        U R                  U-   R                  S5      nUR	                  S5      U l        U R
                  R                  U5        U R                  b$  U R                  Sso0l        UR                  U5        U =R                  U-  sl	        U R                  5         g)z?
Called by Twisted when the cftp client prints data to stdout.
zgot %ró   
rH  N)r   Úmsgr¥  rL  r¦   r¤  rO  r�  Úcallbackr£  Ú_checkForCommand)r-   rÃ   Úlinesró   s       r.   ÚoutReceivedÚSFTPTestProcess.outReceived  sš   € ô 	�Š�˜4‘Ô Ø×!Ñ! DÑ(×/Ñ/°Ó6ˆØ Ÿ9™9 R›=ˆÔØ×Ñ×"Ñ" 5Ô)ð ×ÑÑ)Ø$(×$6Ñ$6¸Ð!ˆAÔ!Ø�J‰J�tÔØ�Š�tÑ�Ø×ÑÕr1   c                 ó4  • SnU R                   (       a…  U R                  U:X  at  SR                  U R                  5      nUR	                  U5      (       a  U[        U5      S  nU R                  5         U R                   S so0l         UR                  U5        g g g )Ns   cftp> r¨  )rŸ  r¥  rg  r¤  Ú
startswithrR  rœ  rª  )r-   ÚpromptÚbufró   s       r.   r«  Ú SFTPTestProcess._checkForCommand.  sƒ   € ØˆØ×!×! d×&6Ñ&6¸&Ó&@Ø—*‘*˜T×0Ñ0Ó1ˆCØ�~‰~˜f×%Ñ%Øœ#˜f›+˜-Ð(�Ø×ÑÔØ(,×(>Ñ(>ÀÐ%ˆAÔ%Ø�J‰J�s�Oð 'AÐ!r1   c                 ó6   • [         R                  " SU-  5        g)z?
Called by Twisted when the cftp client prints data to stderr.
zerr: %sN)r   r©  )r-   rÃ   s     r.   ÚerrReceivedÚSFTPTestProcess.errReceived8  s   € ô 	�Š�	˜DÑ Õ!r1   c                 ó   • U R                   $ )zA
Return the contents of the buffer of data received from stdout.
)r£  r,   s    r.   Ú	getBufferÚSFTPTestProcess.getBuffer>  s   € ð �{‰{Ðr1   c                 óö   • [         R                  " 5       U l        U R                  5         [	        U[
        5      (       a  UR                  S5      nU R                  R                  US-   5        U R                  $ )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.
r9   r¨  )	r   ÚDeferredrŸ  rœ  Ú
isinstanceÚstrr;   r¯   rÀ   ©r-   Úcommands     r.   Ú
runCommandÚSFTPTestProcess.runCommandD  s\   € ô "'§¢Ó!1ˆÔØ×ÑÔÜ�gœs×#Ñ#Ø—n‘n WÓ-ˆGØ�‰×Ñ˜W u™_Ô-Ø×%Ñ%Ð%r1   c                 óº   • [         R                  " S5      nU Vs/ s H  o2R                  U R                  U5      PM      nn[         R                  " U5      $ s  snf )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«   )r   ÚDeferredSemaphoreÚrunrÀ  ÚgatherResults)r-   ÚcommandsÚsemr¿  Údls        r.   Ú	runScriptÚSFTPTestProcess.runScriptV  sL   € ô ×%Ò% aÓ(ˆÙ?GÓHºx°G�g‰g�d—o‘o wÖ/¹xˆÐHÜ×"Ò" 2Ó&Ð&ùò Is   ›%Ac                 óÒ   • U R                   (       a  [        R                  " S5      $ [        R                  " 5       U l        U R
                  R                  S5        U R                  $ )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¯   ÚsignalProcessr,   s    r.   ÚkillProcessÚSFTPTestProcess.killProcesse  sI   € ð ××Ü—=’= Ó&Ð&Ü!ŸNšNÓ,ˆÔØ�‰×$Ñ$ VÔ,Ø× Ñ Ð r1   c                 ó~   • SU l         U R                  (       a%  U R                  Sso l        UR                  S5        gg)z6
Called by Twisted when the cftp client process ends.
TN)r   rž  rª  )r-   Úreasonró   s      r.   ÚprocessEndedÚSFTPTestProcess.processEndedt  s9   € ð "ˆÔØ××Ø#'×#4Ñ#4°dÐ ˆAÔ Ø�J‰J�tÕð r1   )rŸ  r¥  r¤  r   r£  r�  rž  N)rD   rE   rF   rG   rH   r•   rœ  r­  r«  rµ  r¸  rÀ  rÉ  rÎ  rÒ  rI   rJ   r1   r.   rš  rš    s9   † ñò	#òò ò"ò"òò&ò$'ò!õr1   rš  c                   ó2   • \ rS rSrS rS rS rS rS rSr	g)	ÚCFTPClientTestBasei~  c                 ó   • [        SS5       nUR                  [        R                  5        S S S 5        [        SS5       nUR                  [        R                  5        S S S 5        [
        R                  " SS5        [        SS5       nUR                  S[        R                  -   5        S S S 5        [        R                  " U 5      $ ! , (       d  f       N¦= f! , (       d  f       Nƒ= f! , (       d  f       NF= f)Núrsa_test.pubr>  Úrsa_testi€�  Úkh_tests
   127.0.0.1 )	r@  rÀ   r    ÚpublicRSA_opensshÚprivateRSA_opensshrX   Úchmodr
   r/   ©r-   Úfs     r.   r/   ÚCFTPClientTestBase.setUp  s¨   € Ü�. $Ô'¨1Ø�G‰G”H×.Ñ.Ô/÷ (ä�*˜dÔ# qØ�G‰G”H×/Ñ/Ô0÷ $ä
�Š�˜UÔ#Ü�)˜TÔ" aØ�G‰G�M¤H×$>Ñ$>Ñ>Ô?÷ #ä×!Ò! $Ó'Ð'÷ (Õ'úç#Õ#ú÷ #Õ"ús#   � CÁ CÂ#C/Ã
CÃ
C,Ã/
C=c                 ó  • [        U R                  5      n[        R                  " U5      nUR	                  [
        R                  " 5       5        [
        R                  " 5       nX#l        [        R                  " SUSS9U l
        g )Nr   z	127.0.0.1)Ú	interface)r‹  rŽ  r   ÚPortalÚregisterCheckerr    ÚconchTestPublicKeyCheckerÚConchTestServerFactoryr   Ú	listenTCPÚserver)r-   ÚrealmÚpÚfacs       r.   ÚstartServerÚCFTPClientTestBase.startServer‰  s^   € Ü% d§l¡lÓ3ˆÜ�MŠM˜%Ó ˆØ	×Ñœ(×<Ò<Ó>Ô?Ü×-Ò-Ó/ˆØŒ
Ü×'Ò'¨¨3¸+ÑFˆ�r1   c                 ó‚  • [        U R                  R                  S5      (       d  U R                  S 5      $ SU R                  R                  R                  l        [        R                  " U R                  R                  R                  R                  R                  5      nUR                  U R                  5        U$ )NÚprotor«   )Ú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×(Ñ(Ô)Øˆr1   c                 óV   • [         R                  " U R                  R                  5      $ r'   )r   ró  rç  ÚstopListening©r-   Úignoreds     r.   rñ  Ú CFTPClientTestBase._cbStopServer™  s   € Ü×"Ò" 4§;¡;×#<Ñ#<Ó=Ð=r1   c                 ó�   • S H  n [         R                  " U5        M     [        R                  " U 5      $ ! [         a     MA  f = f)N)r×  rØ  rÙ  )rX   ÚremoveÚBaseExceptionr
   ÚtearDownrÝ  s     r.   rÿ  ÚCFTPClientTestBase.tearDownœ  sC   € Û8ˆAðÜ—	’	˜!–ñ 9ô
 ×$Ò$ TÓ*Ð*øô !ó Úðús   ‡7·
AÁA)rç  N)
rD   rE   rF   rG   r/   rë  rõ  rñ  rÿ  rI   rJ   r1   r.   rÕ  rÕ  ~  s   † ò(òGòò>õ+r1   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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g)Ú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                 óB  ^ • [         R                  T 5        T R                  5         SnT R                  R	                  5       R
                  n[        R                  " X-  R                  5       SS9n[        R                  " S[        R                   SU 35        [        R                  " 5       n[        U5      T l        UR#                  U 4S j5        [$        R&                  R)                  5       n[$        R*                  R-                  [        R.                  5      US'   / n0 nU H:  n[1        U[2        5      (       a  UR5                  S5      nUR7                  U5        M<     U HW  nXH   n	[1        U[2        5      (       a  UR5                  S5      n[1        U	[2        5      (       a  U	R5                  S5      n	X–U'   MY     [        R                  " U5        [        R                  " U5        [8        R:                  " T R                   [        R                  XVS	9  U$ )
Nz‚-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 rF  c                 ó8   >• TR                   R                  5       $ r'   )ÚprocessProtocolrœ  ©Ú_r-   s    €r.   r’  Ú3OurServerCmdLineClientTests.setUp.<locals>.<lambda>Â  ó   ø€  × 4Ñ 4× @Ñ @Ô Br1   Ú
PYTHONPATHr9   ©Úenv)rÕ  r/   rë  rç  ÚgetHostÚportr   Ú	_makeArgsrL  r   r©  rî   rï   r   r»  rš  r  rñ   rX   rY   ÚcopyÚpathseprg  r    r¼  r½  r;   rM  r   ÚspawnProcess)
r-   Úcmdsr  ró   r  ÚencodedCmdsÚ
encodedEnvÚcmdÚvarÚvals
   `         r.   r/   Ú!OurServerCmdLineClientTests.setUp¯  sš  ø€ Ü× Ñ  Ô&à×ÑÔðð 	ð �{‰{×"Ñ"Ó$×)Ñ)ˆÜ×#Ò# T¡[×$7Ñ$7Ó$9¸vÑFˆÜ�Š�(œ3Ÿ>™>Ð*¨!¨D¨6Ð2Ô3Ü�NŠNÓˆÜ.¨qÓ1ˆÔØ	�‰ÔBÔCÜ�j‰j�o‰oÓˆÜŸJ™JŸO™O¬C¯H©HÓ5ˆˆLÑØˆØˆ
ÛˆCÜ˜#œs×#Ñ#Ø—j‘j Ó)�Ø×Ñ˜sÖ#ñ ó ˆCØ‘(ˆCÜ˜#œs×#Ñ#Ø—j‘j Ó)�Ü˜#œs×#Ñ#Ø—j‘j Ó)�Ø!�s‹Oñ ô 	�Š�ÔÜ�Š�
ÔÜ×ÒØ× Ñ ¤#§.¡.°+ò	
ð ˆr1   c                 óR   ^ • T R                  5       nUR                  U 4S j5        U$ )Nc                 ó8   >• TR                   R                  5       $ r'   )r  rÎ  r	  s    €r.   r’  Ú6OurServerCmdLineClientTests.tearDown.<locals>.<lambda>Û  r  r1   )rõ  rñ   rò   s   ` r.   rÿ  Ú$OurServerCmdLineClientTests.tearDownÙ  s!   ø€ Ø�O‰OÓˆØ	�‰ÔBÔCØˆr1   c                 ó„   •  U R                   R                  R                  S5        g ! [        R                   a     g f = f)NrÌ  )r  r¯   rÍ  r   ÚProcessExitedAlreadyrù  s     r.   Ú_killProcessÚ(OurServerCmdLineClientTests._killProcessÞ  s9   € ð	Ø× Ñ ×*Ñ*×8Ñ8¸Õ@øÜ×)Ñ)ó 	Ùð	ús   ‚%( ¨?¾?c                 ó8   • U R                   R                  U5      $ )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Ð7r1   c                 ó8   • U R                   R                  U5      $ )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É  )r-   rÆ  s     r.   rÉ  Ú%OurServerCmdLineClientTests.runScriptì  s   € ð ×#Ñ#×-Ñ-¨hÓ7Ð7r1   c                 óþ   • U R                   nU R                  SSSSS5      nS nUR                  U5        UR                  U R                  UR                  [
        R                  " 5       SUR                  /5        U$ )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                 óœ   • / nU  H:  n[        U[        5      (       a  UR                  S5      nUR                  U5        M<     USS USS -   $ )z0
Callback function for handling command output.
r9   Né   é   )r¼  ÚbytesrK  rM  )rU  r  r  s      r.   Ú	cmdOutputÚ8OurServerCmdLineClientTests.testCdPwd.<locals>.cmdOutputÿ  sS   € ð ˆDÛ�Ü˜c¤5×)Ñ)ØŸ*™* WÓ-�CØ—‘˜CÖ ñ ð ˜˜�8˜d 1 2˜hÑ&Ð&r1   r÷   )rŽ  rÉ  rñ   r=   r    rX   Úgetcwd)r-   ÚhomeDirró   r1  s       r.   Ú	testCdPwdÚ%OurServerCmdLineClientTests.testCdPwdô  sg   € ð —,‘,ˆØ�N‰N˜5 &Ð*<¸gÀuÓMˆò		'ð 	
�‰�iÔ Ø	�‰�d×&Ñ&¨¯©´r·y²y³{ÀBÈÏÉÐ(UÔVØˆr1   c                 óZ   ^ • U 4S jnT R                  SSSS5      nUR                  U5      $ )zt
Check that 'ls -l' output includes the access permissions and that
this output changes appropriately with 'chmod'.
c                 ó  >• TR                  5         TR                  U S   R                  S5      5        TR                  U S   S5        TR                  U S   R                  S5      U S   5        TR                  U S   S5        g )Nr   s
   -rw-r--r--r«   r1   rJ  s
   ----------r.  )ÚflushLoggedErrorsr4   r°  r=   ©Úresultsr-   s    €r.   Ú_checkÚ7OurServerCmdLineClientTests.testChAttrs.<locals>._check  ss   ø€ Ø×"Ñ"Ô$Ø�O‰O˜G A™J×1Ñ1°-Ó@ÔAØ×Ñ˜W Q™Z¨Ô-Ø�O‰O˜G A™J×1Ñ1°-Ó@À'È!Á*ÔMØ×Ñ˜W Q™Z¨Õ-r1   zls -l testfile1zchmod 0 testfile1zchmod 644 testfile1©rÉ  rñ   ©r-   r<  ró   s   `  r.   ÚtestChAttrsÚ'OurServerCmdLineClientTests.testChAttrs  s5   ø€ õ	.ð �N‰NØØØØ!ó	
ˆð �}‰}˜VÓ$Ð$r1   c                 ó¶   ^ • U 4S jnT R                  SST R                  R                  5       -   SSS5      nUR                  S 5        UR                  U5      $ )zv
Check 'ls' works as expected. Checks for wildcards, hidden files,
listing directories and listing empty directories.
c                 óê   >• TR                  U S   / SQ5        TR                  U S   / SQ5        TR                  U S   SS/5        TR                  U S   / SQ5        TR                  U S	   S
/5        g )Nr   ©s   testDirectoryó   testRemoveFileó   testRenameFiles	   testfile1r«   rJ  rE  rF  r.  )s   .testHiddenFilerE  rF  r/  r1   ©r=   r:  s    €r.   r<  Ú4OurServerCmdLineClientTests.testList.<locals>._check*  s‚   ø€ Ø×ÑØ˜‘
ÚVôð ×ÑØ˜‘
ÚVôð ×Ñ˜W Q™ZÐ*;Ð=NÐ)OÔPØ×ÑØ˜‘
ÒVôð ×Ñ˜W Q™Z¨#¨Õ/r1   r   zls ../zls *Filezls -a *Filezls -l testDirectoryc                 óN   • U  Vs/ s H  oR                  S5      PM     sn$ s  snf )Nr¨  )rL  )ÚxsÚxs     r.   r’  Ú6OurServerCmdLineClientTests.testList.<locals>.<lambda>@  s   € ¹"Ó!=º"°Q§'¡'¨%¦.¹"Ò!=ùÒ!=s   …")rÉ  rŽ  rh  rñ   r?  s   `  r.   ÚtestListÚ$OurServerCmdLineClientTests.testList$  sW   ø€ õ	0ð �N‰NØØ�t—|‘|×,Ñ,Ó.Ñ.ØØØ!ó
ˆð 	
�‰Ñ=Ô>Ø�}‰}˜VÓ$Ð$r1   c                 ó  • U R                  S5      n[        R                  " S5      R                  S5      R	                  5       n[        U[        5      (       a  UR                  S5      nUR                  U R                  U5        U$ )z2
Check that running the '?' command returns help.
Ú?Nr÷   r9   )
rÀ  r   rÞ   Úcmd_HELPrN  r¼  r½  r;   rñ   r=   )r-   ró   ÚhelpTexts      r.   ÚtestHelpÚ$OurServerCmdLineClientTests.testHelpC  sj   € ð �O‰O˜CÓ ˆä×#Ò# DÓ)×2Ñ2°2Ó6×<Ñ<Ó>ˆÜ�h¤×$Ñ$Ø—‘ wÓ/ˆHØ	�‰�d×&Ñ&¨Ô1Øˆr1   Nc                 ób   • U R                  UR                  5       UR                  5       U5        g)zO
Assert that the files at C{name1} and C{name2} contain exactly the
same data.
N)r=   Ú
getContent)r-   Úname1Úname2r©  s       r.   ÚassertFilesEqualÚ,OurServerCmdLineClientTests.assertFilesEqualO  s(   € ð
 	×Ñ˜×)Ñ)Ó+¨U×-=Ñ-=Ó-?ÀÕEr1   c                 óv  ^ ^• SR                  T R                  R                  T R                  R                  5      m[        T[        5      (       a  TR                  S5      mUU 4S jnT R                  ST R                  R                   S35      nUR                  U5        UR                  U 4S j5        U$ )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 file2r9   c                 óð   >• TR                  U R                  T5      5        TR                  TR                  R	                  S5      TR                  R	                  S5      S5        TR                  S5      $ )NÚ	testfile1ú
test file2z
get failedzrm "test file2")r4   ÚendswithrY  rŽ  ÚchildrÀ  ©r#  rV  r-   s    €€r.   Ú	_checkGetÚ6OurServerCmdLineClientTests.testGet.<locals>._checkGetd  s_   ø€ Ø�O‰O˜FŸO™O¨NÓ;Ô<Ø×!Ñ!Ø—‘×"Ñ" ;Ó/Ø—‘×"Ñ" <Ó0Øôð
 —?‘?Ð#4Ó5Ð5r1   zget testfile1 "z/test file2"c                 ót   >• TR                  TR                  R                  S5      R                  5       5      $ )Nr^  ©ÚassertFalserŽ  r`  Úexistsr	  s    €r.   r’  Ú5OurServerCmdLineClientTests.testGet.<locals>.<lambda>p  ó(   ø€ �d×&Ñ& t§|¡|×'9Ñ'9¸,Ó'G×'NÑ'NÓ'PÔQr1   )r‡  rŽ  r    r¼  r½  r;   rÀ  rñ   )r-   rb  ró   rV  s   `  @r.   ÚtestGetÚ#OurServerCmdLineClientTests.testGetV  sš   ù€ ð E×KÑKØ�L‰L×ÑØ�L‰L×Ñó
ˆô �n¤c×*Ñ*Ø+×2Ñ2°7Ó;ˆNö	6ð �O‰O˜o¨d¯l©l×.?Ñ.?Ð-@ÀÐMÓNˆØ	�‰�iÔ Ø	�‰ÜQô	
ð ˆr1   c                 óT   ^ • U 4S jnT R                  S5      nUR                  U5      $ )zA
Test that 'get' works correctly when given wildcard parameters.
c                 óÚ   >• TR                  TR                  R                  S5      [        S5      S5        TR                  TR                  R                  S5      [        S5      S5        g )NÚtestRemoveFileútestRemoveFile get failedÚtestRenameFileútestRenameFile get failed)rY  rŽ  r`  r   )rú  r-   s    €r.   r<  Ú;OurServerCmdLineClientTests.testWildcardGet.<locals>._checky  s_   ø€ Ø×!Ñ!Ø—‘×"Ñ"Ð#3Ó4ÜÐ)Ó*Ø+ôð
 ×!Ñ!Ø—‘×"Ñ"Ð#3Ó4ÜÐ)Ó*Ø+õr1   z
get testR*)rÀ  rñ   r?  s   `  r.   ÚtestWildcardGetÚ+OurServerCmdLineClientTests.testWildcardGett  s'   ø€ õ

	ð �O‰O˜LÓ)ˆØ�}‰}˜VÓ$Ð$r1   c                 óZ  ^ ^• ST R                   R                  5       R                  -   S-   T R                   R                  5       R                  -   S-   mUU 4S jnT R                  ST R                   R                   S35      nUR	                  U5        UR	                  U 4S j5        U$ )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                 óî   >• TR                  TR                  R                  S5      TR                  R                  S5      5        TR                  U R	                  T5      5        TR                  S5      $ )Nr]  ú
test"file2zrm "test\"file2")rY  rŽ  r`  r4   r_  rÀ  ra  s    €€r.   Ú	_checkPutÚ6OurServerCmdLineClientTests.testPut.<locals>._checkPut–  s[   ø€ Ø×!Ñ!Ø—‘×"Ñ" ;Ó/°·±×1CÑ1CÀLÓ1Qôð �O‰O˜FŸO™O¨NÓ;Ô<Ø—?‘?Ð#6Ó7Ð7r1   úput z/testfile1 "test\"file2"c                 ót   >• TR                  TR                  R                  S5      R                  5       5      $ )Nrw  re  r	  s    €r.   r’  Ú5OurServerCmdLineClientTests.testPut.<locals>.<lambda>   ri  r1   )rŽ  ÚasBytesModer    rÀ  rñ   )r-   rx  ró   rV  s   `  @r.   ÚtestPutÚ#OurServerCmdLineClientTests.testPutˆ  s£   ù€ ð Ø�l‰l×&Ñ&Ó(×-Ñ-ñ.àñ ð �l‰l×&Ñ&Ó(×-Ñ-ñ.ð ñ	ð 	ö	8ð �O‰O˜d 4§<¡<×#4Ñ#4Ð"5Ð5NÐOÓPˆØ	�‰�iÔ Ø	�‰ÜQô	
ð ˆr1   c                 óÔ  ^ • T R                   R                  S5      R                  SS9 nUR                  S5        SSS5        T R                   R                  S5      R                  SS9 nUR                  S5        SSS5        U 4S jnT R	                  S	T R                   R
                   S
35      nUR                  U5        U$ ! , (       d  f       N’= f! , (       d  f       Na= f)zJ
Check that 'put' uploads files correctly when overwriting a longer
file.
ÚshorterFileÚw©Úmodeó   aNÚ
longerFileó   bbc                 óŽ   >• TR                  TR                  R                  S5      TR                  R                  S5      5        g )Nr�  r†  )rY  rŽ  r`  )r#  r-   s    €r.   rx  ÚEOurServerCmdLineClientTests.test_putOverLongerFile.<locals>._checkPut¯  s4   ø€ Ø×!Ñ!Ø—‘×"Ñ" =Ó1°4·<±<×3EÑ3EÀlÓ3Sõr1   rz  z/shorterFile longerFile)rŽ  r`  r@  rÀ   rÀ  r    rñ   )r-   rÞ  rx  ró   s   `   r.   Útest_putOverLongerFileÚ2OurServerCmdLineClientTests.test_putOverLongerFile¤  s´   ø€ ð �\‰\×Ñ Ó.×3Ñ3¸Ð3Ñ=ÀØ�G‰G�DŒM÷ >à�\‰\×Ñ Ó-×2Ñ2¸Ð2Ñ<ÀØ�G‰G�EŒN÷ =õ	ð
 �O‰O˜d 4§<¡<×#4Ñ#4Ð"5Ð5LÐMÓNˆØ	�‰�iÔ Øˆ÷ >Õ=úç<Õ<ús   ªCÁ,CÃ
CÃ
C'c                 ó  ^ ^• T R                   R                  S5      mTR                  5         TR                  S5      R                  SS9 nUR	                  S5        SSS5        T R                   R                  S5      R                  SS9 nUR	                  S5        SSS5        U U4S jnT R                  S	T R                   R                   S
35      nUR                  U5        U$ ! , (       d  f       N“= f! , (       d  f       Nb= f)z€
Check that 'put' uploads files correctly when overwriting a longer
file and you use a wildcard to specify the files to upload.
ÚdirrB  r‚  rƒ  r…  Nr‡  c                 óz   >• TR                  TR                  S5      TR                  R                  S5      5        g )NrB  )rY  r`  rŽ  )r#  r-   ÚsomeDirs    €€r.   rx  ÚMOurServerCmdLineClientTests.test_putMultipleOverLongerFile.<locals>._checkPutÅ  s+   ø€ Ø×!Ñ! '§-¡-°Ó"7¸¿¹×9KÑ9KÈFÓ9SÕTr1   rz  z/dir/*)rŽ  r`  ÚcreateDirectoryr@  rÀ   rÀ  r    rñ   )r-   rÞ  rx  ró   r�  s   `   @r.   Útest_putMultipleOverLongerFileÚ:OurServerCmdLineClientTests.test_putMultipleOverLongerFile¸  sÎ   ù€ ð —,‘,×$Ñ$ UÓ+ˆØ×ÑÔ!Ø�]‰]˜6Ó"×'Ñ'¨SÐ'Ñ1°QØ�G‰G�DŒM÷ 2à�\‰\×Ñ Ó'×,Ñ,°#Ð,Ñ6¸!Ø�G‰G�EŒN÷ 7ö	Uð �O‰O˜d 4§<¡<×#4Ñ#4Ð"5°VÐ<Ó=ˆØ	�‰�iÔ Øˆ÷ 2Õ1úç6Õ6ús   ÁC+ÂC<Ã+
C9Ã<
D
c                 óÂ   ^ • U 4S jnT R                  SST R                  R                   S3ST R                  R                  5       -  5      nUR	                  U5        U$ )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                 ó¦  >• TR                  U S   S5        TR                  U S   S5        TR                  TR                  R                  S5      TR                  R	                  5       R                  S5      S5        TR                  TR                  R                  S5      TR                  R	                  5       R                  S5      S5        g )Nr   r1   rJ  rn  ro  rp  rq  )r=   rY  rŽ  r`  r~  r:  s    €r.   ÚcheckÚ:OurServerCmdLineClientTests.testWildcardPut.<locals>.checkÓ  s­   ø€ Ø×Ñ˜W Q™Z¨Ô-Ø×Ñ˜W Q™Z¨Ô-à×!Ñ!Ø—‘×"Ñ"Ð#3Ó4Ø—‘×#Ñ#Ó%×+Ñ+Ð,<Ó=Ø+ôð
 ×!Ñ!Ø—‘×"Ñ"Ð#3Ó4Ø—‘×#Ñ#Ó%×+Ñ+Ð,<Ó=Ø+õr1   r,  rz  z/testR*zcd %s)rÉ  rŽ  r    rh  rñ   )r-   r–  ró   s   `  r.   ÚtestWildcardPutÚ+OurServerCmdLineClientTests.testWildcardPutÌ  sZ   ø€ õ	ð �N‰NØØ�4—<‘<×$Ñ$Ð% WÐ-Ø�d—l‘l×+Ñ+Ó-Ñ-ó
ˆð
 	
�‰�eÔØˆr1   c                 ó’   ^ • U 4S jnT R                  SS5      nUR                  U5        UR                  T R                  S5        U$ )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                 ó¸   >• TR                  5         TR                  U S   S5        TR                  U S   R                  S5      S5        TR	                  S5      $ )Nr   r1   r«   ó   lzlink failedzrm testLink)r9  r=   r4   r°  rÀ  r:  s    €r.   r<  Ú4OurServerCmdLineClientTests.testLink.<locals>._checkð  sO   ø€ Ø×"Ñ"Ô$Ø×Ñ˜W Q™Z¨Ô-Ø�O‰O˜G A™J×1Ñ1°$Ó7¸ÔGØ—?‘? =Ó1Ð1r1   zln testLink testfile1zls -l testLinkr1   ©rÉ  rñ   r=   r?  s   `  r.   ÚtestLinkÚ$OurServerCmdLineClientTests.testLinkê  sA   ø€ õ	2ð �N‰NÐ2Ð4DÓEˆØ	�‰�fÔØ	�‰�d×&Ñ&¨Ô,Øˆr1   c                 ó’   ^ • U 4S jnT R                  SS5      nUR                  U5        UR                  T R                  S5        U$ )zF
Test that we can create and remove directories with the cftp client.
c                 ó–   >• TR                  U S   S5        TR                  U S   R                  S5      5        TR                  S5      $ )Nr   r1   r«   ó   dzrmdir testMakeDirectory)r=   r4   r°  rÀ  r:  s    €r.   r<  Ú?OurServerCmdLineClientTests.testRemoteDirectory.<locals>._check   sB   ø€ Ø×Ñ˜W Q™Z¨Ô-Ø�O‰O˜G A™J×1Ñ1°$Ó7Ô8Ø—?‘?Ð#<Ó=Ð=r1   úmkdir testMakeDirectoryzls -l testMakeDirector?r1   rž  r?  s   `  r.   ÚtestRemoteDirectoryÚ/OurServerCmdLineClientTests.testRemoteDirectoryû  sA   ø€ õ
	>ð
 �N‰NÐ4Ð6OÓPˆØ	�‰�fÔØ	�‰�d×&Ñ&¨Ô,Øˆr1   c                 óZ   ^ • U 4S jnT R                  SS5      nUR                  U5        U$ )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                 óZ   >• TR                  U S   S5        TR                  U S   S5        g )Nr   r1   r«   s   remote error 11: mkdir failedrG  r:  s    €r.   r<  ÚHOurServerCmdLineClientTests.test_existingRemoteDirectory.<locals>._check  s,   ø€ Ø×Ñ˜W Q™Z¨Ô-Ø×Ñ˜W Q™ZÐ)IÕJr1   r¥  r>  r?  s   `  r.   Útest_existingRemoteDirectoryÚ8OurServerCmdLineClientTests.test_existingRemoteDirectory
  s.   ø€ õ	Kð �N‰NÐ4Ð6OÓPˆØ	�‰�fÔØˆr1   c                 óô   ^ • T R                  ST R                  R                   S35      nUR                  T R                  S5        UR                  U 4S j5        UR                  T R                  S5        U$ )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/testLocalDirectoryr1   c                 ó&   >• TR                  S5      $ )Nzrmdir testLocalDirectory)rÀ  r	  s    €r.   r’  Ú@OurServerCmdLineClientTests.testLocalDirectory.<locals>.<lambda>   s   ø€  §¡Ð0JÔ Kr1   )rÀ  rŽ  r    rñ   r=   rò   s   ` r.   ÚtestLocalDirectoryÚ.OurServerCmdLineClientTests.testLocalDirectory  sb   ø€ ð �O‰O˜g d§l¡l×&7Ñ&7Ð%8Ð8KÐLÓMˆØ	�‰�d×&Ñ&¨Ô,Ø	�‰ÔKÔLØ	�‰�d×&Ñ&¨Ô,Øˆr1   c                 ó’   ^ • U 4S jnT R                  SS5      nUR                  U5        UR                  T R                  S5        U$ )z!
Test that we can rename a file.
c                 óz   >• TR                  U S   S5        TR                  U S   S5        TR                  S5      $ )Nr   r1   r«   s	   testfile2zrename testfile2 testfile1)r=   rÀ  r:  s    €r.   r<  Ú6OurServerCmdLineClientTests.testRename.<locals>._check)  s;   ø€ Ø×Ñ˜W Q™Z¨Ô-Ø×Ñ˜W Q™Z¨Ô6Ø—?‘?Ð#?Ó@Ð@r1   zrename testfile1 testfile2zls testfile?r1   rž  r?  s   `  r.   Ú
testRenameÚ&OurServerCmdLineClientTests.testRename$  sA   ø€ õ
	Að
 �N‰NÐ7¸ÓHˆØ	�‰�fÔØ	�‰�d×&Ñ&¨Ô,Øˆr1   )r  r'   )rD   rE   rF   rG   rH   r/   rÿ  r#  rÀ  rÉ  r5  r@  rM  rS  rY  rj  rs  r~  rŠ  r’  r˜  rŸ  r¦  r«  r°  rµ  rI   rJ   r1   r.   r  r  ¥  sr   † ñò(òTò
ò8ò8òò4%ò,%ò>
ôFòò<%ò(ò8ò(ò(ò<ò"òò
õr1   r  c                   ó<   • \ rS rSrSrS rS rS rS rS r	S r
S	rg
)ÚOurServerBatchFileTestsi4  za
Functional tests which launch a SFTP server over localhost and checks csftp
in batch interface.
c                 óN   • [         R                  U 5        U R                  5         g r'   ©rÕ  r/   rë  r,   s    r.   r/   ÚOurServerBatchFileTests.setUp;  s   € Ü× Ñ  Ô&Ø×ÑÕr1   c                 óL   • [         R                  U 5        U R                  5       $ r'   )rÕ  rÿ  rõ  r,   s    r.   rÿ  Ú OurServerBatchFileTests.tearDown?  s   € Ü×#Ñ# DÔ)Ø�‰Ó Ð r1   c                 óâ  ^• U R                  5       m[        TS5       nUR                  U5        S S S 5        U R                  R	                  5       R
                  nSUT4-  n[        R                  " UR                  5       SS9SS  n[        R                  " S[        R                   SU 35        [        R                  R                  5       n[        R                   R#                  [        R$                  5      US'   SU R                  R&                  l        [+        [        R                  XES	9nU4S
 jnUR-                  S 5        UR/                  U5        U$ ! , (       d  f       GN6= f)Nr‚  zˆ-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  r«   r  rF  r  r  c                 ó4   >• [         R                  " T5        U $ r'   )rX   rý  )ÚresÚfns    €r.   Ú_cleanupÚ9OurServerBatchFileTests._getBatchOutput.<locals>._cleanupZ  s   ø€ Ü�IŠI�bŒMØˆJr1   c                 ó   • U S   $ )Nr   rJ   )rÀ  s    r.   r’  Ú9OurServerBatchFileTests._getBatchOutput.<locals>.<lambda>^  s   €  # a¢&r1   )r?  r@  rÀ   rç  r  r  r   r  rL  r   r©  rî   rï   rX   rY   r  r  rg  r    rð  rò  r   rñ   ÚaddBoth)	r-   rÞ  Úfpr  r  r  ró   rÂ  rÁ  s	           @r.   Ú_getBatchOutputÚ'OurServerBatchFileTests._getBatchOutputC  s  ø€ Ø�[‰[‹]ˆÜ�"�cŒ]˜bØ�H‰H�QŒK÷ à�{‰{×"Ñ"Ó$×)Ñ)ˆð!ð �2ˆJñˆô ×#Ò# D§J¡J£L°fÑ=¸a¸bÐAˆÜ�Š�(œ3Ÿ>™>Ð*¨!¨D¨6Ð2Ô3Ü�j‰j�o‰oÓˆÜŸJ™JŸO™O¬C¯H©HÓ5ˆˆLÑà56ˆ�‰×ÑÔ2ä$¤S§^¡^°TÑCˆõ	ð 	
�‰Ñ(Ô)Ø	�	‰	�(Ôàˆ÷9 Ž]ús   žEÅ
E.c                 ó\   ^ • SnU 4S jnT R                  U5      nUR                  U5        U$ )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                 ó  >• U R                  S5      n [        R                  " S[        U 5      -  5        TR	                  TR
                  R                  5       R                  U S   5        TR                  U SS / SQ5        g )Nr¨  zRES %sr«   r.  éþÿÿÿrD  )	rL  r   r©  ÚreprÚassertInrŽ  r}  r    r=   ©rÀ  r-   s    €r.   Ú_cbCheckResultÚ=OurServerBatchFileTests.testBatchFile.<locals>._cbCheckResultm  se   ø€ Ø—)‘)˜EÓ"ˆCÜ�GŠG�Hœt C›yÑ(Ô)Ø�M‰M˜$Ÿ,™,×2Ñ2Ó4×9Ñ9¸3¸q¹6ÔBØ×ÑØ�A�b�	ÚVõr1   ©rÈ  rñ   ©r-   r  rÐ  ró   s   `   r.   ÚtestBatchFileÚ%OurServerBatchFileTests.testBatchFilec  s2   ø€ ð
ˆõ
	ð × Ñ  Ó&ˆØ	�‰�nÔ%Øˆr1   c                 ó\   ^ • SnU 4S jnT R                  U5      nUR                  U5        U$ )z?
Test that an error in the batch file stops running the batch.
zchown 0 missingFile
pwd
exit
c                 ón   >• TR                  TR                  R                  5       R                  U 5        g r'   )ÚassertNotInrŽ  r}  r    rÏ  s    €r.   rÐ  Ú9OurServerBatchFileTests.testError.<locals>._cbCheckResultƒ  s&   ø€ Ø×Ñ˜TŸ\™\×5Ñ5Ó7×<Ñ<¸cÕBr1   rÒ  rÓ  s   `   r.   Ú	testErrorÚ!OurServerBatchFileTests.testErrorz  s3   ø€ ðˆõ
	Cð × Ñ  Ó&ˆØ	�‰�nÔ%Øˆr1   c                 ó\   ^ • SnU 4S jnT R                  U5      nUR                  U5        U$ )zG
Test that a minus sign '-' at the front of a line ignores
any errors.
z-chown 0 missingFile
pwd
exit
c                 ón   >• TR                  TR                  R                  5       R                  U 5        g r'   )rÎ  rŽ  r}  r    rÏ  s    €r.   rÐ  Ú@OurServerBatchFileTests.testIgnoredError.<locals>._cbCheckResult”  s$   ø€ Ø�M‰M˜$Ÿ,™,×2Ñ2Ó4×9Ñ9¸3Õ?r1   rÒ  rÓ  s   `   r.   ÚtestIgnoredErrorÚ(OurServerBatchFileTests.testIgnoredErrorŠ  s3   ø€ ð
ˆõ
	@ð × Ñ  Ó&ˆØ	�‰�nÔ%Øˆr1   rJ   N)rD   rE   rF   rG   rH   r/   rÿ  rÈ  rÔ  rÚ  rß  rI   rJ   r1   r.   r¸  r¸  4  s&   † ñò
ò!òò@ò.õ r1   r¸  Ússhz$no ssh command-line client availableÚsftpz%no sftp command-line client availablec                   ó*   • \ rS rSrSrS rS rS rSrg)ÚOurServerSftpClientTestsiœ  z8
Test the sftp server against sftp command line client.
c                 óL   • [         R                  U 5        U R                  5       $ r'   rº  r,   s    r.   r/   ÚOurServerSftpClientTests.setUp¤  s   € Ü× Ñ  Ô&Ø×ÑÓ!Ð!r1   c                 ó"   • U R                  5       $ r'   )rõ  r,   s    r.   rÿ  Ú!OurServerSftpClientTests.tearDown¨  s   € Ø�‰Ó Ð r1   c                 ó  ^ ^	• [        [        R                  5      nT R                  5       n[	        US5       nUR                  S5        SSS5        T R                  R                  5       R                  n[        R                  m	U	4S jnT R                  [        SU5        ST R                  R                  l        SSS	S
S	SS	SS	SS	SU4-  SUS4nU 4S jn[        SXa5      nUR                  U5      $ ! , (       d  f       N²= f)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                 ó"   >• T" X5      nSUS'   U$ )Nré   Úext_foorJ   )r-   Úsr¶   Ú
oldGetAttrs      €r.   Ú	_getAttrsÚCOurServerSftpClientTests.test_extendedAttributes.<locals>._getAttrs¾  s   ø€ Ù˜tÓ'ˆEØ$ˆE�)ÑØˆLr1   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                 ó�   >• TR                  U S   SU S   R                  S5      5        S H  nTR                  XS   5        M     g )NrJ  r   r«   ÚasciirD  )r=   rK  rÎ  )r#  Úir-   s     €r.   r–  Ú?OurServerSftpClientTests.test_extendedAttributes.<locals>.checkÛ  sF   ø€ Ø×Ñ˜V A™Y¨¨6°!©9×+;Ñ+;¸GÓ+DÔEó�ð —‘˜a¨¡Ö+òr1   râ  )ÚdictrX   rY   r?  r@  rÀ   rç  r  r  r"   rî  r]   rð  rò  r   rñ   )
r-   r  rÁ  rÞ  r  rî  Úargsr–  ró   rí  s
   `        @r.   Útest_extendedAttributesÚ0OurServerSftpClientTests.test_extendedAttributes«  sï   ù€ ô ”2—:‘:Óˆà�[‰[‹]ˆÜ�"�cŒ]˜aØ�G‰G�LÔ!÷ à�{‰{×"Ñ"Ó$×)Ñ)ˆä.×8Ñ8ˆ
õ	ð
 	�
‰
Ô,¨k¸9ÔEØ59ˆ�‰×ÑÔ2ð ØØØ ØØ#ØØ(ØØ'ØØ˜˜ÑØØØ ð
ˆõ$	,ô % V¨TÓ7ˆØ�}‰}˜UÓ#Ð#÷] �]ús   ¸C6Ã6
DrJ   N)	rD   rE   rF   rG   rH   r/   rÿ  rö  rI   rJ   r1   r.   rä  rä  œ  s   † ñò"ò!õ;$r1   rä  )QrH   rë   r�   r_   rX   r  rî   rU   Ú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$   rL   r�   rš   r©   rº   rÙ   r‹  ÚProcessProtocolrš  rÕ  r  r¸  rä  rJ   r1   r.   Ú<module>r     s:  ðñ
ó Û Û Û 	Û Û 
Û ß %Ý å &å Ý .ß UÝ ß HÕ HÝ 'Ý 4Ý ;Ý Ý /Ý ,Ý *Ý 0Ý +á˜^Ó,€ÙÐ)Ó*€æð	Ý.Ý9Ý2ÝEß;Ý;ÝRð €	ØˆD�, 
× :Ò :¸7ÀDÓ IÐJÓJØ€Iñ ˆ	Ð?Ó@ô$
�hó $
ó Að$
ôN_
�8ô _
ôD˜ô ÷ #.ñ #.÷L9ñ 9ñ6 ˆ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   Â),G? Ç?H	ÈH	