Ë
    oj?É  ã                   óü  — d Z ddlZddlZddlZddlZddlZddlZddlZddlm	Z	m
Z
 ddlmZ ddlmZ ddlmZ ddlmZ ddlmZmZ dd	lmZ dd
lmZmZmZmZmZ ddlmZ ddl m!Z! ddl"m#Z#m$Z$ ddl%m&Z& ddl'm(Z( ddl)m*Z* ddl+m,Z, ddl-m.Z. ddl/m0Z0  e.d«      Z1 e.d«      Z2e1r-	 ddl3m4Z4 ddl5m6Z6 ddl7m8Z8 ddl9m:Z: ddl;m<Z<m=Z= ddl>m?Z? ddlm@Z@ dZBde2e1 ej†                  ed«      fv rdZB eeBd«       G d „ d!e0«      «       ZD G d"„ d#e0«      ZE G d$„ d%e!«      ZF G d&„ d'«      ZG G d(„ d)«      ZH ee«       G d*„ d+e	«      «       ZI eeBd«       G d,„ d-e0«      «       ZJ G d.„ d/«      ZK G d0„ d1ej˜                  «      ZM G d2„ d3e«      ZN eeBd«       G d4„ d5eN«      «       ZO eeBd«       G d6„ d7eN«      «       ZP eeBd«       e e,d8«       d9«       e e,d:«       d;«       G d<„ d=eN«      «       «       «       ZQy# eA$ r Y �Œ(w xY w)>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ÚgetProcessValue)Ú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                   ó(   — e Zd ZdZdd„Zdd„Zdd„Zy)ÚSSHSessionTestsz=
    Tests for L{twisted.conch.scripts.cftp.SSHSession}.
    Nc                 óþ   — t        «       | _        t        «       | _        | j                  | j                  _        t	        «       | _        t        | j
                  «      | _        | j                  | j                  _        y ©N)r"   Ústdior   Úchannelr   ÚstderrBufferr   Ústderr©Úselfs    ú>/usr/lib/python3/dist-packages/twisted/conch/test/test_cftp.pyÚsetUpzSSHSessionTests.setUp>   sP   € Ü“[ˆŒ
Ü!“|ˆŒØ!ŸZ™Zˆ�‰ÔÜ#›IˆÔÜ# D×$5Ñ$5Ó6ˆŒØ"Ÿk™kˆ�‰Õó    c                 ó‚   — | j                   j                  «        | j                  | j                  j                  «       y)z|
        L{twisted.conch.scripts.cftp.SSHSession.eofReceived} loses the write
        half of its stdio connection.
        N)r)   ÚeofReceivedÚ
assertTruer(   ÚwriteConnLostr,   s    r.   Útest_eofReceivedz SSHSessionTests.test_eofReceivedF   s*   € ð
 	�‰× Ñ Ô"Ø�‰˜Ÿ
™
×0Ñ0Õ1r0   c                 óÊ   — d}|j                  d«      }| j                  j                  t        |dz   «       | j	                  | j
                  j                  «       |dz   «       y)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_extReceivedStderrz&SSHSessionTests.test_extReceivedStderrN   s`   € ð "ˆ	Ø×%Ñ% gÓ.ˆ
Ø�‰× Ñ Ü Ø˜Ñ ô	
ð 	×ÑØ×Ñ×&Ñ&Ó(Ø˜Ñ!õ	
r0   )ÚreturnN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r/   r5   r?   © r0   r.   r%   r%   8   s   „ ñó*ó2ô
r0   r%   c                   óz  — e Zd ZdZ eedd«      €dZd„ Zd„ Zd„ Z	d„ Z
d	„ Z ej                  «       Z	 	  ej                  ej                   d
«       dZ ej                  ej                   e«        eed«      d„ «       Zd„ Zy# ej$                  $ r dZY ŒCw xY w#  ej                  ej                   e«       w xY w)ÚListingTestszƒ
    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                 óZ  ‡ — d‰ _         ˆ fd„}‰ j                  t        d|«       dt        j                  v ra‰ j                  t        j                  t        j                  dt        j                  d   «       ‰ j                  t        j                  «       yd„ }‰ j                  |«       y)zo
        Patch the L{ls} module's time function so the results of L{lsLine} are
        deterministic.
        iÍ[c                  ó   •— ‰ j                   S r'   )Únowr,   s   €r.   ÚfakeTimez$ListingTests.setUp.<locals>.fakeTimep   s   ø€ Ø—8‘8ˆOr0   ÚtimeÚTZc                  ón   — 	 t         j                  d= t        j                  «        y # t        $ r Y Œ w xY w)NrN   )ÚosÚenvironÚKeyErrorrM   rH   rE   r0   r.   Úcleanupz#ListingTests.setUp.<locals>.cleanup|   s2   € ðÜŸ
™
 4Ð(ô —
‘
•øô  ò Ùðús   ‚( ¨	4³4N)
rK   Úpatchr   rP   rQ   Ú
addCleanupÚoperatorÚsetitemrM   rH   )r-   rL   rS   s   `  r.   r/   zListingTests.setUpi   sy   ø€ ð
 ˆŒô	ð 	�
‰
”2�v˜xÔ(ð ”2—:‘:ÑØ�O‰OœH×,Ñ,¬b¯j©j¸$ÄÇ
Á
È4Ñ@PÔQØ�O‰OœDŸJ™JÕ'òð �O‰O˜GÕ$r0   c                 ó|   — |t         j                  d<   t        j                  «        t	        j
                  d|«      S )zl
        Call L{ls.lsLine} after setting the timezone to C{timezone} and return
        the result.
        rN   Úfoo)rP   rQ   rM   rH   r   ÚlsLine)r-   ÚtimezoneÚstats      r.   Ú_lsInTimezonezListingTests._lsInTimezone†   s,   € ð $Œ�
‰
�4ÑÜ�
‰
ŒÜ�y‰y˜ Ó%Ð%r0   c                 óè   — | j                   dz
  }t        j                  dddddddd|df
«      }| j                  | j	                  d|«      d«       | j                  | j	                  d|«      d«       y)z‘
        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©rK   rP   Ústat_resultr;   r]   ©r-   Úthenr\   s      r.   Útest_oldFilezListingTests.test_oldFile‘   ó|   € ð �x‰xÐ0Ñ1ˆÜ�~‰~˜q ! Q¨¨1¨a°°A°t¸QÐ?Ó@ˆà×ÑØ×ÑÐ1°4Ó8ØIô	
ð 	×ÑØ×ÑÐ1°4Ó8ØIõ	
r0   c                 óî   — | j                   dz
  dz   }t        j                  dddddddd|df
«      }| j                  | j	                  d|«      d«       | j                  | j	                  d|«      d«       y)	úæ
        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.
        r_   i€— r   r`   z;!---------    0 0        0               0 May 01  1973 foora   z;!---------    0 0        0               0 May 02  1973 fooNrb   rd   s      r.   Útest_oldSingleDigitDayOfMonthz*ListingTests.test_oldSingleDigitDayOfMonth£   ó‚   € ð �x‰xÐ0Ñ1Ð5EÑFˆÜ�~‰~˜q ! Q¨¨1¨a°°A°t¸QÐ?Ó@ˆà×ÑØ×ÑÐ1°4Ó8ØIô	
ð 	×ÑØ×ÑÐ1°4Ó8ØIõ	
r0   c                 óè   — | j                   dz
  }t        j                  dddddddd|df
«      }| j                  | j	                  d|«      d«       | j                  | j	                  d|«      d«       y)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   r`   ú;!---------    0 0        0               0 Aug 28 17:33 foora   ú;!---------    0 0        0               0 Aug 29 09:33 fooNrb   rd   s      r.   Útest_newFilezListingTests.test_newFile·   rg   r0   ú
es_AR.UTF8FTz'The es_AR.UTF8 locale is not installed.c                 ó¶  — | j                   dz
  }t        j                  dddddddd|df
«      }t        j                  «       }t        j
                  t        j                  d«       | j                  t        j
                  t        j                  |«       | j                  | j                  d|«      d«       | j                  | j                  d|«      d«       y)	zC
        The month name in the date is locale independent.
        rm   r   rq   r`   rn   ra   ro   N)
rK   rP   rc   ÚlocaleÚ	getlocaleÚ	setlocaleÚLC_ALLrU   r;   r]   )r-   re   r\   ÚcurrentLocales       r.   Útest_localeIndependentz#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õ	
r0   c                 óî   — | j                   dz
  dz   }t        j                  dddddddd|df
«      }| j                  | j	                  d|«      d«       | j                  | j	                  d|«      d«       y)	ri   rm   i F r   r`   z;!---------    0 0        0               0 Sep 01 17:33 foora   z;!---------    0 0        0               0 Sep 02 09:33 fooNrb   rd   s      r.   Útest_newSingleDigitDayOfMonthz*ListingTests.test_newSingleDigitDayOfMonthí   rk   r0   )rA   rB   rC   rD   ÚgetattrrM   Úskipr/   r]   rf   rj   rp   rs   rt   rw   ru   rv   Ú
localeSkipÚErrorr   rx   rz   rE   r0   r.   rG   rG   `   sØ   „ ññ
 ˆt�W˜dÓ#Ð+ØIˆò%ò:	&ò
ò$
ò(
ð( %�F×$Ñ$Ó&€Mð7ð	ØˆF×Ñ˜VŸ]™]¨LÔ9ð ˆJàˆ×Ñ˜Ÿ™¨Ô6áˆJÐAÓBñ
ó Cð
ó,
øð= �|‰|ò 	ØŠJð	ûð
 	ˆ×Ñ˜Ÿ™¨Õ6ús)   µB ÁB ÂBÂB ÂBÂB ÂB:rG   c                   ó"   ‡ — e Zd ZdZˆ fd„Zˆ xZS )ÚInMemorySSHChannelzp
    Minimal implementation of a L{SSHChannel} like class which only reads and
    writes data from memory.
    c                 ó>   •— || _         d| _        t        ‰| �  «        y)zt
        @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…   zInMemorySSHChannel.__init__  s   ø€ ð
 ˆŒ	ØˆÔÜ‰ÑÕr0   )rA   rB   rC   rD   r…   Ú__classcell__)r†   s   @r.   r€   r€     s   ø„ ñ÷
ð r0   r€   c                   ó"   — e Zd ZdZd„ Zd„ Zd„ Zy)ÚFilesystemAccessExpectationszC
    A test helper used to support expected filesystem access.
    c                 ó   — i | _         y r'   ©Ú_cacher,   s    r.   r…   z%FilesystemAccessExpectations.__init__  s	   € Øˆ�r0   c                 ó&   — || j                   ||f<   y)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.   Úputz FilesystemAccessExpectations.put  s   € ð &,ˆ�‰�T˜5�MÒ"r0   c                 ó<   — | j                   j                  ||f«      S )a  
        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“   z FilesystemAccessExpectations.pop(  s   € ð �{‰{�‰  e˜}Ó-Ð-r0   N)rA   rB   rC   rD   r…   r‘   r“   rE   r0   r.   r‰   r‰     s   „ ñòò,ó.r0   r‰   c                   ó   — e Zd ZdZd„ Zd„ Zy)ÚInMemorySFTPClienta'  
    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                 óF   — t        | «      | _        dddœ| _        || _        y )Né   é
   )ÚrequestsÚ
buffersize)r€   Ú	transportÚoptionsÚ_availableFiles)r-   ÚavailableFiless     r.   r…   zInMemorySFTPClient.__init__B  s'   € Ü+¨DÓ1ˆŒàØñ
ˆŒð  .ˆÕr0   c                 ó:   — | j                   j                  ||«      S )z}
        @see: L{filetransfer.FileTransferClient.openFile}.

        Retrieve and remove cached file based on flags.
        )r�   r“   )r-   Úfilenamer�   Úattrss       r.   ÚopenFilezInMemorySFTPClient.openFileJ  s   € ð ×#Ñ#×'Ñ'¨°%Ó8Ð8r0   N)rA   rB   rC   rD   r…   r¢   rE   r0   r.   r•   r•   8  s   „ ñò.ó9r0   r•   c                   ó:   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	d„ Z
y	)
ÚInMemoryRemoteFilez;
    An L{ISFTPFile} which handles all data in memory.
    c                 ó<   — || _         t        j                  | «       y)zL
        @param name: Name of this file.
        @type name: L{str}
        N)Únamer   r…   )r-   r¦   s     r.   r…   zInMemoryRemoteFile.__init__Y  s   € ð
 ˆŒ	Ü×Ñ˜Õr0   c                 óp   — | j                  |«       | j                  |«       t        j                  | «      S )z/
        @see: L{ISFTPFile.writeChunk}
        )ÚseekÚwriter   Úsucceed)r-   ÚstartÚdatas      r.   Ú
writeChunkzInMemoryRemoteFile.writeChunka  s+   € ð 	�	‰	�%ÔØ�
‰
�4ÔÜ�}‰}˜TÓ"Ð"r0   c                 ó   — d| _         y)zo
        @see: L{ISFTPFile.writeChunk}

        Keeps data after file was closed to help with testing.
        TN)Ú_closedr,   s    r.   ÚclosezInMemoryRemoteFile.closei  s   € ð ˆ�r0   c                  ó   — y r'   rE   r,   s    r.   ÚgetAttrszInMemoryRemoteFile.getAttrsq  ó   € àr0   c                  ó   — y r'   rE   )r-   ÚoffsetÚlengths      r.   Ú	readChunkzInMemoryRemoteFile.readChunku  r³   r0   c                  ó   — y r'   rE   )r-   r¡   s     r.   ÚsetAttrszInMemoryRemoteFile.setAttrsy  r³   r0   c                 ó,   — t        j                  | «      S )zb
        Get current data of file.

        Allow reading data event when file is closed.
        )r   r<   r,   s    r.   r<   zInMemoryRemoteFile.getvalue}  s   € ô ×Ñ Ó%Ð%r0   N)rA   rB   rC   rD   r…   r­   r°   r²   r·   r¹   r<   rE   r0   r.   r¤   r¤   S  s*   „ ñòò#òòòòó&r0   r¤   c                   ó€   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	d„ Z
d	„ Zd
„ Zd„ Zd„ Zd„ Zdd„Zdd„Zd„ Zd„ Zd„ Zd„ Zy)ÚStdioClientTestsz(
    Tests for L{cftp.StdioClient}.
    c                 ód  — t        «       | _        t        | j                  «      }t        j                  |«      | _        d| j
                  _        t        «       x| _        | j
                  _	        | j                  dd«       | j
                  j
                  j                  | j
                  _        y)zm
        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/   zStdioClientTests.setUpŒ  s‚   € ô
 ;Ó<ˆÔÜ'¨×(;Ñ(;Ó<ˆ
Ü×&Ñ& zÓ2ˆŒØ'*ˆ�‰Ô$Ü+7«>Ð9ˆŒ˜Ÿ™Ô(ð
 	× Ñ   bÔ)ð !%§¡× 2Ñ 2× <Ñ <ˆ�‰Õr0   c           	      ó  — | j                   j                  t        j                  «       dt	        j
                  «       dddt        j                  «       | j                  j                  d«      }|j                  | j                  d«       |S )zs
        The I{exec} command runs its arguments locally in a child process
        using the user's shell.
        ÚsecretéÒ  rY   Úbarzexec print(1 + 2)s   3
)rÄ   ÚaddUserÚgetpassÚgetuserrP   ÚgetuidÚsysÚ
executablerÂ   Ú_dispatchCommandÚaddCallbackr;   ©r-   Úds     r.   Ú	test_execzStdioClientTests.test_execŸ  sf   € ð
 	�‰×ÑÜ�O‰OÓ˜x¬¯©«°d¸EÀ5Ì#Ï.É.ô	
ð �K‰K×(Ñ(Ð)<Ó=ˆØ	�‰�d×&Ñ&¨Ô/Øˆr0   c           	      óþ   — | j                   j                  t        j                  «       dt	        j
                  «       dddd«       | j                  j                  d«      }|j                  | j                  d«       |S )zr
        If the local user has no shell, the I{exec} command runs its arguments
        using I{/bin/sh}.
        rÉ   rÊ   rY   rË   Ú zexec echo helloó   hello
©
rÄ   rÌ   rÍ   rÎ   rP   rÏ   rÂ   rÒ   rÓ   r;   rÔ   s     r.   Útest_execWithoutShellz&StdioClientTests.test_execWithoutShell¬  sb   € ð
 	�‰×ÑÜ�O‰OÓ˜x¬¯©«°d¸EÀ5È"ô	
ð �K‰K×(Ñ(Ð):Ó;ˆØ	�‰�d×&Ñ&¨
Ô3Øˆr0   c           	      óþ   — | j                   j                  t        j                  «       dt	        j
                  «       dddd«       | j                  j                  d«      }|j                  | j                  d«       |S )zO
        The I{exec} command is run for lines which start with C{"!"}.
        rÉ   rÊ   rY   rË   z/bin/shz!echo hellorÙ   rÚ   rÔ   s     r.   Ú	test_bangzStdioClientTests.test_bang¹  sa   € ð 	�‰×ÑÜ�O‰OÓ˜x¬¯©«°d¸EÀ5È)ô	
ð �K‰K×(Ñ(¨Ó7ˆØ	�‰�d×&Ñ&¨
Ô3Øˆr0   c                 óf   ‡‡‡— ddl Š G ˆˆˆfd„d«      }| j                  t        d |«       «       y)a  
        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                   ó   •— e Zd Zˆ ˆˆfd„Zy)ú7StdioClientTests.setKnownConsoleSize.<locals>.FakeFcntlc                 óv   •— |‰j                   k7  r| j                  d«       t        j                  d‰‰dd«      S )Nz#Only window-size queries supported.Ú4Hr   )Ú
TIOCGWINSZÚfailÚstructÚpack)r-   ÚfdÚoptÚmutateÚheightÚttyÚwidths       €€€r.   Úioctlz=StdioClientTests.setKnownConsoleSize.<locals>.FakeFcntl.ioctlÓ  s3   ø€ Ø˜#Ÿ.™.Ò(Ø—I‘IÐCÔDÜ—{‘{ 4¨°¸¸1Ó=Ð=r0   N)rA   rB   rC   rí   )rê   rë   rì   s   €€€r.   Ú	FakeFcntlrà   Ò  s   ø„ ÷>r0   rî   Úfcntl)rë   rT   r   )r-   rì   rê   rî   rë   s    `` @r.   rÆ   z$StdioClientTests.setKnownConsoleSizeÅ  s&   ú€ ó 	÷	>õ 	>ð 	�
‰
”4˜¡)£+Õ.r0   c                 óÊ  — | j                  dd«       t        «       x}| j                  _        t	        d«      }d|_        t        j                  |«      }d|_        |j                  «       }|j                  d«       |xj                  dz  c_        | j                  j                  ||«       d}| j                  | j                  j                  j                  «       |«       y	)
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_printProgressBarReportingz/StdioClientTests.test_printProgressBarReportingÚ  s¯   € ð 	× Ñ   RÔ(Ü&+£gÐ-ˆ�—‘Ô#Ü˜$“-ˆØ ˆŒÜ×"Ñ" 7Ó+ˆØ ˆŒØ—M‘M“Oˆ	Ø�‰�cÔØ�Š˜Ñ�à�‰×%Ñ% g¨yÔ9à8ˆØ×Ñ˜Ÿ™×.Ñ.×4Ñ4Ó6¸Õ?r0   c                 óp  — | j                  dd«       t        «       x}| j                  _        t	        d«      }d|_        t        j                  |«      }|j                  «       }| j                  j                  ||«       d}| j                  | j                  j                  j                  «       |«       y)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_printProgressBarNoProgressz0StdioClientTests.test_printProgressBarNoProgressò  sŽ   € ð 	× Ñ   RÔ(Ü&+£gÐ-ˆ�—‘Ô#Ü˜$“-ˆØ ˆŒÜ×"Ñ" 7Ó+ˆØ—M‘M“Oˆ	à�‰×%Ñ% g¨yÔ9à6ˆØ×Ñ˜Ÿ™×.Ñ.×4Ñ4Ó6¸Õ?r0   c                 ó  — | j                  dd«       t        «       }d|_        t        j                  |«      }| j
                  j                  |d«       d}| j                  || j
                  j                  j                  «       «       y)z5
        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_printProgressBarEmptyFilez/StdioClientTests.test_printProgressBarEmptyFile  sn   € ð 	× Ñ   RÔ(Ü“)ˆØ$ˆŒÜ×"Ñ" 7Ó+ˆà�‰×%Ñ% g¨qÔ1à:ˆØ×Ñ˜ §¡×!6Ñ!6×!<Ñ!<Ó!>Õ?r0   c                 ó^   — | j                   j                  d«      }| j                  d|«       y)zK
        Returns empty value for both filename and remaining data.
        z  )rØ   rØ   N©rÂ   Ú_getFilenamer;   ©r-   r   s     r.   Útest_getFilenameEmptyz&StdioClientTests.test_getFilenameEmpty  s(   € ð —‘×)Ñ)¨$Ó/ˆà×Ñ˜ 6Õ*r0   c                 ó^   — | j                   j                  d«      }| j                  d|«       y)zd
        Returns empty value for remaining data when line contains
        only a filename.
        ú
only-local)r  rØ   Nr  r	  s     r.   Útest_getFilenameOnlyLocalz*StdioClientTests.test_getFilenameOnlyLocal  s)   € ð
 —‘×)Ñ)¨,Ó7ˆà×ÑÐ+¨VÕ4r0   c                 ó^   — | j                   j                  d«      }| j                  d|«       y)ze
        Returns filename and remaining data striped of leading and trailing
        spaces.
        z local  remote file  )Úlocalzremote fileNr  r	  s     r.   Útest_getFilenameNotQuotedz*StdioClientTests.test_getFilenameNotQuoted#  s*   € ð
 —‘×)Ñ)Ð*AÓBˆà×ÑÐ1°6Õ:r0   c                 ó^   — | j                   j                  d«      }| j                  d|«       y)z‰
        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_getFilenameQuotedz'StdioClientTests.test_getFilenameQuoted,  s*   € ð
 —‘×)Ñ)Ð*NÓOˆà×ÑÐ=¸vÕFr0   Nc                 ó�   — |€| j                  «       }t        |d«      5 }|j                  |«       ddd«       |S # 1 sw Y   |S xY w)ab  
        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.   ÚmakeFilezStdioClientTests.makeFile5  sF   € ð ˆ<Ø—;‘;“=ˆDÜ�$˜Óð 	  Ø�J‰J�wÔ÷	 àˆ÷	 àˆús	   Ÿ;»Ac                 óö  — | j                   j                  j                  «       }|j                  d«      }|j	                  d«      }g }g }|D �]T  \  }}}g }	|D ]  }
|	j                  |› d|
› �«       Œ |	j                  d|› d|› �«       |j                  |	«       |j                  d«      j                  d«      j	                  d«      }|dd	 }|d	   j                  d
«      j	                  d
«      }|j                  |«       g }|dd	 D ]o  }
|
j                  «       j                  dd«      d   }
|
j                  «       j	                  dd«      }
|j                  |
d   › d|
d   j                  «       › �«       Œq |j                  |d	   «       |j                  |«       �ŒW |r%| j                  t        |«      t        |«      «       n| j                  ||«       | j                  dt        |«      d«       y)a  
        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

        r7   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ÚactualOutputr  ÚremoteÚexpectedÚexpectedTransferÚlineÚprogressPartsÚactualÚlastÚactualTransfers                  r.   ÚcheckPutMessagez StdioClientTests.checkPutMessageI  sù  € ð —‘×&Ñ&×,Ñ,Ó.ˆØ—‘˜wÓ'ˆØ—‘˜fÓ%ˆàˆØˆà'0ó 	0Ñ#ˆE�6˜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 ˜ò F�ð —z‘z“|×*Ñ*¨3°Ó2°1Ñ5�ð —z‘z“|×)Ñ)¨#¨qÓ1�Ø×%Ñ%¨¨a©¨	°°4¸±7·=±=³?Ð2CÐ&DÕEðFð ×!Ñ! &¨¡*Ô-Ø×Ñ Ö/ð?	0ñB Ø×ÑœV NÓ3´V¸LÓ5IÕJà×Ñ˜^¨\Ô:à×ÑØÜ�‹KØCõ	
r0   c                 óÂ  — d}| j                  |¬«      }t        j                  t        j                  z  t        j                  z  }t
        j                  j                  dt
        j                  j                  |«      «      }t        |«      }| j                  j                  ||t        j                  |«      «       d| j                  j                  j                  d<   | j                  j!                  |«      }| j#                  |«       | j%                  ||j'                  «       «       | j)                  |j*                  «       | j-                  ||g d¢fg«       y)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)r  r¾   r˜   rš   )z	76% 10.0Bú
100% 13.0Br7  N)r  r   Ú	FXF_WRITEÚ	FXF_CREATÚ	FXF_TRUNCrP   rŽ   ÚjoinÚbasenamer¤   rÀ   r‘   r   rª   rÂ   rœ   Úcmd_PUTÚsuccessResultOfr;   r<   r3   r¯   r5  )r-   r  Ú	localPathr�   Ú
remoteNameÚ
remoteFileÚdeferreds          r.   Útest_cmd_PUTSingleNoRemotePathz/StdioClientTests.test_cmd_PUTSingleNoRemotePath†  s  € ð %ˆØ—M‘M¨'�MÓ2ˆ	Ü×&Ñ&¬×)?Ñ)?Ñ?Ä,×BXÑBXÑXˆÜ—W‘W—\‘\ #¤r§w¡w×'7Ñ'7¸	Ó'BÓCˆ
Ü'¨
Ó3ˆ
Ø×Ñ×Ñ 
¨E´5·=±=ÀÓ3LÔMØ35ˆ�‰×Ñ×"Ñ" <Ñ0à—;‘;×&Ñ& yÓ1ˆØ×Ñ˜XÔ&à×Ñ˜ *×"5Ñ"5Ó"7Ô8Ø�‰˜
×*Ñ*Ô+Ø×ÑØ˜Ò%NÐOÐPõ	
r0   c                 ó  — | j                  «       }t        j                  t        j                  z  t        j                  z  }d}t        |«      }| j                  j                  ||t        j                  |«      «       | j                  j                  |› d|› d�«      }| j                  |«       | j                  ||dgfg«       | j                  |j                  «       | j!                  d|j#                  «       «       y)z€
        Remote path is extracted from first filename after local file.

        Any other data in the line is ignored.
        z/remote-pathr  z ignoredú	100% 0.0Br0   N)r  r   r8  r9  r:  r¤   rÀ   r‘   r   rª   rÂ   r=  r>  r5  r3   r¯   r;   r<   )r-   r?  r�   r@  rA  rB  s         r.   Útest_cmd_PUTSingleRemotePathz-StdioClientTests.test_cmd_PUTSingleRemotePathž  sÔ   € ð —M‘M“Oˆ	Ü×&Ñ&¬×)?Ñ)?Ñ?Ä,×BXÑBXÑXˆØ#ˆ
Ü'¨
Ó3ˆ
Ø×Ñ×Ñ 
¨E´5·=±=ÀÓ3LÔMà—;‘;×&Ñ&¨)¨°A°j°\ÀÐ'JÓKˆØ×Ñ˜XÔ&à×Ñ˜y¨*°{°mÐDÐEÔFØ�‰˜
×*Ñ*Ô+Ø×Ñ˜˜j×1Ñ1Ó3Õ4r0   c                 ó"  — | j                  «       }t        j                  j                  |«      }d}t        j                  j	                  |«      }| j                  t        j                  j                  ||«      ¬«      }t        j                  t        j                  z  t        j                  z  }d|› �}d|› �}t        |«      }	t        |«      }
| j                  j                  ||t        j                  |	«      «       | j                  j                  ||t        j                  |
«      «       | j                  j!                  t        j                  j                  |d«      «      }| j#                  |«       | j%                  |	j&                  «       | j)                  d|	j+                  «       «       | j%                  |
j&                  «       | j)                  d|
j+                  «       «       | j-                  ||dgf||dgfgd¬«       y	)
z„
        When a gobbing expression is used local files are transferred with
        remote file names based on local names.
        úsecond-name©rŽ   r¾   Ú*r0   rE  T©r)  N)r  rP   rŽ   r<  Údirnamer;  r   r8  r9  r:  r¤   rÀ   r‘   r   rª   rÂ   r=  r>  r3   r¯   r;   r<   r5  )r-   ÚfirstÚ	firstNameÚ
secondNameÚparentÚsecondr�   ÚfirstRemotePathÚsecondRemotePathÚfirstRemoteFileÚsecondRemoteFilerB  s               r.   Ú test_cmd_PUTMultipleNoRemotePathz1StdioClientTests.test_cmd_PUTMultipleNoRemotePath±  s¯  € ð
 —‘“ˆÜ—G‘G×$Ñ$ UÓ+ˆ	Ø"ˆ
Ü—‘—‘ Ó'ˆØ—‘¤B§G¡G§L¡L°¸Ó$D�ÓEˆÜ×&Ñ&¬×)?Ñ)?Ñ?Ä,×BXÑBXÑXˆØ˜i˜[˜/ˆØ˜z˜lÐ+ÐÜ,¨_Ó=ˆÜ-Ð.>Ó?ÐØ×Ñ×Ñ °¼¿¹ÀoÓ8VÔWØ×Ñ×ÑØ˜e¤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ðð ð 	õ 	
r0   c                 ó@  — | j                  «       }t        j                  j                  |«      }d}t        j                  j	                  |«      }| j                  t        j                  j                  ||«      ¬«      }t        j                  t        j                  z  t        j                  z  }t        |«      }t        |«      }d|› �}	d|› �}
| j                  j                  |	|t        j                  |«      «       | j                  j                  |
|t        j                  |«      «       | j                  j!                  dj#                  t        j                  j                  |d«      «      «      }| j%                  |«       | j'                  |j(                  «       | j+                  d|j-                  «       «       | j'                  |j(                  «       | j+                  d|j-                  «       «       | j/                  ||dgf||dgfgd¬	«       y
)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.
        rH  rI  z/remote/z	{} remoterJ  r0   rE  TrK  N)r  rP   rŽ   r<  rL  r;  r   r8  r9  r:  r¤   rÀ   r‘   r   rª   rÂ   r=  Úformatr>  r3   r¯   r;   r<   r5  )r-   rM  rN  rO  rP  rQ  r�   rT  rU  rR  rS  rB  s               r.   Ú"test_cmd_PUTMultipleWithRemotePathz3StdioClientTests.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Ø×Ñ×ÑØ˜e¤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ðð ð 	õ 	
r0   )Nr0   )F)rA   rB   rC   rD   r/   rÖ   rÛ   rÝ   rÆ   r  r  r  r
  r  r  r  r  r5  rC  rF  rV  rY  rE   r0   r.   r¼   r¼   †  sg   „ ñò=ò&òò
ò/ò*@ò0@ò$@ò+ò5ò;òGóó(;
òz
ò05ò&!
óF#
r0   r¼   c                   ó   — e Zd Zd„ Zd„ Zy)ÚFileTransferTestRealmc                 ó   — || _         y r'   )ÚtestDir)r-   r]  s     r.   r…   zFileTransferTestRealm.__init__û  s	   € Øˆ�r0   c                 ó>   — t        | j                  «      }|d   |d„ fS )Nr   c                   ó   — y r'   rE   rE   r0   r.   ú<lambda>z5FileTransferTestRealm.requestAvatar.<locals>.<lambda>   s   � r0   )r	   r]  )r-   ÚavatarIDÚmindr   Úas        r.   ÚrequestAvatarz#FileTransferTestRealm.requestAvatarþ  s!   € Ü" 4§<¡<Ó0ˆØ˜!‰}˜a¡Ð-Ð-r0   N)rA   rB   rC   r…   rd  rE   r0   r.   r[  r[  ú  s   „ òó.r0   r[  c                   óL   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	d„ Z
d	„ Zd
„ Zd„ Zy)ÚSFTPTestProcessz³
    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                 ó\   — | j                  «        || _        d| _        d| _        d| _        y)zr
        @param onOutReceived: A L{Deferred} to be fired as soon as data is
        received from stdout.
        NF)ÚclearBufferÚonOutReceivedÚonProcessEndÚ_expectingCommandÚ_processEnded)r-   ri  s     r.   r…   zSFTPTestProcess.__init__
  s0   € ð
 	×ÑÔØ*ˆÔØ ˆÔØ!%ˆÔØ"ˆÕr0   c                 ó.   — d| _         g | _        d| _        y)zR
        Clear any buffered data received from stdout. Should be private.
        r0   N)ÚbufferÚ_linesReceivedÚ_lineBufferr,   s    r.   rh  zSFTPTestProcess.clearBuffer  s   € ð ˆŒØ ˆÔØˆÕr0   c                 ó~  — t        j                  d|z  «       | j                  |z   j                  d«      }|j	                  d«      | _        | j
                  j                  |«       | j                  �%| j                  dc}| _        |j                  |«       | xj                  |z  c_	        | j                  «        y)zO
        Called by Twisted when the cftp client prints data to stdout.
        zgot %ró   
r  N)r   Úmsgrp  r!  r“   ro  r$  ri  Úcallbackrn  Ú_checkForCommand)r-   r¬   ÚlinesrÕ   s       r.   ÚoutReceivedzSFTPTestProcess.outReceived  sœ   € ô 	�‰�˜4‘Ô Ø×!Ñ! DÑ(×/Ñ/°Ó6ˆØ Ÿ9™9 R›=ˆÔØ×Ñ×"Ñ" 5Ô)ð ×ÑÐ)Ø$(×$6Ñ$6¸Ð!ˆAˆtÔ!Ø�J‰J�tÔØ�Š�tÑ�Ø×ÑÕr0   c                 ó   — d}| j                   r€| j                  |k(  rpdj                  | j                  «      }|j	                  |«      r|t        |«      d  }| j                  «        | j                   d c}| _         |j                  |«       y y y )Ns   cftp> rr  )rk  rp  r;  ro  Ú
startswithr'  rh  rt  )r-   ÚpromptÚbufrÕ   s       r.   ru  z SFTPTestProcess._checkForCommand.  s‚   € ØˆØ×!Ò! d×&6Ñ&6¸&Ò&@Ø—*‘*˜T×0Ñ0Ó1ˆCØ�~‰~˜fÔ%Øœ#˜f›+˜-Ð(�Ø×ÑÔØ(,×(>Ñ(>ÀÐ%ˆAˆtÔ%Ø�J‰J�s�Oð 'AÐ!r0   c                 ó4   — t        j                  d|z  «       y)zO
        Called by Twisted when the cftp client prints data to stderr.
        zerr: %sN)r   rs  )r-   r¬   s     r.   ÚerrReceivedzSFTPTestProcess.errReceived8  s   € ô 	�‰�	˜DÑ Õ!r0   c                 ó   — | j                   S )zQ
        Return the contents of the buffer of data received from stdout.
        )rn  r,   s    r.   Ú	getBufferzSFTPTestProcess.getBuffer>  s   € ð �{‰{Ðr0   c                 óê   — t        j                  «       | _        | j                  «        t	        |t
        «      r|j                  d«      }| j                  j                  |dz   «       | j                  S )a¬  
        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.
        r7   rr  )	r   ÚDeferredrk  rh  Ú
isinstanceÚstrr9   r›   r©   ©r-   Úcommands     r.   Ú
runCommandzSFTPTestProcess.runCommandD  sY   € ô "'§¡Ó!1ˆÔØ×ÑÔÜ�gœsÔ#Ø—n‘n WÓ-ˆGØ�‰×Ñ˜W u™_Ô-Ø×%Ñ%Ð%r0   c                 ó²   — t        j                  d«      }|D �cg c]  }|j                  | j                  |«      ‘Œ  }}t        j                  |«      S c c}w )ax  
        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.   Ú	runScriptzSFTPTestProcess.runScriptV  sM   € ô ×%Ñ% aÓ(ˆØ?GÖH°Gˆc�g‰g�d—o‘o wÕ/ÐHˆÐHÜ×"Ñ" 2Ó&Ð&ùò Is   š#Ac                 óÄ   — | j                   rt        j                  d«      S t        j                  «       | _        | j
                  j                  d«       | j                  S )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)rl  r   rª   r�  rj  r›   ÚsignalProcessr,   s    r.   ÚkillProcesszSFTPTestProcess.killProcesse  sI   € ð ×ÒÜ—=‘= Ó&Ð&Ü!ŸN™NÓ,ˆÔØ�‰×$Ñ$ VÔ,Ø× Ñ Ð r0   c                 óv   — d| _         | j                  r&| j                  dc}| _        |j                  d«       yy)zF
        Called by Twisted when the cftp client process ends.
        TN)rl  rj  rt  )r-   ÚreasonrÕ   s      r.   ÚprocessEndedzSFTPTestProcess.processEndedt  s;   € ð "ˆÔØ×ÒØ#'×#4Ñ#4°dÐ ˆAˆtÔ Ø�J‰J�tÕð r0   N)rA   rB   rC   rD   r…   rh  rw  ru  r}  r  r†  rŽ  r’  r•  rE   r0   r.   rf  rf    s9   „ ñò	#òò ò"ò"òò&ò$'ò!ór0   rf  c                   ó*   — e Zd Zd„ Zd„ Zd„ Zd„ Zd„ Zy)ÚCFTPClientTestBasec                 óÞ  — t        dd«      5 }|j                  t        j                  «       d d d «       t        dd«      5 }|j                  t        j                  «       d d d «       t        j                  dd«       t        dd«      5 }|j                  dt        j                  z   «       d d d «       t        j                  | «      S # 1 sw Y   ŒŸxY w# 1 sw Y   ŒwxY w# 1 sw Y   Œ6xY w)Núdsa_test.pubr  Údsa_testi€�  Úkh_tests
   127.0.0.1 )
r  r©   r!   ÚpublicDSA_opensshÚprivateDSA_opensshrP   ÚchmodÚpublicRSA_opensshr
   r/   ©r-   Úfs     r.   r/   zCFTPClientTestBase.setUp  sÃ   € Ü�. $Ó'ð 	0¨1Ø�G‰G”H×.Ñ.Ô/÷	0ä�*˜dÓ#ð 	1 qØ�G‰G”H×/Ñ/Ô0÷	1ä
�‰�˜UÔ#Ü�)˜TÓ"ð 	@ aØ�G‰G�M¤H×$>Ñ$>Ñ>Ô?÷	@ä×!Ñ! $Ó'Ð'÷	0ð 	0ú÷	1ð 	1ú÷	@ð 	@ús#   � CÁ CÂ#C#ÃCÃC Ã#C,c                 ó  — t        | j                  «      }t        j                  |«      }|j	                  t        j                  «       «       t        j                  «       }||_        t        j                  d|d¬«      | _
        y )Nr   z	127.0.0.1)Ú	interface)r[  r]  r   ÚPortalÚregisterCheckerr!   ÚconchTestPublicKeyCheckerÚConchTestServerFactoryr   Ú	listenTCPÚserver)r-   ÚrealmÚpÚfacs       r.   ÚstartServerzCFTPClientTestBase.startServer‰  s`   € Ü% d§l¡lÓ3ˆÜ�M‰M˜%Ó ˆØ	×Ñœ(×<Ñ<Ó>Ô?Ü×-Ñ-Ó/ˆØˆŒ
Ü×'Ñ'¨¨3¸+ÔFˆ�r0   c                 óv  — t        | j                  j                  d«      s| j                  d «      S d| j                  j                  j                  _        t        j                  | j                  j                  j                  j                  j                  «      }|j                  | j                  «       |S )NÚprotor—   )Úhasattrr©  ÚfactoryÚ_cbStopServerr¯  ÚexpectedLoseConnectionr   ÚmaybeDeferredr›   ÚloseConnectionrÓ   rÔ   s     r.   Ú
stopServerzCFTPClientTestBase.stopServer‘  s‚   € Ü�t—{‘{×*Ñ*¨GÔ4Ø×%Ñ% dÓ+Ð+Ø;<ˆ�‰×Ñ×!Ñ!Ô8Ü×Ñ §¡× 3Ñ 3× 9Ñ 9× CÑ C× RÑ RÓSˆØ	�‰�d×(Ñ(Ô)Øˆr0   c                 óT   — t        j                  | j                  j                  «      S r'   )r   r´  r©  ÚstopListening©r-   Úignoreds     r.   r²  z CFTPClientTestBase._cbStopServer™  s   € Ü×"Ñ" 4§;¡;×#<Ñ#<Ó=Ð=r0   c                 ó„   — dD ]  }	 t        j                  |«       Œ t        j                  | «      S # t        $ r Y Œ;w xY w)N)r™  rš  r›  )rP   ÚremoveÚBaseExceptionr
   ÚtearDownr   s     r.   r¾  zCFTPClientTestBase.tearDownœ  sH   € Ø8ò 	ˆAðÜ—	‘	˜!•ð	ô
 ×$Ñ$ TÓ*Ð*øô !ò Ùðús   ‡3³	?¾?N)rA   rB   rC   r/   r­  r¶  r²  r¾  rE   r0   r.   r—  r—  ~  s   „ ò(òGòò>ó+r0   r—  c                   ó�   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	d„ Z
d	„ Zd
„ Zdd„Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zy)ÚOurServerCmdLineClientTestszí
    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                 ó"  ‡ — t         j                  ‰ «       ‰ j                  «        d}‰ j                  j	                  «       j
                  }t        j                  ||z  j                  «       d¬«      }t        j                  dt        j                  › d|› �«       t        j                  «       }t        |«      ‰ _        |j#                  ˆ fd„«       t$        j&                  j)                  «       }t$        j*                  j-                  t        j.                  «      |d<   g }i }|D ]4  }t1        |t2        «      r|j5                  d«      }|j7                  |«       Œ6 |D ]N  }||   }	t1        |t2        «      r|j5                  d«      }t1        |	t2        «      r|	j5                  d«      }	|	||<   ŒP t        j                  |«       t        j                  |«       t9        j:                  ‰ j                   t        j                  ||¬	«       |S )
Nz‚-p %i -l testuser --known-hosts kh_test --user-authentications publickey --host-key-algorithms ssh-rsa -i dsa_test -a -v 127.0.0.1r   ©Úmodúrunning r  c                 ó8   •— ‰j                   j                  «       S r'   )ÚprocessProtocolrh  ©Ú_r-   s    €r.   r`  z3OurServerCmdLineClientTests.setUp.<locals>.<lambda>Â  ó   ø€  × 4Ñ 4× @Ñ @Ó B€ r0   Ú
PYTHONPATHr7   ©Úenv)r—  r/   r­  r©  ÚgetHostÚportr    Ú	_makeArgsr!  r   rs  rÐ   rÑ   r   r�  rf  rÆ  rÓ   rP   rQ   ÚcopyÚpathsepr;  rŽ   r‚  rƒ  r9   r"  r   ÚspawnProcess)
r-   ÚcmdsrÎ  rÕ   rÌ  ÚencodedCmdsÚ
encodedEnvÚcmdÚvarÚvals
   `         r.   r/   z!OurServerCmdLineClientTests.setUp¯  s£  ø€ Ü× Ñ  Ô&à×ÑÔðð 	ð �{‰{×"Ñ"Ó$×)Ñ)ˆÜ×#Ñ# T¨D¡[×$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‘(ˆCÜ˜#œsÔ#Ø—j‘j Ó)�Ü˜#œsÔ#Ø—j‘j Ó)�Ø!ˆJ�sŠOð	"ô 	�‰�ÔÜ�‰�
ÔÜ×ÑØ× Ñ ¤#§.¡.°+À:õ	
ð ˆr0   c                 óP   ‡ — ‰ j                  «       }|j                  ˆ fd„«       |S )Nc                 ó8   •— ‰j                   j                  «       S r'   )rÆ  r’  rÇ  s    €r.   r`  z6OurServerCmdLineClientTests.tearDown.<locals>.<lambda>Û  rÉ  r0   )r¶  rÓ   rÔ   s   ` r.   r¾  z$OurServerCmdLineClientTests.tearDownÙ  s!   ø€ Ø�O‰OÓˆØ	�‰ÓBÔCØˆr0   c                 ó‚   — 	 | j                   j                  j                  d«       y # t        j                  $ r Y y w xY w)Nr�  )rÆ  r›   r‘  r   ÚProcessExitedAlreadyr¹  s     r.   Ú_killProcessz(OurServerCmdLineClientTests._killProcessÞ  s9   € ð	Ø× Ñ ×*Ñ*×8Ñ8¸Õ@øÜ×)Ñ)ò 	Ùð	ús   ‚%( ¨>½>c                 ó8   — | j                   j                  |«      S )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†  z&OurServerCmdLineClientTests.runCommandä  s   € ð ×#Ñ#×.Ñ.¨wÓ7Ð7r0   c                 ó8   — | j                   j                  |«      S )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Ž  z%OurServerCmdLineClientTests.runScriptì  s   € ð ×#Ñ#×-Ñ-¨hÓ7Ð7r0   c                 óü   — | j                   }| j                  ddddd«      }d„ }|j                  |«       |j                  | j                  |j                  t        j                  «       d|j                  g«       |S )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                 óŽ   — g }| D ]4  }t        |t        «      r|j                  d«      }|j                  |«       Œ6 |dd |dd z   S )zH
            Callback function for handling command output.
            r7   Né   é   )r‚  Úbytesr   r"  )r*  rÓ  rÖ  s      r.   Ú	cmdOutputz8OurServerCmdLineClientTests.testCdPwd.<locals>.cmdOutputÿ  sU   € ð ˆDØò !�Ü˜c¤5Ô)ØŸ*™* WÓ-�CØ—‘˜CÕ ð!ð ˜˜�8˜d 1 2˜hÑ&Ð&r0   rØ   )r]  rŽ  rÓ   r;   rŽ   rP   Úgetcwd)r-   ÚhomeDirrÕ   rè  s       r.   Ú	testCdPwdz%OurServerCmdLineClientTests.testCdPwdô  sg   € ð —,‘,ˆØ�N‰N˜5 &Ð*<¸gÀuÓMˆò		'ð 	
�‰�iÔ Ø	�‰�d×&Ñ&¨¯©´r·y±y³{ÀBÈÏÉÐ(UÔVØˆr0   c                 óX   ‡ — ˆ fd„}‰ j                  dddd«      }|j                  |«      S )zŒ
        Check that 'ls -l' output includes the access permissions and that
        this output changes appropriately with 'chmod'.
        c                 ó  •— ‰j                  «        ‰j                  | d   j                  d«      «       ‰j                  | d   d«       ‰j                  | d   j                  d«      | d   «       ‰j                  | d   d«       y )Nr   s
   -rw-r--r--r—   r0   r  s
   ----------rå  )ÚflushLoggedErrorsr3   ry  r;   ©Úresultsr-   s    €r.   Ú_checkz7OurServerCmdLineClientTests.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¨Õ-r0   zls -l testfile1zchmod 0 testfile1zchmod 644 testfile1©rŽ  rÓ   ©r-   rñ  rÕ   s   `  r.   ÚtestChAttrsz'OurServerCmdLineClientTests.testChAttrs  s5   ø€ ô	.ð �N‰NØØØØ!ó	
ˆð �}‰}˜VÓ$Ð$r0   c                 ó´   ‡ — ˆ fd„}‰ j                  dd‰ j                  j                  «       z   ddd«      }|j                  d„ «       |j                  |«      S )zŽ
        Check 'ls' works as expected. Checks for wildcards, hidden files,
        listing directories and listing empty directories.
        c                 óê   •— ‰j                  | d   g d¢«       ‰j                  | d   g d¢«       ‰j                  | d   ddg«       ‰j                  | d   g d¢«       ‰j                  | d	   d
g«       y )Nr   ©s   testDirectoryó   testRemoveFileó   testRenameFiles	   testfile1r—   r  rø  rù  rå  )s   .testHiddenFilerø  rù  ræ  r0   ©r;   rï  s    €r.   rñ  z4OurServerCmdLineClientTests.testList.<locals>._check*  s‚   ø€ Ø×ÑØ˜‘
ÚVôð ×ÑØ˜‘
ÚVôð ×Ñ˜W Q™ZÐ*;Ð=NÐ)OÔPØ×ÑØ˜‘
ÒVôð ×Ñ˜W Q™Z¨#¨Õ/r0   r   zls ../zls *Filezls -a *Filezls -l testDirectoryc                 óJ   — | D �cg c]  }|j                  d«      ‘Œ c}S c c}w )Nrr  )r!  )ÚxsÚxs     r.   r`  z6OurServerCmdLineClientTests.testList.<locals>.<lambda>@  s   € ¸"Ö!=°Q !§'¡'¨%¥.Ò!=€ ùÒ!=s   … )rŽ  r]  r<  rÓ   ró  s   `  r.   ÚtestListz$OurServerCmdLineClientTests.testList$  sW   ø€ ô	0ð �N‰NØØ�t—|‘|×,Ñ,Ó.Ñ.ØØØ!ó
ˆð 	
�‰Ñ=Ô>Ø�}‰}˜VÓ$Ð$r0   c                 ó  — | j                  d«      }t        j                  d«      j                  d«      j	                  «       }t        |t        «      r|j                  d«      }|j                  | j                  |«       |S )zB
        Check that running the '?' command returns help.
        ú?NrØ   r7   )
r†  r   rÁ   Úcmd_HELPr#  r‚  rƒ  r9   rÓ   r;   )r-   rÕ   ÚhelpTexts      r.   ÚtestHelpz$OurServerCmdLineClientTests.testHelpC  sg   € ð �O‰O˜CÓ ˆä×#Ñ# DÓ)×2Ñ2°2Ó6×<Ñ<Ó>ˆÜ�h¤Ô$Ø—‘ wÓ/ˆHØ	�‰�d×&Ñ&¨Ô1Øˆr0   Nc                 ób   — | j                  |j                  «       |j                  «       |«       y)zg
        Assert that the files at C{name1} and C{name2} contain exactly the
        same data.
        N)r;   Ú
getContent)r-   Úname1Úname2rs  s       r.   ÚassertFilesEqualz,OurServerCmdLineClientTests.assertFilesEqualO  s(   € ð
 	×Ñ˜×)Ñ)Ó+¨U×-=Ñ-=Ó-?ÀÕEr0   c                 óh  ‡ ‡— dj                  ‰ j                  j                  ‰ j                  j                  «      Št        ‰t        «      r‰j                  d«      Šˆˆ fd„}‰ j                  d‰ j                  j                  › d�«      }|j                  |«       |j                  ˆ fd„«       |S )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 file2r7   c                 óð   •— ‰j                  | j                  ‰«      «       ‰j                  ‰j                  j	                  d«      ‰j                  j	                  d«      d«       ‰j                  d«      S )NÚ	testfile1ú
test file2z
get failedzrm "test file2")r3   Úendswithr  r]  Úchildr†  ©r   r+  r-   s    €€r.   Ú	_checkGetz6OurServerCmdLineClientTests.testGet.<locals>._checkGetd  s_   ø€ Ø�O‰O˜FŸO™O¨NÓ;Ô<Ø×!Ñ!Ø—‘×"Ñ" ;Ó/Ø—‘×"Ñ" <Ó0Øôð
 —?‘?Ð#4Ó5Ð5r0   zget testfile1 "z/test file2"c                 ót   •— ‰j                  ‰j                  j                  d«      j                  «       «      S )Nr  ©ÚassertFalser]  r  ÚexistsrÇ  s    €r.   r`  z5OurServerCmdLineClientTests.testGet.<locals>.<lambda>p  ó*   ø€ �d×&Ñ& t§|¡|×'9Ñ'9¸,Ó'G×'NÑ'NÓ'PÓQ€ r0   )rX  r]  rŽ   r‚  rƒ  r9   r†  rÓ   )r-   r  rÕ   r+  s   `  @r.   ÚtestGetz#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ô	
ð ˆr0   c                 óR   ‡ — ˆ fd„}‰ j                  d«      }|j                  |«      S )zQ
        Test that 'get' works correctly when given wildcard parameters.
        c                 óÚ   •— ‰j                  ‰j                  j                  d«      t        d«      d«       ‰j                  ‰j                  j                  d«      t        d«      d«       y )NÚtestRemoveFileútestRemoveFile get failedÚtestRenameFileútestRenameFile get failed)r  r]  r  r   )rº  r-   s    €r.   rñ  z;OurServerCmdLineClientTests.testWildcardGet.<locals>._checky  s_   ø€ Ø×!Ñ!Ø—‘×"Ñ"Ð#3Ó4ÜÐ)Ó*Ø+ôð
 ×!Ñ!Ø—‘×"Ñ"Ð#3Ó4ÜÐ)Ó*Ø+õr0   z
get testR*)r†  rÓ   ró  s   `  r.   ÚtestWildcardGetz+OurServerCmdLineClientTests.testWildcardGett  s'   ø€ ô

	ð �O‰O˜LÓ)ˆØ�}‰}˜VÓ$Ð$r0   c                 óV  ‡ ‡— d‰ j                   j                  «       j                  z   dz   ‰ j                   j                  «       j                  z   dz   Šˆˆ fd„}‰ j                  d‰ j                   j                  › d�«      }|j	                  |«       |j	                  ˆ fd„«       |S )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                 óî   •— ‰j                  ‰j                  j                  d«      ‰j                  j                  d«      «       ‰j                  | j	                  ‰«      «       ‰j                  d«      S )Nr  ú
test"file2zrm "test\"file2")r  r]  r  r3   r  r†  r  s    €€r.   Ú	_checkPutz6OurServerCmdLineClientTests.testPut.<locals>._checkPut–  s[   ø€ Ø×!Ñ!Ø—‘×"Ñ" ;Ó/°·±×1CÑ1CÀLÓ1Qôð �O‰O˜FŸO™O¨NÓ;Ô<Ø—?‘?Ð#6Ó7Ð7r0   úput z/testfile1 "test\"file2"c                 ót   •— ‰j                  ‰j                  j                  d«      j                  «       «      S )Nr   r  rÇ  s    €r.   r`  z5OurServerCmdLineClientTests.testPut.<locals>.<lambda>   r  r0   )r]  ÚasBytesModerŽ   r†  rÓ   )r-   r!  rÕ   r+  s   `  @r.   ÚtestPutz#OurServerCmdLineClientTests.testPutˆ  s£   ù€ ð Ø�l‰l×&Ñ&Ó(×-Ñ-ñ.àñ ð �l‰l×&Ñ&Ó(×-Ñ-ñ.ð ñ	ð 	õ	8ð �O‰O˜d 4§<¡<×#4Ñ#4Ð"5Ð5NÐOÓPˆØ	�‰�iÔ Ø	�‰ÛQô	
ð ˆr0   c                 óÊ  ‡ — ‰ j                   j                  d«      j                  d¬«      5 }|j                  d«       ddd«       ‰ j                   j                  d«      j                  d¬«      5 }|j                  d«       ddd«       ˆ fd„}‰ j	                  d	‰ j                   j
                  › d
�«      }|j                  |«       |S # 1 sw Y   Œ�xY w# 1 sw Y   ŒVxY w)zb
        Check that 'put' uploads files correctly when overwriting a longer
        file.
        ÚshorterFileÚw©Úmodeó   aNÚ
longerFileó   bbc                 óŽ   •— ‰j                  ‰j                  j                  d«      ‰j                  j                  d«      «       y )Nr'  r,  )r  r]  r  )r   r-   s    €r.   r!  zEOurServerCmdLineClientTests.test_putOverLongerFile.<locals>._checkPut¯  s4   ø€ Ø×!Ñ!Ø—‘×"Ñ" =Ó1°4·<±<×3EÑ3EÀlÓ3Sõr0   r"  z/shorterFile longerFile)r]  r  r  r©   r†  rŽ   rÓ   )r-   r¡  r!  rÕ   s   `   r.   Útest_putOverLongerFilez2OurServerCmdLineClientTests.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Á2CÃCÃC"c                 ó  ‡ ‡— ‰ j                   j                  d«      Š‰j                  «        ‰j                  d«      j                  d¬«      5 }|j	                  d«       ddd«       ‰ j                   j                  d«      j                  d¬«      5 }|j	                  d«       ddd«       ˆ ˆfd„}‰ j                  d	‰ j                   j                  › d
�«      }|j                  |«       |S # 1 sw Y   Œ�xY w# 1 sw Y   ŒWxY w)z˜
        Check that 'put' uploads files correctly when overwriting a longer
        file and you use a wildcard to specify the files to upload.
        Údirr  r(  r)  r+  Nr-  c                 óz   •— ‰j                  ‰j                  d«      ‰j                  j                  d«      «       y )Nr  )r  r  r]  )r   r-   ÚsomeDirs    €€r.   r!  zMOurServerCmdLineClientTests.test_putMultipleOverLongerFile.<locals>._checkPutÅ  s+   ø€ Ø×!Ñ! '§-¡-°Ó"7¸¿¹×9KÑ9KÈFÓ9SÕTr0   r"  z/dir/*)r]  r  ÚcreateDirectoryr  r©   r†  rŽ   rÓ   )r-   r¡  r!  rÕ   r3  s   `   @r.   Útest_putMultipleOverLongerFilez:OurServerCmdLineClientTests.test_putMultipleOverLongerFile¸  sÞ   ù€ ð —,‘,×$Ñ$ UÓ+ˆØ×ÑÔ!Ø�]‰]˜6Ó"×'Ñ'¨SÐ'Ó1ð 	°QØ�G‰G�DŒM÷	à�\‰\×Ñ Ó'×,Ñ,°#Ð,Ó6ð 	¸!Ø�G‰G�EŒN÷	õ	Uð �O‰O˜d 4§<¡<×#4Ñ#4Ð"5°VÐ<Ó=ˆØ	�‰�iÔ Øˆ÷	ð 	ú÷	ð 	ús   ÁC0ÂC<Ã0C9Ã<Dc                 óÀ   ‡ — ˆ fd„}‰ j                  dd‰ j                  j                  › d�d‰ j                  j                  «       z  «      }|j	                  |«       |S )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                 ó¦  •— ‰j                  | d   d«       ‰j                  | d   d«       ‰j                  ‰j                  j                  d«      ‰j                  j	                  «       j                  d«      d«       ‰j                  ‰j                  j                  d«      ‰j                  j	                  «       j                  d«      d«       y )Nr   r0   r  r  r  r  r  )r;   r  r]  r  rP  rï  s    €r.   Úcheckz:OurServerCmdLineClientTests.testWildcardPut.<locals>.checkÓ  s­   ø€ Ø×Ñ˜W Q™Z¨Ô-Ø×Ñ˜W Q™Z¨Ô-à×!Ñ!Ø—‘×"Ñ"Ð#3Ó4Ø—‘×#Ñ#Ó%×+Ñ+Ð,<Ó=Ø+ôð
 ×!Ñ!Ø—‘×"Ñ"Ð#3Ó4Ø—‘×#Ñ#Ó%×+Ñ+Ð,<Ó=Ø+õr0   rã  r"  z/testR*zcd %s)rŽ  r]  rŽ   r<  rÓ   )r-   r8  rÕ   s   `  r.   ÚtestWildcardPutz+OurServerCmdLineClientTests.testWildcardPutÌ  sZ   ø€ ô	ð �N‰NØØ�4—<‘<×$Ñ$Ð% WÐ-Ø�d—l‘l×+Ñ+Ó-Ñ-ó
ˆð
 	
�‰�eÔØˆr0   c                 ó�   ‡ — ˆ fd„}‰ j                  dd«      }|j                  |«       |j                  ‰ j                  d«       |S )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                 ó¸   •— ‰j                  «        ‰j                  | d   d«       ‰j                  | d   j                  d«      d«       ‰j	                  d«      S )Nr   r0   r—   ó   lzlink failedzrm testLink)rî  r;   r3   ry  r†  rï  s    €r.   rñ  z4OurServerCmdLineClientTests.testLink.<locals>._checkð  sO   ø€ Ø×"Ñ"Ô$Ø×Ñ˜W Q™Z¨Ô-Ø�O‰O˜G A™J×1Ñ1°$Ó7¸ÔGØ—?‘? =Ó1Ð1r0   zln testLink testfile1zls -l testLinkr0   ©rŽ  rÓ   r;   ró  s   `  r.   ÚtestLinkz$OurServerCmdLineClientTests.testLinkê  sA   ø€ ô	2ð �N‰NÐ2Ð4DÓEˆØ	�‰�fÔØ	�‰�d×&Ñ&¨Ô,Øˆr0   c                 ó�   ‡ — ˆ fd„}‰ j                  dd«      }|j                  |«       |j                  ‰ j                  d«       |S )zV
        Test that we can create and remove directories with the cftp client.
        c                 ó–   •— ‰j                  | d   d«       ‰j                  | d   j                  d«      «       ‰j                  d«      S )Nr   r0   r—   ó   dzrmdir testMakeDirectory)r;   r3   ry  r†  rï  s    €r.   rñ  z?OurServerCmdLineClientTests.testRemoteDirectory.<locals>._check   sB   ø€ Ø×Ñ˜W Q™Z¨Ô-Ø�O‰O˜G A™J×1Ñ1°$Ó7Ô8Ø—?‘?Ð#<Ó=Ð=r0   úmkdir testMakeDirectoryzls -l testMakeDirector?r0   r=  ró  s   `  r.   ÚtestRemoteDirectoryz/OurServerCmdLineClientTests.testRemoteDirectoryû  sA   ø€ ô
	>ð
 �N‰NÐ4Ð6OÓPˆØ	�‰�fÔØ	�‰�d×&Ñ&¨Ô,Øˆr0   c                 óX   ‡ — ˆ fd„}‰ j                  dd«      }|j                  |«       |S )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   •— ‰j                  | d   d«       ‰j                  | d   d«       y )Nr   r0   r—   s   remote error 11: mkdir failedrú  rï  s    €r.   rñ  zHOurServerCmdLineClientTests.test_existingRemoteDirectory.<locals>._check  s,   ø€ Ø×Ñ˜W Q™Z¨Ô-Ø×Ñ˜W Q™ZÐ)IÕJr0   rB  rò  ró  s   `  r.   Útest_existingRemoteDirectoryz8OurServerCmdLineClientTests.test_existingRemoteDirectory
  s.   ø€ ô	Kð �N‰NÐ4Ð6OÓPˆØ	�‰�fÔØˆr0   c                 óò   ‡ — ‰ j                  d‰ j                  j                  › d�«      }|j                  ‰ j                  d«       |j                  ˆ fd„«       |j                  ‰ j                  d«       |S )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/testLocalDirectoryr0   c                 ó&   •— ‰j                  d«      S )Nzrmdir testLocalDirectory)r†  rÇ  s    €r.   r`  z@OurServerCmdLineClientTests.testLocalDirectory.<locals>.<lambda>   s   ø€  §¡Ð0JÓ K€ r0   )r†  r]  rŽ   rÓ   r;   rÔ   s   ` r.   ÚtestLocalDirectoryz.OurServerCmdLineClientTests.testLocalDirectory  sb   ø€ ð �O‰O˜g d§l¡l×&7Ñ&7Ð%8Ð8KÐLÓMˆØ	�‰�d×&Ñ&¨Ô,Ø	�‰ÓKÔLØ	�‰�d×&Ñ&¨Ô,Øˆr0   c                 ó�   ‡ — ˆ fd„}‰ j                  dd«      }|j                  |«       |j                  ‰ j                  d«       |S )z1
        Test that we can rename a file.
        c                 óz   •— ‰j                  | d   d«       ‰j                  | d   d«       ‰j                  d«      S )Nr   r0   r—   s	   testfile2zrename testfile2 testfile1)r;   r†  rï  s    €r.   rñ  z6OurServerCmdLineClientTests.testRename.<locals>._check)  s;   ø€ Ø×Ñ˜W Q™Z¨Ô-Ø×Ñ˜W Q™Z¨Ô6Ø—?‘?Ð#?Ó@Ð@r0   zrename testfile1 testfile2zls testfile?r0   r=  ró  s   `  r.   Ú
testRenamez&OurServerCmdLineClientTests.testRename$  sA   ø€ ô
	Að
 �N‰NÐ7¸ÓHˆØ	�‰�fÔØ	�‰�d×&Ñ&¨Ô,Øˆr0   r'   )rA   rB   rC   rD   r/   r¾  rÝ  r†  rŽ  rë  rô  rþ  r  r  r  r  r%  r/  r5  r9  r>  rC  rF  rI  rL  rE   r0   r.   rÀ  rÀ  ¥  sr   „ ñò(òTò
ò8ò8òò4%ò,%ò>
óFòò<%ò(ò8ò(ò(ò<ò"òò
ór0   rÀ  c                   ó4   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	y)	ÚOurServerBatchFileTestszm
    Functional tests which launch a SFTP server over localhost and checks csftp
    in batch interface.
    c                 óN   — t         j                  | «       | j                  «        y r'   ©r—  r/   r­  r,   s    r.   r/   zOurServerBatchFileTests.setUp;  s   € Ü× Ñ  Ô&Ø×ÑÕr0   c                 óL   — t         j                  | «       | j                  «       S r'   )r—  r¾  r¶  r,   s    r.   r¾  z OurServerBatchFileTests.tearDown?  s   € Ü×#Ñ# DÔ)Ø�‰Ó Ð r0   c                 óà  ‡— | j                  «       Št        ‰d«      5 }|j                  |«       d d d «       | j                  j	                  «       j
                  }d|‰fz  }t        j                  |j                  «       d¬«      dd  }t        j                  dt        j                  › d|› �«       t        j                  j                  «       }t        j                   j#                  t        j$                  «      |d<   d| j                  j&                  _        t+        t        j                  ||¬	«      }ˆfd
„}|j-                  d„ «       |j/                  |«       |S # 1 sw Y   �Œ5xY w)Nr(  zˆ-p %i -l testuser --known-hosts kh_test --user-authentications publickey --host-key-algorithms ssh-rsa -i dsa_test -a -v -b %s 127.0.0.1r   rÂ  r—   rÄ  r  rÊ  rË  c                 ó2   •— t        j                  ‰«       | S r'   )rP   r¼  )ÚresÚfns    €r.   Ú_cleanupz9OurServerBatchFileTests._getBatchOutput.<locals>._cleanupZ  s   ø€ Ü�I‰I�bŒMØˆJr0   c                 ó   — | d   S )Nr   rE   )rT  s    r.   r`  z9OurServerBatchFileTests._getBatchOutput.<locals>.<lambda>^  s
   €  # a¡&€ r0   )r  r  r©   r©  rÍ  rÎ  r    rÏ  r!  r   rs  rÐ   rÑ   rP   rQ   rÐ  rÑ  r;  rŽ   r±  r³  r   rÓ   ÚaddBoth)	r-   r¡  ÚfprÎ  rÓ  rÌ  rÕ   rV  rU  s	           @r.   Ú_getBatchOutputz'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¸sÔCˆô	ð 	
�‰Ñ(Ô)Ø	�	‰	�(Ôàˆ÷9	ñ 	ús   žE#Å#E-c                 óZ   ‡ — d}ˆ fd„}‰ j                  |«      }|j                  |«       |S )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                 ó  •— | j                  d«      } t        j                  dt        | «      z  «       ‰j	                  ‰j
                  j                  «       j                  | d   «       ‰j                  | dd g d¢«       y )Nrr  zRES %sr—   rå  éþÿÿÿr÷  )	r!  r   rs  ÚreprÚassertInr]  r$  rŽ   r;   ©rT  r-   s    €r.   Ú_cbCheckResultz=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õr0   ©rZ  rÓ   ©r-   rÓ  ra  rÕ   s   `   r.   ÚtestBatchFilez%OurServerBatchFileTests.testBatchFilec  s2   ø€ ð
ˆô
	ð × Ñ  Ó&ˆØ	�‰�nÔ%Øˆr0   c                 óZ   ‡ — d}ˆ fd„}‰ j                  |«      }|j                  |«       |S )zO
        Test that an error in the batch file stops running the batch.
        zchown 0 missingFile
pwd
exit
c                 ón   •— ‰j                  ‰j                  j                  «       j                  | «       y r'   )ÚassertNotInr]  r$  rŽ   r`  s    €r.   ra  z9OurServerBatchFileTests.testError.<locals>._cbCheckResultƒ  s&   ø€ Ø×Ñ˜TŸ\™\×5Ñ5Ó7×<Ñ<¸cÕBr0   rb  rc  s   `   r.   Ú	testErrorz!OurServerBatchFileTests.testErrorz  s3   ø€ ðˆô
	Cð × Ñ  Ó&ˆØ	�‰�nÔ%Øˆr0   c                 óZ   ‡ — d}ˆ fd„}‰ j                  |«      }|j                  |«       |S )z_
        Test that a minus sign '-' at the front of a line ignores
        any errors.
        z-chown 0 missingFile
pwd
exit
c                 ón   •— ‰j                  ‰j                  j                  «       j                  | «       y r'   )r_  r]  r$  rŽ   r`  s    €r.   ra  z@OurServerBatchFileTests.testIgnoredError.<locals>._cbCheckResult”  s$   ø€ Ø�M‰M˜$Ÿ,™,×2Ñ2Ó4×9Ñ9¸3Õ?r0   rb  rc  s   `   r.   ÚtestIgnoredErrorz(OurServerBatchFileTests.testIgnoredErrorŠ  s3   ø€ ð
ˆô
	@ð × Ñ  Ó&ˆØ	�‰�nÔ%Øˆr0   N)
rA   rB   rC   rD   r/   r¾  rZ  rd  rh  rk  rE   r0   r.   rN  rN  4  s&   „ ñò
ò!òò@ò.ó r0   rN  Ússhz$no ssh command-line client availableÚsftpz%no sftp command-line client availablec                   ó"   — e Zd ZdZd„ Zd„ Zd„ Zy)ÚOurServerSftpClientTestsz@
    Test the sftp server against sftp command line client.
    c                 óL   — t         j                  | «       | j                  «       S r'   rP  r,   s    r.   r/   zOurServerSftpClientTests.setUp¤  s   € Ü× Ñ  Ô&Ø×ÑÓ!Ð!r0   c                 ó"   — | j                  «       S r'   )r¶  r,   s    r.   r¾  z!OurServerSftpClientTests.tearDown¨  s   € Ø�‰Ó Ð r0   c                 ó4  ‡ ‡‡‡‡	— t        t        j                  «      Š‰ j                  «       Št	        ‰d«      5 }|j                  d«       ddd«       ‰ j                  j                  «       j                  Š	t        j                  Šˆfd„}‰ j                  t        d|«       d‰ j                  j                  _        t        dd‰«      }ˆˆ	fd	„}ˆ fd
„}|j                  |«       |j                  ˆfd„«       |j                  |«      S # 1 sw Y   ŒÂxY w)a  
        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                 ó$   •—  ‰| |«      }d|d<   |S )NrË   Úext_foorE   )r-   Úsr¡   Ú
oldGetAttrs      €r.   Ú	_getAttrszCOurServerSftpClientTests.test_extendedAttributes.<locals>._getAttrs¾  s   ø€ Ù˜t QÓ'ˆEØ$ˆE�)ÑØˆLr0   rw  Trl  )ú-oúPubkeyAcceptedKeyTypes=ssh-dssz-Vc                 óH   •— | dk(  rd}nd}|dddddddd	dd
‰fz  d‰dfz  }|S )Nr   )rx  ry  rE   z-Fz	/dev/nullrx  zIdentityFile=dsa_testzUserKnownHostsFile=kh_testzHostKeyAlgorithms=ssh-rsazPort=%iz-bztestuser@127.0.0.1rE   )ÚstatusÚargsrU  rÎ  s     €€r.   ÚhasPAKTzAOurServerSftpClientTests.test_extendedAttributes.<locals>.hasPAKTÌ  sZ   ø€ Ø˜Š{Ø?‘à�ð ØØØØ'ØØ,ØØ+ØØ˜T˜GÑ#ØØØ$ðñ ˆDð ˆKr0   c                 óŽ   •— ‰j                  | d   d| d   j                  d«      «       dD ]  }‰j                  || d   «       Œ y )Nr  r   r—   Úasciir÷  )r;   r   r_  )r   Úir-   s     €r.   r8  z?OurServerSftpClientTests.test_extendedAttributes.<locals>.checkå  sM   ø€ Ø×Ñ˜V A™Y¨¨6°!©9×+;Ñ+;¸GÓ+DÔEðò ,�ð —‘˜a ¨¡Õ+ñ,r0   c                 ó   •— t        d| ‰«      S )Nrm  )r   )r|  rÌ  s    €r.   r`  zBOurServerSftpClientTests.test_extendedAttributes.<locals>.<lambda>ð  s   ø€ Ô#;¸FÀDÈ#Ó#N€ r0   )ÚdictrP   rQ   r  r  r©   r©  rÍ  rÎ  r#   rw  rT   r±  r³  r   rÓ   )
r-   r¡  rw  rÕ   r}  r8  rÌ  rU  rv  rÎ  s
   `     @@@@r.   Útest_extendedAttributesz0OurServerSftpClientTests.test_extendedAttributes«  sÞ   ü€ ô ”2—:‘:Óˆà�[‰[‹]ˆÜ�"�c‹]ð 	"˜aØ�G‰G�LÔ!÷	"à�{‰{×"Ñ"Ó$×)Ñ)ˆä.×8Ñ8ˆ
ô	ð
 	�
‰
Ô,¨k¸9ÔEØ59ˆ�‰×ÑÔ2ô ˜EÐ#QÐSVÓWˆõ	ô2	,ð 	
�‰�gÔØ	�‰ÓNÔOØ�}‰}˜UÓ#Ð#÷s	"ð 	"ús   »DÄDN)rA   rB   rC   rD   r/   r¾  rƒ  rE   r0   r.   ro  ro  œ  s   „ ñò"ò!óF$r0   ro  )RrD   rÍ   rs   rV   rP   rå   rÐ   rM   Ú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   r   Ú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%   rG   r€   r‰   r•   r¤   r¼   r[  ÚProcessProtocolrf  r—  rÀ  rN  ro  rE   r0   r.   ú<module>r      s=  ðñ
ó Û Û Û 	Û Û 
Û ß %Ý å &å Ý .ß UÝ ß HÕ HÝ 'Ý 4ß LÝ Ý /Ý ,Ý *Ý 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ôR$Ð1ó R$ó Dó Bó AñR$øð_+ ò Úðús   Â&,G2 Ç2G;Ç:G;