%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/twisted/test/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/twisted/test/__pycache__/test_ftp.cpython-312.pyc

�

Ϫ�f����dZddlZddlZddlZddlZddlZddlmZddlm	Z	ddl
mZddlm
Z
mZmZddlmZddlmZdd	lmZmZmZmZmZdd
lmZddlmZmZmZddl m!Z!m"Z"m#Z#dd
l$m%Z%ddl&m'Z'e#jPjS�sdZ*ndZ*Gd�dejV�Z,Gd�dejZ�Z.dSd�Z/Gd�de'�Z0Gd�de0�Z1Gd�de0�Z2Gd�de0�Z3Gd�de0�Z4Gd�d e4�Z5Gd!�d"e'�Z6Gd#�d$e'�Z7Gd%�d&ejZ�Z8Gd'�d(ejr�Z:Gd)�d*e'�Z;Gd+�d,e'�Z<Gd-�d.e'�Z=Gd/�d0e'�Z>Gd1�d2e'�Z?Gd3�d4e'�Z@Gd5�d6e'�ZAGd7�d8e'�ZBGd9�d:e'�ZCGd;�d<e'�ZDGd=�d>e'�ZEGd?�d@�ZFGdA�dBe'eF�ZGe	e�GdC�dD��ZHGdE�dF�ZIGdG�dH�ZJGdI�dJe'eJ�ZKe	ej��GdK�dL��ZMGdM�dN�ZNGdO�dPe'�ZOGdQ�dRe'�ZPy)Tz
FTP tests.
�N)�BytesIO)�implementer)�verifyClass)�checkers�credentials�portal)�UnauthorizedLogin)�IRealm)�defer�error�protocol�reactor�task)�	IConsumer)�basic�ftp�loopback)�failure�filepath�runtime)�
proto_helpers)�TestCasezCannot run on Windowsc�.�eZdZdZd�Zd�Zd�Zd�Zd�Zy)�DummyNc� �g|_g|_y�N)�lines�rawData��selfs �7/usr/lib/python3/dist-packages/twisted/test/test_ftp.py�__init__zDummy.__init__%s����
����c�&�|j|_yr)�factory�frs r!�connectionMadezDummy.connectionMade)s
������r#c�:�|jj|�yr)r�append�r �lines  r!�lineReceivedzDummy.lineReceived,����
�
���$�r#c�:�|jj|�yr)rr)�r �datas  r!�rawDataReceivedzDummy.rawDataReceived/s�������D�!r#c��yr�r*s  r!�lineLengthExceededzDummy.lineLengthExceeded2s��r#)	�__name__�
__module__�__qualname__�lognamer"r'r,r1r4r3r#r!rr"s ���G��� �"�
r#rc��eZdZd�Zd�Zd�Zy)�_BufferingProtocolc�D�d|_tj�|_y�Nr#)�bufferr�Deferred�drs r!r'z!_BufferingProtocol.connectionMade7s��������!��r#c�.�|xj|z
c_yr�r=r/s  r!�dataReceivedz_BufferingProtocol.dataReceived;s�����t��r#c�:�|jj|�yr)r?�callback)r �reasons  r!�connectionLostz!_BufferingProtocol.connectionLost>s��������r#N)r5r6r7r'rBrFr3r#r!r:r:6s��"��r#r:c�l�dtj||��d�}|j|j�S)z�
    Construct a passive mode message with the correct encoding

    @param protocol: the FTP protocol from which to base the encoding
    @param host: the hostname
    @param port: the port
    @return: the passive mode message
    z227 Entering Passive Mode (z).)r�encodeHostPort�encode�	_encoding)r
�host�port�msgs    r!�passivemode_msgrNBs5��
(��(:�(:�4��(F�'G�r�
J�C��:�:�h�(�(�)�)r#c�N�eZdZdZej
ZdZd�Zd	d�Z	d
d�Z
d�Zd�Zy)�FTPServerTestCasezw
    Simple tests for an FTP server with the default settings.

    @ivar clientFactory: class used as ftp client.
    �	anonymousc���	�
��g��j��_tj�j�t	j
�j��_tjtj�j�j���}|jtj�tj�tj �}d�_d�_|j'�j"�j$�|j|tj(�tj*|�j,���_t1j2d�j.d��x�_}�j7|j8��j.j:�	t=j>��
�	�
��fd�}|�j._|jA�j4}tCjDt0�jF�}|jId|�}��fd	�}|jK|��j7tLjNt0��t=jP�
|g�S)
N)�
anonymousRoot�userHomez	test-userz
test-password)r�
userAnonymousr�	127.0.0.1��	interfacec�����j`�|�}|j�_�fd�}�j	|��jd��j
|�|S)Nc�|���jj�%�jjj�yyr��serverProtocol�	transport�loseConnectionrs�r!�
cleanupServerzQFTPServerTestCase.setUp.<locals>._rememberProtocolInstance.<locals>.cleanupServer�s2����&�&�0�0�<��'�'�1�1�@�@�B�=r#)r%�
buildProtocol�wrappedProtocolr\�
addCleanuprDr))�addrr
r_r`�d1�	protocolsr s   ����r!�_rememberProtocolInstancez:FTPServerTestCase.setUp.<locals>._rememberProtocolInstance{sX������*�$�T�*�H�"*�":�":�D��
C�
�O�O�M�*��K�K������X�&��Or#c���|�_�j�jjj��j	�j�yr)�clientrbr]r^r))rhrer s ��r!�	gotClientz*FTPServerTestCase.setUp.<locals>.gotClient�s8��� �D�K��O�O�D�K�K�1�1�@�@�A����T�[�[�)r#))�mktemp�	directory�os�mkdirr�FilePath�dirPathr�Portalr�FTPRealm�registerCheckerr�AllowAnonymousAccessr�
IAnonymous�'InMemoryUsernamePasswordDatabaseDontUse�username�password�addUser�IUsernamePassword�
FTPFactoryrUr%r�	listenTCPrLrb�
stopListeningr`rr>�getHostr
�
ClientCreator�
clientFactory�
connectTCP�addCallbackr�waitUntilAllDisconnected�
gatherResults)r �p�
users_checkerrLrf�portNum�
clientCreator�d2rir`rdres`        @@@r!�setUpzFTPServerTestCase.setUpYs�����	�������
������ ��(�(����8���
�M�M��L�L�"�n�n����
�
��	
���(�7�7�9�;�;Q�;Q�R� �H�H�J�
�#��
�'��
����d�m�m�T�]�]�;�	���-��)F�)F�G��~�~�Q�d�>P�>P�Q���"�,�,�Q�����T�T��	�D�����*�*�+����2�2�
�
�^�^�
��	� &?����"��,�,�.�%�%�� �.�.�w��8J�8J�K�
�
�
%�
%�k�7�
;��	*�
	���y�!����
�>�>���S��"�"�B��8�,�,r#Nc�f����|�tjd�}���fd�}|j|�S)z�
        Asserts that a sending an FTP command receives the expected
        response.

        Returns a Deferred.  Optionally accepts a deferred to chain its actions
        to.
        Nc�h���jj��}��fd�}|j|�S)Nc�*���j�|�yr��assertEqual)�
responseLines�expectedResponseLinesr s ��r!�gotResponsezRFTPServerTestCase.assertCommandResponse.<locals>.queueCommand.<locals>.gotResponse�s���� � �!6�
�Fr#�rh�queueStringCommandr�)�ignoredr?r��commandr�r s   ���r!�queueCommandz=FTPServerTestCase.assertCommandResponse.<locals>.queueCommand�s.������.�.�w�7�A�
G��=�=��-�-r#)r�succeedr�)r r�r��
chainDeferredr�s```  r!�assertCommandResponsez'FTPServerTestCase.assertCommandResponse�s1���� �!�M�M�$�/�M�	.��(�(��6�6r#c������|�tjd�}��fd�}|j|��j|tj
���fd�}|j|�S)Nc�:���jj��Sr�rhr�)r�r�r s ��r!r�z;FTPServerTestCase.assertCommandFailed.<locals>.queueCommand�s����;�;�1�1�'�:�:r#c�J���� �j�|jd�yy�Nr�r��args)�	exception�expectedResponser s ��r!�failedz5FTPServerTestCase.assertCommandFailed.<locals>.failed�s(����+�� � �!1�9�>�>�!�3D�E�,r#)rr�r��
assertFailurer�
CommandFailed)r r�r�r�r�r�s```   r!�assertCommandFailedz%FTPServerTestCase.assertCommandFailed�s[���� �!�M�M�$�/�M�	;�	�!�!�,�/����=�#�*;�*;�<�	F��(�(��0�0r#c�R�|jddg�}|jddg|��S)N�USER anonymous�8331 Guest login ok, type your email address as password.�PASS test@twistedmatrix.com�2230 Anonymous login ok, access restrictions apply.�r��r��r r?s  r!�_anonymousLoginz!FTPServerTestCase._anonymousLogin�sA���&�&��
G�H�
���)�)�)�
A�B��*�
�	
r#c��|jd|jzd|jzg�}|jd|jzdg|��S)zx
        Authenticates the FTP client using the test account.

        @return: L{Deferred} of command response
        zUSER %sz331 Password required for %s.zPASS %sz230 User logged in, proceedr�)r�rvrwr�s  r!�
_userLoginzFTPServerTestCase._userLogin�s^��
�&�&�����'�
,��
�
�
>�?�
���)�)�����'�
*�+��*�
�	
r#r)NN)
r5r6r7�__doc__r�FTPClientBasicrrUr�r�r�r�r�r3r#r!rPrPOs4����&�&�M��M�A-�F7�*1� 	
�
r#rPc��eZdZdZdZd�Zy)�FTPAnonymousTestsz�
    Simple tests for an FTP server with different anonymous username.
    The new anonymous username used in this test case is "guest"
    �guestc�R�|jddg�}|jddg|��S)a
        Tests whether the changing of the anonymous username is working or not.
        The FTP server should not comply about the need of password for the
        username 'guest', letting it login as anonymous asking just an email
        address as password.
        z
USER guestr�r�r�r�r�r�s  r!�test_anonymousLoginz%FTPAnonymousTests.test_anonymousLogin�sC��
�&�&��U�V�
���)�)�)�
A�B��*�
�	
r#N)r5r6r7r�rUr�r3r#r!r�r��s���
�M�
r#r�c��eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zy)�BasicFTPServerTestsz,
    Basic functionality of FTP server.
    c���d�j_tjtt
�}|j
d�jj�j�}|jd��}|j�fd��}|S)zn
        When the connection limit is reached, the server should send an
        appropriate response
        �rVc��|jSr)r?)�protos r!riz>BasicFTPServerTests.test_tooManyConnections.<locals>.gotClients���7�7�Nr#c�>���jd|j�y)Ns;421 Too many users right now, try again in a few minutes.
�r�r=)r�r s �r!�onConnectionLostzEBasicFTPServerTests.test_tooManyConnections.<locals>.onConnectionLosts������T����
r#)
r%�connectionLimitr
r~rr:r�rLr}r�)r �ccr?rir�s`    r!�test_tooManyConnectionsz+BasicFTPServerTests.test_tooManyConnections�s|���
()����$�
�
#�
#�G�-?�
@���M�M�+�t�y�y�'8�'8�':�'?�'?�@��	
���	�
�	�
���	�
�	��r#c���gd�}dg}�fd�}�fd�}g}|D]`}�jj|�}�j|tj�|j||�|j
|��b|D]@}�jj|�}|j||�|j
|��Btj|d��S)z�
        When not logged in, most commands other than USER and PASS should
        get NOT_LOGGED_IN errors, but some can be called before USER and PASS.
        )
�CDUP�CWD�LIST�MODE�PASV�PWD�RETR�STRU�SYST�TYPE�FEATc�|��|jd}�j|djd�|�d|d���y)Nr����530z# - Response didn't start with 530: )r��
assertTrue�
startswith)r�r��failureResponseLinesr s   �r!�checkFailResponsezDBasicFTPServerTests.test_NotLoggedInReply.<locals>.checkFailResponse%sC���#,�>�>�!�#4� ��O�O�$�R�(�3�3�E�:��(��,��
r#c�\��|d}�j|jd�|�d|���y)Nrr�z - Response start with 530: )�assertFalser�)�resultr�r s  �r!�checkPassResponsezDBasicFTPServerTests.test_NotLoggedInReply.<locals>.checkPassResponse0s5����A�Y�F�����!�!�%�(����
r#T��fireOnOneErrback)	rhr�r�rr�r�r)r�DeferredList)r �loginRequiredCommandList�loginNotRequiredCommandListr�r��	deferredsr��deferreds`       r!�test_NotLoggedInReplyz)BasicFTPServerTests.test_NotLoggedInReplys����
$
� �(.�h�#�		�		��	�/�	'�G��{�{�5�5�g�>�H����x��):�):�;�� � �!2�G�<����X�&�		'�3�	'�G��{�{�5�5�g�>�H�� � �!2�G�<����X�&�	'�
�!�!�)�d�C�Cr#c�(�|jddg�S)z@
        Issuing PASS before USER should give an error.
        zPASS fooz=503 Incorrect sequence of commands: USER required before PASS�r�rs r!�test_PASSBeforeUSERz'BasicFTPServerTests.test_PASSBeforeUSERIs ���'�'��
O�P�
�	
r#c�(�|jddg�S)zD
        Issuing USER without a username is a syntax error.
        �USERz,500 Syntax error: USER requires an argument.r�rs r!�test_NoParamsForUSERz(BasicFTPServerTests.test_NoParamsForUSERRs ���'�'��C�D�
�	
r#c�b�|jjd�}|jddg|��S)zD
        Issuing PASS without a password is a syntax error.
        �USER foo�PASSz,500 Syntax error: PASS requires an argument.r�)rhr�r�r�s  r!�test_NoParamsForPASSz(BasicFTPServerTests.test_NoParamsForPASSZs<��
�K�K�*�*�:�6���'�'��C�D�TU�(�
�	
r#c����d�}|�jj_�jj	d�}�jddg|��|j�fd��}|S)zI
        Unexpected exceptions from the login handler are caught
        c�>�tjtd��S)Nztest exception�r�fail�AssertionError)r��kwargss  r!�_fake_loginhandlerz?BasicFTPServerTests.test_loginError.<locals>._fake_loginhandlerhs���:�:�n�-=�>�?�?r#r�zPASS barz5550 Requested action not taken: internal server errorr�c����j�}�jdt|���j|djt
�y)Nr�r��flushLoggedErrorsr��len�assertIsInstance�valuer��r��logsr s  �r!�	checkLogsz6BasicFTPServerTests.test_loginError.<locals>.checkLogsss=����)�)�+�D����Q��D�	�*��!�!�$�q�'�-�-��@r#)r\r�loginrhr�r�r�)r r�r?r�s`   r!�test_loginErrorz#BasicFTPServerTests.test_loginErrorcss���
	@�,>����"�"�(��K�K�*�*�:�6��� � ��
D�E��	!�	
�
���	A�
�	A�
�r#c�"�|j�S)z/
        Login with userid 'anonymous'
        )r�rs r!�test_AnonymousLoginz'BasicFTPServerTests.test_AnonymousLogin{s���#�#�%�%r#c�L�|j�}|jddg|��S)zm
        Issuing QUIT should return a 221 message.

        @return: L{Deferred} of command response
        �QUITz221 Goodbye.r��r�r�r�s  r!�	test_QuitzBasicFTPServerTests.test_Quit�s.��
� � �"���)�)�&�>�2B�RS�)�T�Tr#c�2�d|j_tj�}|jjj|tj�|jddg�}|jddg|��}|jddg|��}|S)	z�
        Reconfigure the server to disallow anonymous access, and to have an
        IUsernamePassword checker that always rejects.

        @return: L{Deferred} of command response
        Fr�z$331 Password required for anonymous.r�z!530 Sorry, Authentication failed.r�r�z$530 Please login with USER and PASS.)
r%�allowAnonymousrrurrrrryr�r�)r �denyAlwaysCheckerr?s   r!�test_AnonymousLoginDeniedz-BasicFTPServerTests.test_AnonymousLoginDenied�s���',����#�$�L�L�N�������+�+��{�<�<�	
�

�&�&��E�F�
��

�$�$�)�
0�1��
%�
��
�$�$��:�;�1�
%�
���r#c�L�|j�}|jddg|��S)z�
        When an anonymous user attempts to edit the server-side filesystem, they
        will receive a 550 error with a descriptive message.

        @return: L{Deferred} of command response
        z
MKD newdirz:550 Anonymous users are forbidden to change the filesystemr��r�r�r�s  r!�test_anonymousWriteDeniedz-BasicFTPServerTests.test_anonymousWriteDenied�s6��
� � �"���'�'��
I�J��(�
�	
r#c�L�|j�}|jddg|��S)z\
        Send an invalid command.

        @return: L{Deferred} of command response
        �	GIBBERISHz'502 Command 'GIBBERISH' not implementedr�rr�s  r!�test_UnknownCommandz'BasicFTPServerTests.test_UnknownCommand�s6��
� � �"���'�'��C�D�TU�(�
�	
r#c�L�|j�}|jddg|��S)zb
        Send RETR before sending PORT.

        @return: L{Deferred} of command response
        �RETR foozE503 Incorrect sequence of commands: PORT or PASV required before RETRr�rr�s  r!�test_RETRBeforePORTz'BasicFTPServerTests.test_RETRBeforePORT��<��
� � �"���'�'��4�
��
(�
�	
r#c�L�|j�}|jddg|��S)zb
        Send STOR before sending PORT.

        @return: L{Deferred} of command response
        zSTOR foozE503 Incorrect sequence of commands: PORT or PASV required before STORr�rr�s  r!�test_STORBeforePORTz'BasicFTPServerTests.test_STORBeforePORT�rr#c�z�|j�}|jddg|��|jddg|��|S)zd
        Send command with bad arguments.

        @return: L{Deferred} of command response
        zMODE zz&504 Not implemented for parameter 'z'.r�zSTRU Iz&504 Not implemented for parameter 'I'.rr�s  r!�test_BadCommandArgsz'BasicFTPServerTests.test_BadCommandArgs�sY��
� � �"��� � ��?�@�PQ�	!�	
�	
� � ��?�@�PQ�	!�	
��r#c�,�|jtjd�d�td�}td�D]V}t	|�}d||<djt
t|��}|jttj|��Xy)z%
        Decode a host port.
        z25,234,129,22,100,23)z
25.234.129.22id���,N)
r�r�decodeHostPort�range�list�join�map�str�assertRaises�
ValueError)r �nums�i�badValue�ss     r!�test_DecodeHostPortz'BasicFTPServerTests.test_DecodeHostPort�s���	
������5�6�8P�	
��Q�x���q��	A�A��D�z�H��H�Q�K�����S�(�+�,�A����j�#�*<�*<�a�@�		Ar#c����j�}|j�fd���fd�}|j|�|j�fd��|S)z�
        When the client sends the command C{PASV}, the server responds with a
        host and port, and is listening on that port.
        c�:���jjd�S)Nr�r���_r s �r!�<lambda>z/BasicFTPServerTests.test_PASV.<locals>.<lambda>s������ >� >�v� F�r#c���tj|ddd�\}}�j|�jjj�j�y)z�
            Extract the host and port from the resonse, and
            verify the server is listening of the port it claims to be.
            r��N)rrr�r\�dtpPortr}rL)r�rKrLr s   �r!�cbz)BasicFTPServerTests.test_PASV.<locals>.cb	sP���
�+�+�M�"�,=�a�b�,A�B�J�D�$����T�4�#6�#6�#>�#>�#F�#F�#H�#M�#M�Nr#c�L���jjj�Srr[r+s �r!r-z/BasicFTPServerTests.test_PASV.<locals>.<lambda>s���� 3� 3� =� =� L� L� N�r#�r�r��r r?r1s`  r!�	test_PASVzBasicFTPServerTests.test_PASV�sF���
� � �"��	�
�
�F�G�	O�	
�
�
�b��	�
�
�N�O��r#c�P�|j�}|jddg|��|S)z?
        SYST command will always return UNIX Type: L8
        r�z215 UNIX Type: L8r�rr�s  r!�	test_SYSTzBasicFTPServerTests.test_SYSTs1��
� � �"���"�"�6�,?�+@�PQ�"�R��r#c����jj�j�j��jj�j�jd�j	��j�}�j
ddg|���j
ddg|���fd�}|j|�|S)z�
        Sending the RNFR command followed by RNTO, with valid filenames, will
        perform a successful rename operation.
        �foo�RNFR foo�6350 Requested file action pending further information.r�zRNTO bar�&250 Requested File Action Completed OKc����j�jj�j�jd�j	��|S�N�bar)r�ro�childrv�exists�r�r s �r!�check_renamez:BasicFTPServerTests.test_RNFRandRNTO.<locals>.check_rename1s;����O�O�D�L�L�.�.�t�}�}�=�C�C�E�J�Q�Q�S�T��Mr#)ror@rv�createDirectory�touchr�r�r�)r r?rCs`  r!�test_RNFRandRNTOz$BasicFTPServerTests.test_RNFRandRNTOs����	
�����4�=�=�)�9�9�;������4�=�=�)�/�/��6�<�<�>��O�O����"�"��
E�F��	#�	
�
	
�"�"��A�B�RS�	#�	
�	�	
�
�
�l�#��r#c�z�|j�}|jddg|��|jddg|��|S)z�
        Sending the RNFR command followed by any command other than RNTO
        should return an error informing users that RNFR should be followed
        by RNTO.
        r:r;r�zOTHER don-tcarez<503 Incorrect sequence of commands: RNTO required after RNFR)r�r�r�r�s  r!�test_RNFRwithoutRNTOz(BasicFTPServerTests.test_RNFRwithoutRNTO8sY��
� � �"���"�"��
E�F��	#�	
�
	
� � ��
K�L��	!�	
�
�r#c��d�}||j_|jt|jjtj��y)z�
        Exceptions other than L{error.CannotListenError} which are raised by
        C{listenFactory} should be raised to the caller of L{FTP.getDTPPort}.
        c��t��r)�RuntimeError��
portNumberr%s  r!�
listenFactoryzEBasicFTPServerTests.test_portRangeForwardError.<locals>.listenFactoryQs
���.� r#N)r\rNr"rK�
getDTPPortr
�Factory)r rNs  r!�test_portRangeForwardErrorz.BasicFTPServerTests.test_portRangeForwardErrorKsA��	!�-:����)�����$�-�-�8�8�(�:J�:J�:L�	
r#c�"�d�}||j_|jjtj��}|j|d�t
dd�|j_|jjtj��}|j|d�t
dd�|j_|jtj|jjtj��y)a3
        L{FTP.passivePortRange} should determine the ports which
        L{FTP.getDTPPort} attempts to bind. If no port from that iterator can
        be bound, L{error.CannotListenError} should be raised, otherwise the
        first successful result from L{FTP.listenFactory} should be returned.
        c�<�|dvrtjd|d��|S)N)�ViViV�	localhostr)r�CannotListenErrorrLs  r!rNz9BasicFTPServerTests.test_portRange.<locals>.listenFactorybs&���2�2��-�-�k�:�w�O�O��r#rrTiiVN)r\rNrOr
rPr�r�passivePortRanger"rrV)r rNrLs   r!�test_portRangez"BasicFTPServerTests.test_portRangeZs���	�
-:����)��"�"�-�-�h�.>�.>�.@�A������q�!�/4�U�E�/B����,��"�"�-�-�h�.>�.>�.@�A������u�%�/4�U�E�/B����,�����#�#�T�%8�%8�%C�%C�X�EU�EU�EW�	
r#c��tdd�}||j_|jjd�}|j	||j
j�y)z�
        The L{FTP} instances created by L{ftp.FTPFactory.buildProtocol} have
        their C{passivePortRange} attribute set to the same object the
        factory's C{passivePortRange} attribute is set to.
        i�i�N)rr%rWr`r�ra)r �	portRanger
s   r!�"test_portRangeInheritedFromFactoryz6BasicFTPServerTests.test_portRangeInheritedFromFactoryusL���$��%�	�(1����%��<�<�-�-�d�3������H�$<�$<�$M�$M�Nr#c�f���jjd�}�fd�}|j|�S)z�
        When the server receives 'FEAT', it should report the list of supported
        features. (Additionally, ensure that the server reports various
        particular features that are supported by all Twisted FTP servers.)
        r�c�����jd|d��jd|��jd|��jd|��jd|��jd|d�y)	Nz
211-Features:rz MDTMz PASVz	 TYPE A;Iz SIZEz211 Endr�)r��assertIn)r�r s �r!r�z2BasicFTPServerTests.test_FEAT.<locals>.gotResponse�se������_�m�A�.>�?��M�M�'�=�1��M�M�'�=�1��M�M�+�}�5��M�M�'�=�1����Y�
�b�(9�:r#r�)r r?r�s`  r!�	test_FEATzBasicFTPServerTests.test_FEAT�s/���
�K�K�*�*�6�2��	;��}�}�[�)�)r#c�P�|j�}|jddg|��|S)z�
        When the server receives 'OPTS something', it should report
        that the FTP server does not support the option called 'something'.
        zOPTS somethingz'502 Option 'something' not implemented.r�rr�s  r!�	test_OPTSzBasicFTPServerTests.test_OPTS�s8��

� � �"��� � ��
6�7��	!�	
�
�r#c����jj�j�j��jj�j�jd�j��j	�}�fd�}�fd�}|j|�|j|��j
ddg|��|S)zl
        Any FTP error raised inside STOR while opening the file is returned
        to the client.
        �folderc�:���jjd�S)zE
            Send the PASV command required before port.
            r�r�rBs �r!�sendPASVzCBasicFTPServerTests.test_STORreturnsErrorFromOpen.<locals>.sendPASV�s����;�;�1�1�&�9�9r#c����jjjjd�t	��j_|S)z�
            Fake an incoming connection and create a mock DTPInstance so
            that PORT command will start processing the request.
            N)r\�
dtpFactoryr�rD�object�dtpInstancerBs �r!�mockDTPInstancezJBasicFTPServerTests.test_STORreturnsErrorFromOpen.<locals>.mockDTPInstance�s:���

���*�*�3�3�<�<�T�B�.4�h�D���+��Mr#zSTOR folderz550 folder: is a directoryr�)ror@rvrDr�r�r�)r r?rerjs`   r!�test_STORreturnsErrorFromOpenz1BasicFTPServerTests.test_STORreturnsErrorFromOpen�s����	
�����4�=�=�)�9�9�;������4�=�=�)�/�/��9�I�I�K��O�O���	:�	�	
�
�
�h��	�
�
�o�&�� � ��
)�*��	!�	
�
�r#c������j�}d���fd�}��fd�}�fd�}|j|�|j|��jddg|��|j|�|S)z�
        Any non FTP error raised inside STOR while opening the file is
        converted into FileNotFound error and returned to the client together
        with the path.

        The unknown error is logged.
        c�<�tjt��S)z�
            Override openForWriting.

            @param ignore: ignored, used for callback
            @return: an error
            r�)�ignores r!�failingOpenForWritingz[BasicFTPServerTests.test_STORunknownErrorBecomesFileNotFound.<locals>.failingOpenForWriting�s���:�:�n�.�/�/r#c�:���jjd�S)z
            Send the PASV command required before port.

            @param result: parameter used in L{Deferred}
            r�r�rBs �r!rezNBasicFTPServerTests.test_STORunknownErrorBecomesFileNotFound.<locals>.sendPASV�s����;�;�1�1�&�9�9r#c�����jjjjd�t	��j_��jj_|S)z�
            Fake an incoming connection and create a mock DTPInstance so
            that PORT command will start processing the request.

            @param result: parameter used in L{Deferred}
            N)r\rgr�rDrhri�shell�openForWriting)r�ror s ��r!rjzUBasicFTPServerTests.test_STORunknownErrorBecomesFileNotFound.<locals>.mockDTPInstance�sN���
���*�*�3�3�<�<�T�B�.4�h�D���+�7L�D���%�%�4��Mr#c����j�}�jdt|���j|djt
�y)zy
            Check that unknown errors are logged.

            @param result: parameter used in L{Deferred}
            r�rNr�r�s  �r!r�zOBasicFTPServerTests.test_STORunknownErrorBecomesFileNotFound.<locals>.checkLogs�s?����)�)�+�D����Q��D�	�*��!�!�$�q�'�-�-��@r#zSTOR somethingz)550 something: No such file or directory.r�)r�r�r�)r r?rerjr�ros`    @r!�(test_STORunknownErrorBecomesFileNotFoundz<BasicFTPServerTests.test_STORunknownErrorBecomesFileNotFound�sr���
�O�O���	0�	:�
	�	A�	
�
�
�h��	�
�
�o�&�� � ��
8�9��	!�	
�
	
�
�
�i� ��r#N)r5r6r7r�r�r�r�r�r�r�rrr	rrrrrr(r5r7rFrHrQrXr[r_rarkrur3r#r!r�r��s�����,6D�p
�
�
��0&�U��>
�	
�
� 
� 
�A��.��4�&

�
�6	O�*�$�"�H:r#r�c�@�eZdZdZej
Zd�Zd�Zd�Z	d�Z
y)�FTPServerAdvancedClientTestsz:
    Test FTP server with the L{ftp.FTPClient} class.
    c����fd�}�jjd�\}}|j|�tj||g�S)zl
        Try to make an STOR as anonymous, and check that we got a permission
        denied error.
        c���|jtj��j|jj
ddd�y)Nrz550 foo: Permission denied.)�traprr�r�r�r���resr s �r!�ebz;FTPServerAdvancedClientTests.test_anonymousSTOR.<locals>.eb
s8����H�H�S�&�&�'����S�Y�Y�^�^�A�.�q�1�3P�Qr#r9)rh�	storeFile�
addErrbackrr�)r r}rdr�s`   r!�test_anonymousSTORz/FTPServerAdvancedClientTests.test_anonymousSTORsD���	R����&�&�u�-���B�
�
�
�b���"�"�B��8�,�,r#c����Gd�dtj���fd�}�jtjd|��fd�}�jjd�\}}|j
|�tj||g�S)zm
        Any FTP error raised by STOR while transferring the file is returned
        to the client.
        c��eZdZd�Zy)�XFTPServerAdvancedClientTests.test_STORtransferErrorIsReturned.<locals>.FailingFileWriterc�R�tjtjd��S)N�failing_file�rr�r�IsADirectoryErrorrs r!�receivez`FTPServerAdvancedClientTests.test_STORtransferErrorIsReturned.<locals>.FailingFileWriter.receives���z�z�#�"7�"7��"G�H�Hr#N�r5r6r7r�r3r#r!�FailingFileWriterr�s��
Ir#r�c�:��tj�d��Sr�rr���a�br�s  �r!�failingSTORzRFTPServerAdvancedClientTests.test_STORtransferErrorIsReturned.<locals>.failingSTOR �����=�=�!2�4�!8�9�9r#rsc�L��|jtj��j�}�j	dt|���j
|djtj��j	|jjddd�y)Nr�rz 550 failing_file: is a directory)
rzrr�r�r�r�r�r�r�r��r|r�r s  �r!r}zIFTPServerAdvancedClientTests.test_STORtransferErrorIsReturned.<locals>.eb'sx����H�H�S�&�&�'��)�)�+�D����Q��D�	�*��!�!�$�q�'�-�-��1F�1F�G����S�Y�Y�^�^�A�.�q�1�3U�Vr#r��	r�_FileWriter�patch�FTPAnonymousShellrhr~rrr��r r�r}rdr�r�s`    @r!� test_STORtransferErrorIsReturnedz=FTPServerAdvancedClientTests.test_STORtransferErrorIsReturnedst���	I����	I�	:�
	
�
�
�3�(�(�*:�K�H�	W����&�&�~�6���B�
�
�
�b���"�"�B��8�,�,r#c����Gd�dtj���fd�}�jtjd|��fd�}�jjd�\}}|j
|�tj||g�S)z�
        Any non FTP error raised by STOR while transferring the file is
        converted into a critical error and transfer is closed.

        The unknown error is logged.
        c��eZdZd�Zy)�aFTPServerAdvancedClientTests.test_STORunknownTransferErrorBecomesAbort.<locals>.FailingFileWriterc�<�tjt��Srr�rs r!r�ziFTPServerAdvancedClientTests.test_STORunknownTransferErrorBecomesAbort.<locals>.FailingFileWriter.receive;s���z�z�.�"2�3�3r#Nr�r3r#r!r�r�:s��
4r#r�c�:��tj�d��Srr�r�s  �r!r�z[FTPServerAdvancedClientTests.test_STORunknownTransferErrorBecomesAbort.<locals>.failingSTOR>r�r#rsc�8��|jtj��j�}�j	dt|���j
|djt��j	|jjddd�y)Nr�rz.426 Transfer aborted.  Data connection closed.)
rzrr�r�r�r�r�r�r�r�r�s  �r!r}zRFTPServerAdvancedClientTests.test_STORunknownTransferErrorBecomesAbort.<locals>.ebEsu����H�H�S�&�&�'��)�)�+�D����Q��D�	�*��!�!�$�q�'�-�-��@�����	�	���q�!�!�$�&V�
r#r�r�r�s`    @r!�)test_STORunknownTransferErrorBecomesAbortzFFTPServerAdvancedClientTests.test_STORunknownTransferErrorBecomesAbort2sq���	4����	4�	:�
	
�
�
�3�(�(�*:�K�H�	����&�&�~�6���B�
�
�
�b���"�"�B��8�,�,r#c����Gd�dtj���fd�}�jtjd|��fd�}t	�}�j
j
d|�}|j|�|S)zj
        Any errors during reading a file inside a RETR should be returned to
        the client.
        c��eZdZd�Zy)�JFTPServerAdvancedClientTests.test_RETRreadError.<locals>.FailingFileReaderc�R�tjtjd��S)N�blahr�)r �consumers  r!�sendzOFTPServerAdvancedClientTests.test_RETRreadError.<locals>.FailingFileReader.sendZs���z�z�#�"7�"7��"?�@�@r#N)r5r6r7r�r3r#r!�FailingFileReaderr�Ys��
Ar#r�c�:��tj�d��Srr�)r�r�r�s  �r!�failingRETRzDFTPServerAdvancedClientTests.test_RETRreadError.<locals>.failingRETR]r�r#�openForReadingc����j�|jtj��j	|j
jddd��j	|j
jddd�y)Nrz3125 Data connection already open, starting transferr�z550 blah: is a directory)r�rzrr�r�r�r�)rr s �r!�check_responsezGFTPServerAdvancedClientTests.test_RETRreadError.<locals>.check_responsedsr����"�"�$��G�L�L��*�*�+�����
�
�"�"�1�%�a�(�E�
�
���W�]�]�/�/��2�1�5�7Q�Rr#r�)r�_FileReaderr�r�r:rh�retrieveFiler)r r�r�r�r?r�s`    @r!�test_RETRreadErrorz/FTPServerAdvancedClientTests.test_RETRreadErrorRsj���	A����	A�	:�
	
�
�
�3�(�(�*:�K�H�	S�#�$���K�K�$�$�^�U�;��	���^�$��r#N)r5r6r7r�r�	FTPClientrr�r�r�r�r3r#r!rwrws'����M�M�M�-�-�:-�@r#rwc�n�eZdZdZdd�Zdd�Zd�Zd�Zd�Zd�Z	d	�Z
d
�Zd�Zd�Z
d
�Zd�Zd�Zd�Zd�Zy)� FTPServerPasvDataConnectionTestsz
    PASV data connection.
    Nc�`�|jjd�}d�}|j|�S)z�
        Establish a passive data connection (i.e. client connecting to
        server).

        @param ignored: ignored
        @return: L{Deferred.addCallback}
        r�c��tj|ddd�\}}tjtt
�}|j
d|�S)Nr�r/rV)rrr
r~rr:r�)r�rKrLr�s    r!�gotPASVzEFTPServerPasvDataConnectionTests._makeDataConnection.<locals>.gotPASV�sF���+�+�M�"�,=�a�b�,A�B�J�D�$��'�'��1C�D�B��=�=��d�3�3r#r�)r r�r?r�s    r!�_makeDataConnectionz4FTPServerPasvDataConnectionTests._makeDataConnectionxs.��
�K�K�*�*�6�2��	4�
�}�}�W�%�%r#c����|�tjd�}|j�j���fd�}|j|�d�}|j|�S)z�
        Download file.

        @param command: command to run
        @param chainDeferred: L{Deferred} used to queue commands.
        @return: L{Deferred} of command response
        Nc����jj��}|j}tj||g�Sr)rhr�r?rr�)�
downloaderrdr�r�r s   ��r!r�z@FTPServerPasvDataConnectionTests._download.<locals>.queueCommand�s7������/�/��8�B����B��&�&��B�x�0�0r#c�$�|\}}|jSrrA)r�r�r�s   r!�downloadDonez@FTPServerPasvDataConnectionTests._download.<locals>.downloadDone�s��$*�!�W�j��$�$�$r#)rr�r�r�)r r�r�r�r�s``   r!�	_downloadz*FTPServerPasvDataConnectionTests._download�sZ���� �!�M�M�$�/�M��!�!�$�":�":�;�	1�	�!�!�,�/�	%��(�(��6�6r#c�v���j�}�jd|���fd�}|j|�S)zM
        When listing empty folders, LIST returns an empty response.
        r�r�c�*���jd|�yr<r�rBs �r!�
checkEmptyzCFTPServerPasvDataConnectionTests.test_LISTEmpty.<locals>.checkEmpty�s������S�&�)r#�r�r�r�)r r?r�s`  r!�test_LISTEmptyz/FTPServerPasvDataConnectionTests.test_LISTEmpty�s;���
� � �"��	
���v�Q��/�	*��}�}�Z�(�(r#c�j��tjtjj�jd��tjtjj�jd���j�}�j
d|���fd�}|j|�S)z}
        LIST ignores requests for folder with names like '-al' and will list
        the content of current folder.
        r9r?zLIST -aLr�c���g}|j�D]%}|j|jd�d��'�jdt	|���jd|��jd|�y)N� r���foo�bar)�
splitlinesr)�splitr�r�r^)�download�namesr+r s   �r!�
checkDownloadzOFTPServerPasvDataConnectionTests.test_LISTWithBinLsFlags.<locals>.checkDownload�sj����E� �+�+�-�
3�����T�Z�Z��-�b�1�2�
3����Q��E�
�+��M�M�&�%�(��M�M�&�%�(r#�rlrm�pathrrkr�r�r��r r?r�s`  r!�test_LISTWithBinLsFlagsz8FTPServerPasvDataConnectionTests.test_LISTWithBinLsFlags�sy���
	��������d�n�n�e�4�5�
��������d�n�n�e�4�5�
� � �"�����z���3�	)��}�}�]�+�+r#c���tjtjj�jd��tjtjj�jd���j�}�j
d|���fd�}|j|��j
d|���fd�}|j|��j
d|���fd	�}|j|��fd
�}|j|��j
d|���fd�}|j|�S)z�
        LIST returns all folder's members, each member listed on a separate
        line and with name and other details.
        r9r?r�r�c�`���jdt|ddjd���y)Nr�����
)r�r�r��r�r s �r!r�zLFTPServerPasvDataConnectionTests.test_LISTWithContent.<locals>.checkDownload�s)������Q��H�S�b�M�$7�$7��$@� A�Br#�NLST c�v��|ddjd�}|j��jddg|�y)Nr�r�r�r��r��sortr��r��	filenamesr s  �r!r�zLFTPServerPasvDataConnectionTests.test_LISTWithContent.<locals>.checkDownload�s8��� ��"�
�+�+�G�4�I��N�N�����f�f�-�y�9r#zLIST fooc�*���jd|�yr<r�r�s �r!r�zLFTPServerPasvDataConnectionTests.test_LISTWithContent.<locals>.checkDownload��������S�(�+r#c�:���jjd�S)NzCWD foor�)r�r s �r!�chdirzDFTPServerPasvDataConnectionTests.test_LISTWithContent.<locals>.chdir�s����;�;�1�1�)�<�<r#c�*���jd|�yr<r�r�s �r!r�zLFTPServerPasvDataConnectionTests.test_LISTWithContent.<locals>.checkDownload�r�r#r�)r r?r�r�s`   r!�test_LISTWithContentz5FTPServerPasvDataConnectionTests.test_LISTWithContent�s����
	��������d�n�n�e�4�5�
��������d�n�n�e�4�5�
� � �"��	
���v�Q��/�	C�	
�
�
�m�$�	
���w�a��0�	:�
	
�
�
�m�$�	
���z���3�	,�	
�
�
�m�$�	=�	
�
�
�e��	
���v�Q��/�	,��}�}�]�+�+r#c�������j�}d�fd�	���fd�}|j|��j|�d�|�����fd�}|j|�S)a5
        Exercise handling by the implementation of I{LIST} or I{NLST} of certain
        return values and types from an L{IFTPShell.list} implementation.

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

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

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

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

        @return: A L{Deferred} which fires when the test is done, either with an
            L{Failure} if the test failed or with a function object if it
            succeeds.  The function object is the function which implements
            L{IFTPShell.list} (and is useful to make assertions about what
            warnings might have been emitted).
        @rtype: L{Deferred}
        c�0��tj�g�Srr�)�segments�keys�
listOutputs  �r!�patchedListzEFTPServerPasvDataConnectionTests._listTestHelper.<locals>.patchedLists����=�=�*��.�.r#c�>����jj_|Sr)r\rrr)r�r�r s ��r!�loggedInzBFTPServerPasvDataConnectionTests._listTestHelper.<locals>.loggedIn"s���-8�D���%�%�*��Mr#z
 somethingr�c�,���j�|��Srr�)r��expectedOutputr�r s ���r!r�zGFTPServerPasvDataConnectionTests._listTestHelper.<locals>.checkDownload*s������^�X�6��r#)r3)r�r�r�)r r�r�r�r?r�r�r�s` ``   @r!�_listTestHelperz0FTPServerPasvDataConnectionTests._listTestHelper�sX���<
� � �"��	/�	�	
�
�
�h�����'��*�-�Q��?�	��}�}�]�+�+r#c�`�|jddddtjd�ddddffd�S)	z�
        Unicode filenames returned from L{IFTPShell.list} are encoded using
        UTF-8 before being sent with the response.
        r��
my resumérr���user�group�Ldrwxrwxrwx   0 user      group                   0 Jan 01  1970 my resumé
�r�r�Permissionsrs r!�test_LISTUnicodez1FTPServerPasvDataConnectionTests.test_LISTUnicode0sD��
�#�#����A�x�+�+�E�2�A�q�&�'�J�
�
3�

�	
r#c�`�|jddddtjd�ddddffd�S)	z�
        When LIST receive a filename as byte string from L{IFTPShell.list}
        it will just pass the data to lower level without any change.

        @return: L{_listTestHelper}
        r��
my resumérr�r�r�r�r�r�rs r!�test_LISTNonASCIIBytesz7FTPServerPasvDataConnectionTests.test_LISTNonASCIIBytes?sD���#�#��#��A�x�+�+�E�2�A�q�&�'�J�
�
3�

�	
r#c�l���j�}tddd�D]�}ttjj�jd|fz�d�5}|jd|z�ddd��jd|fz|�	�|f�fd
�	}|j|���|S#1swY�<xYw)zJ
        Download many large files.

        @return: L{Deferred}
        i��i��i�z%d.txt�wb�xNzRETR %d.txtr�c�<���j|t|��yr�r�r�)r��sizer s  �r!r�zOFTPServerPasvDataConnectionTests.test_ManyLargeDownloads.<locals>.checkDownload`s���� � ��s�8�}�5r#)
r�r�openrlr�rrk�writer�r�)r r?r��fObjr�s`    r!�test_ManyLargeDownloadsz8FTPServerPasvDataConnectionTests.test_ManyLargeDownloadsPs����
� � �"���&�&�#�.�		)�D��b�g�g�l�l�4�>�>�8�t�g�3E�F��M�
(�QU��
�
�4�$�;�'�
(�
�N�N�=�D�7�2�!�N�D�-1�
6�
�M�M�-�(�		)���
(�
(�s�B*�*B3	c�0���jjd�j��j�}|j	�j
��fd�}|j	|�d�}|j	|��fd�}|j
|�|S)zo
        When RETR is called for a folder, it will fail complaining that
        the path is a folder.
        r9c�r��|jj��jjd�}|S)Nr)r]r^rhr�)r�r�r s  �r!�
retrFolderzHFTPServerPasvDataConnectionTests.test_downloadFolder.<locals>.retrFolderqs.���� � �/�/�1��{�{�5�5�j�A�H��Or#c��td��)Nz(Downloading a folder should not succeed.)r�)r�s r!�
failOnSuccesszKFTPServerPasvDataConnectionTests.test_downloadFolder.<locals>.failOnSuccessxs�� �!K�L�Lr#c����|jtj��jdg|jj
d��j
�}�jdt|�d�y)Nz550 foo: is a directoryrz6No errors should be logged while downloading a folder.)rzrr�r�r�r�r�r�)r�current_errorsr s  �r!�
checkErrorzHFTPServerPasvDataConnectionTests.test_downloadFolder.<locals>.checkError}sd����G�L�L��*�*�+����7�8�'�-�-�:L�:L�Q�:O�P�!�3�3�5�N������N�#�H�
r#)ror@rDr�r�r�r)r r?rrrs`    r!�test_downloadFolderz4FTPServerPasvDataConnectionTests.test_downloadFolderfs���	
�����5�!�1�1�3�� � �"��	�
�
�d�.�.�/�	�
	
�
�
�j�!�	M�	
�
�
�m�$�	�	
���Z� ��r#c����j�}�jjd�j��jjd�j	��jd|���fd�}|j
|�S)zp
        NLST with no argument returns the directory listing for the current
        working directory.
        �test.txtr9r�r�c�v��|ddjd�}|j��jddg|�y)Nr�r�r��test.txtr�r�s  �r!r�zFFTPServerPasvDataConnectionTests.test_NLSTEmpty.<locals>.checkDownload�s8��� ��"�
�+�+�G�4�I��N�N�����f�k�2�I�>r#)r�ror@rErDr�r�r�s`  r!�test_NLSTEmptyz/FTPServerPasvDataConnectionTests.test_NLSTEmpty�sq���
� � �"��	
�����:�&�,�,�.������5�!�1�1�3����w�a��0�	?�
�}�}�]�+�+r#c�v���j�}�jd|���fd�}|j|�S)zH
        NLST on a non-existent file/directory returns nothing.
        zNLST nonexistent.txtr�c�*���jd|�yr<r�r�s �r!r�zLFTPServerPasvDataConnectionTests.test_NLSTNonexistent.<locals>.checkDownload�r�r#r�r�s`  r!�test_NLSTNonexistentz5FTPServerPasvDataConnectionTests.test_NLSTNonexistent�s:���

� � �"�����-�Q��?�	,��}�}�]�+�+r#c�`�|jddddtjd�ddddffd�S)	zs
        NLST will receive Unicode filenames for IFTPShell.list, and will
        encode them using UTF-8.
        �NLSTr�rr�r�r�r��my resumé
r�rs r!�test_NLSTUnicodez1FTPServerPasvDataConnectionTests.test_NLSTUnicode�sD��
�#�#����A�x�+�+�E�2�A�q�&�'�J�
�
$�

�	
r#c�`�|jddddtjd�ddddffd�S)	zJ
        NLST will just pass the non-Unicode data to lower level.
        rr�rr�r�r�r�rr�rs r!�test_NLSTNonASCIIBytesz7FTPServerPasvDataConnectionTests.test_NLSTNonASCIIBytes�sD���#�#��#��A�x�+�+�E�2�A�q�&�'�J�
�
$�

�	
r#c�����j�}�jjd�j��j	d|���fd�}|j|�S)zN
        NLST on an existent file returns only the path to that file.
        rz
NLST test.txtr�c�T��|ddjd�}�jdg|�y)Nr�r�r)r�r�r�s  �r!r�zMFTPServerPasvDataConnectionTests.test_NLSTOnPathToFile.<locals>.checkDownload�s+��� ��"�
�+�+�G�4�I����k�]�I�6r#)r�ror@rEr�r�r�s`  r!�test_NLSTOnPathToFilez6FTPServerPasvDataConnectionTests.test_NLSTOnPathToFile�sV���

� � �"��	
�����:�&�,�,�.�����a��8�	7��}�}�]�+�+r#r)r5r6r7r�r�r�r�r�r�r�r�r�rrrrrrrr3r#r!r�r�ssU���&�"7�8)�,�.3,�j/,�b

�
�"�,"�H,�,,�
�
�,r#r�c�,�eZdZd�Zdd�Zd�Zd�Zd�Zy)� FTPServerPortDataConnectionTestsc�:�g|_tj|�Sr)�	dataPortsr�r�rs r!r�z&FTPServerPortDataConnectionTests.setUp�s�����/�5�5�d�;�;r#Nc�n��tj��G�fd�dtj�}t	j
d|�d��}|jj|�dtjd|j�j�z}|jj|��S)Nc���eZdZeZ�fd�Zy)�IFTPServerPortDataConnectionTests._makeDataConnection.<locals>.DataFactoryc���tjj||�}tjd�j
|�|Sr�)r
�
ServerFactoryr`r�	callLaterrD)r rcr�r�s   �r!r`zWFTPServerPortDataConnectionTests._makeDataConnection.<locals>.DataFactory.buildProtocol�s8����*�*�8�8��t�D���!�!�!�X�%6�%6��:��r#N)r5r6r7r:r
r`)r�s�r!�DataFactoryr$�s
���)�H�
r#r(rrVrW�PORT )rr>r
r&rr{r!r)rrHr}rLrhr�)r r�r(�dataPort�cmdr�s     @r!r�z4FTPServerPortDataConnectionTests._makeDataConnection�s�����>�>�#��	�(�0�0�	��$�$�Q��
��M�������h�'���*�*�;��8H�8H�8J�8O�8O�P�P�����&�&�s�+��r#c��|jD�cgc]!}tj|j���#}}tjtj
|�}|j
|�tj|d��Scc}w)zS
        Tear down the connection.

        @return: L{defer.DeferredList}
        Tr�)r!r�
maybeDeferredr|r��tearDownr)r�)r rL�lr?s    r!r.z)FTPServerPortDataConnectionTests.tearDown�sk��BF���P��U�
 �
 ��!3�!3�
4�P��P���� @� I� I�4�P��	������!�!�!�d�;�;��
Qs�&Bc�x���j�}d�}|j|��fd�}|j|�S)z�
        Listen on a port, and immediately stop listening as a way to find a
        port number that is definitely closed.
        c����tjdtj�d��}|j	�j
�|j
�}|j�fd��|S)NrrVrWc����Srr3)r,r�s �r!r-z[FTPServerPortDataConnectionTests.test_PORTCannotConnect.<locals>.loggedIn.<locals>.<lambda>s���G�r#)rr{r
rPr}rLr|r�)r�rLr?r�s   @r!r�zIFTPServerPortDataConnectionTests.test_PORTCannotConnect.<locals>.loggedInsQ����$�$�Q��(8�(8�(:�k�R�D��l�l�n�)�)�G��"�"�$�A�
�M�M�+�,��Hr#c�X���jdtjd|�zdg�S)Nr)rVz425 Can't open data connection.)r�rrH)r�r s �r!�
gotPortNumzKFTPServerPortDataConnectionTests.test_PORTCannotConnect.<locals>.gotPortNums1����+�+��#�,�,�[�'�B�B�2�3��
r#r3)r r?r�r4s`   r!�test_PORTCannotConnectz7FTPServerPortDataConnectionTests.test_PORTCannotConnect�s<���
� � �"��	�	
�
�
�h��	��}�}�Z�(�(r#c�l���jjd�j��jjd�j��jjd�j��j�}�j	d|���fd�}|j|�S)zv
        When Unix shell globbing is used with NLST only files matching the
        pattern will be returned.
        rzceva.txtzno.matchz
NLST *.txtr�c�v��|ddjd�}|j��jddg|�y)Nr�r�sceva.txtrr�r�s  �r!r�zIFTPServerPortDataConnectionTests.test_nlstGlobbing.<locals>.checkDownload&s8��� ��"�
�+�+�G�4�I��N�N�����k�;�7��Cr#)ror@rEr�r�r�r�s`  r!�test_nlstGlobbingz2FTPServerPortDataConnectionTests.test_nlstGlobbings����
	
�����:�&�,�,�.������:�&�,�,�.������:�&�,�,�.�� � �"�����|�1��5�	D�
�}�}�]�+�+r#r)r5r6r7r�r�r.r5r8r3r#r!rr�s��<��&	<�)�6,r#rc�:�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
y	)
�DTPFactoryTestsz&
    Tests for L{ftp.DTPFactory}.
    c���tj�|_Gd�d�}|�|_t	j
|jd|j�|_y)zf
        Create a fake protocol interpreter and a L{ftp.DTPFactory} instance to
        test.
        c��eZdZdZy)�2DTPFactoryTests.setUp.<locals>.ProtocolInterpreterN�r5r6r7rir3r#r!�ProtocolInterpreterr=:����Kr#r?N)r�Clockr�protocolInterpreterr�
DTPFactoryr%�r r?s  r!r�zDTPFactoryTests.setUp3sF��
�z�z�|���	�	�$7�#8�� ��~�~�d�&>�&>��d�l�l�S��r#c���g}|j|jjtj�}|j|j�|jjd�|jjd�|j|�|jjd�|j|�|j|jj�y)z�
        L{ftp.DTPFactory.setTimeout} uses the reactor passed to its initializer
        to set up a timed event to time out the DTP setup after the specified
        number of seconds.
        r�r�N)
r�r%r�r�PortConnectionErrorr�r)�
setTimeoutr�advancer�r��calls�r �finishedr?s   r!�test_setTimeoutzDTPFactoryTests.test_setTimeout@s��������t�|�|�4�4�c�6M�6M�N��	�
�
�h�o�o�&�������"�	
�����Q��	
����"�	
�����Q��	
����!�	
������+�+�,r#c���|jjd�}|j|tj�|j|jjd��y)z�
        A L{ftp.DTPFactory} instance's C{buildProtocol} method can be used once
        to create a L{ftp.DTP} instance.
        N)r%r`r�r�DTP�assertIsNone)r r
s  r!�test_buildProtocolOncez&DTPFactoryTests.test_buildProtocolOnce]sK��
�<�<�-�-�d�3�����h����0�	
���$�,�,�4�4�T�:�;r#c��|jjd�|jjd�|j|jj
�y)z�
        If a timeout has been set up using L{ftp.DTPFactory.setTimeout}, it is
        cancelled by L{ftp.DTPFactory.buildProtocol}.
        �
N)r%rHr`r�rrJrs r!�test_timeoutAfterConnectionz+DTPFactoryTests.test_timeoutAfterConnectionhs@��
	
������#����"�"�4�(�������+�+�,r#c�.�|j|jjtj�}|jjd�|jjd�|j|jjd��|S)z�
        If L{ftp.DTPFactory.buildProtocol} is called after the timeout
        specified by L{ftp.DTPFactory.setTimeout} has elapsed, L{None} is
        returned.
        rSN)
r�r%r�rrGrHrrIrPr`r�s  r!�test_connectionAfterTimeoutz+DTPFactoryTests.test_connectionAfterTimeoutrsr��
���t�|�|�4�4�c�6M�6M�N��	
������#������R� �	
���$�,�,�4�4�T�:�;��r#c��g}|j|jjtj�}|j|j�|jjd�|j|�|jjdd�|j|�|jjd�|S)a
        L{ftp.DTPFactory.deferred} fails with L{PortConnectionError} when
        L{ftp.DTPFactory.clientConnectionFailed} is called.  If the timeout
        specified with L{ftp.DTPFactory.setTimeout} expires after that, nothing
        additional happens.
        rSN)
r�r%r�rrGr�r)rHr��clientConnectionFailedr�rrIrKs   r!�!test_timeoutAfterConnectionFailedz1DTPFactoryTests.test_timeoutAfterConnectionFailed�s��������t�|�|�4�4�c�6M�6M�N��	�
�
�h�o�o�&�������#�����"����+�+�D�$�7�����!������R� ��r#c�8�|j|jjtj�}|jjd�|jjd�|jjdtjd��|S)z�
        If L{ftp.DTPFactory.clientConnectionFailed} is called after the timeout
        specified by L{ftp.DTPFactory.setTimeout} has elapsed, nothing beyond
        the normal timeout before happens.
        rSNr9)r�r%r�rrGrHrrIrXr�TimeoutErrorr�s  r!�!test_connectionFailedAfterTimeoutz1DTPFactoryTests.test_connectionFailedAfterTimeout�st��
���t�|�|�4�4�c�6M�6M�N��	
������#������R� �	
���+�+�D�%�2D�2D�U�2K�L��r#N)r5r6r7r�r�rMrQrTrVrYr\r3r#r!r:r:.s+���T�-�:	<�-��(�$r#r:c��eZdZdZd�Zd�Zy)�DTPTestszx
    Tests for L{ftp.DTP}.

    The DTP instances in these tests are generated using
    DTPFactory.buildProtocol()
    c���tj�|_Gd�d�}|�|_t	j
|jd|j�|_tj�|_	y)z�
        Create a fake protocol interpreter, a L{ftp.DTPFactory} instance,
        and dummy transport to help with tests.
        c��eZdZdZy)�+DTPTests.setUp.<locals>.ProtocolInterpreterNr>r3r#r!r?ra�r@r#r?N)
rrArrBrrCr%r� StringTransportWithDisconnectionr]rDs  r!r�zDTPTests.setUp�sV��
�z�z�|���	�	�$7�#8�� ��~�~�d�&>�&>��d�l�l�S���&�G�G�I��r#c���|jjd�}|j|j�d}|j	|�|jj�}|j
|dz|�y)zr
        L{ftp.DTP.sendLine} writes the line passed to it plus a line delimiter
        to its transport.
        Nsline contentr�)r%r`�makeConnectionr]�sendLiner�r�)r ri�lineContent�dataSents    r!�test_sendLineNewlinezDTPTests.test_sendLineNewline�sd��
�l�l�0�0��6���"�"�4�>�>�2�%�����[�)��>�>�'�'�)������w�.��9r#N)r5r6r7r�r�rhr3r#r!r^r^�s���J�:r#r^c��eZdZdZd�Zd�Zy)�
PrintLinesz3
    Helper class used by FTPFileListingTests.
    c��||_yr)�_lines)r rs  r!r"zPrintLines.__init__�s	����r#c��|jD]/}|jj|jd�dz��1|jj	�y)Nzlatin-1r�)rlr]rrIr^r*s  r!r'zPrintLines.connectionMade�sG���K�K�	C�D��N�N� � ����Y�!7�'�!A�B�	C����%�%�'r#N)r5r6r7r�r"r'r3r#r!rjrj�s����(r#rjc��eZdZd�Zd�Zy)�MyFTPFileListProtocolc�P�g|_tjj|�yr)�otherr�FTPFileListProtocolr"rs r!r"zMyFTPFileListProtocol.__init__�s����
����(�(��.r#c�:�|jj|�yr)rqr)r*s  r!�unknownLinez!MyFTPFileListProtocol.unknownLine�r-r#N)r5r6r7r"rtr3r#r!roro�s��/� r#roc�6�eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	y)	�FTPFileListingTestsc���t��tjt|���}|j	�fd��|S)Nc�4���j�jfSr)�filesrq)r,�fileLists �r!r-z6FTPFileListingTests.getFilesForLines.<locals>.<lambda>�s��������� @�r#)ror�
loopbackAsyncrjr�)r rr?rzs   @r!�getFilesForLinesz$FTPFileListingTests.getFilesForLines�s4���(�*���"�"�:�e�#4�h�?��	�
�
�@�A��r#c�T��d}�fd�}�j|g�j|�S)z�
        This example line taken from the docstring for FTPFileListProtocol

        @return: L{Deferred} of command response
        z<-rw-r--r--   1 root     other        531 Jan 29 03:26 READMEc���|\\}}�j|dt|�����j|ddk(d��j|ddk(d��j|dd	k(d��j|d
dk(d��j|dd
k(d��j|ddk(d��j|ddk(d��j|ddk(d��j|dd�y)Nzunexpect unparsable lines: �filetype�-�misparsed fileitem�perms�	rw-r--r--�misparsed perms�owner�rootr�rqr���date�Jan 29 03:26�filename�README�nlinksr��misparsed nlinks�
linktarget�misparsed linktarget)r��reprr�)�	fileOther�filerqr s   �r!�checkz/FTPFileListingTests.test_OneLine.<locals>.check�s���(��W�d�e����U�&A�$�u�+��$O�P��O�O�D��,��3�5I�J��O�O�D��M�[�8�:K�L��O�O�D��M�V�3�5I�J��O�O�D��M�W�4�6J�K��O�O�D��L�C�/�1E�F��O�O�D��L�N�:�<P�Q��O�O�D��,��8�:N�O��O�O�D��N�a�/�1C�D����T�,�/�1G�Hr#�r|r�)r r+r�s`  r!�test_OneLinez FTPFileListingTests.test_OneLine�s1���N��	I��$�$�d�V�,�8�8��?�?r#c�`��d}d}d}�fd�}�j|||g�j|�S)z 
        Variant lines.
        z7drw-r--r--   2 root     other        531 Jan  9  2003 Az<lrw-r--r--   1 root     other          1 Jan 29 03:26 B -> Azwoohoo! c���|\\}}\}�j|dk(d��j|ddk(d��j|ddk(d��j|d	d
k(d��j|dd
k(d��j|ddk(d��j|ddk(d��j|ddk(d��j|ddk(d��j|dd��j|ddk(d��j|ddk(d��j|d	d
k(d��j|dd
k(d��j|ddk(d��j|ddk(d��j|dd k(d��j|ddk(d��j|ddk(d�y)!Nz	woohoo! 
zincorrect other linerr?r�r�r�r�r�r�zmisparsed ownerr�rqzmisparsed groupr�r�zmisparsed sizer�zJan  9  2003zmisparsed dater��A�misparsed filenamer�r�r�r�r�r/r�r��B)r�r�)r��file1�file2rqr s    �r!r�z4FTPFileListingTests.test_VariantLines.<locals>.checks����)/�&�^�e�U�X�e��O�O�E�\�1�3I�J��O�O�E�*�-��4�6J�K��O�O�E�'�N�k�9�;L�M��O�O�E�'�N�f�4�6G�H��O�O�E�'�N�g�5�7H�I��O�O�E�&�M�S�0�2B�C��O�O�E�&�M�^�;�=M�N��O�O�E�*�-��4�6J�K��O�O�E�(�O�q�0�2D�E����U�<�0�2H�I��O�O�E�*�-��4�6J�K��O�O�E�'�N�k�9�;L�M��O�O�E�'�N�f�4�6G�H��O�O�E�'�N�g�5�7H�I��O�O�E�&�M�Q�.�0@�A��O�O�E�&�M�^�;�=M�N��O�O�E�*�-��4�6J�K��O�O�E�(�O�q�0�2D�E��O�O�E�,�/�3�6�8N�Or#r�)r �line1�line2�line3r�s`    r!�test_VariantLinesz%FTPFileListingTests.test_VariantLiness@���J��N����	P�0�$�$�e�U�E�%:�;�G�G��N�Nr#c�R���fd�}�jddg�j|�S)z 
        Unknown lines.
        c�z��|\}}�j|d��j|ddgk(dt|�z�y)Nzunexpected file entrieszABC
znot a file
zincorrect unparsable lines: %s)r�r�r��r�ry�othersr s   �r!r�z3FTPFileListingTests.test_UnknownLine.<locals>.check3sB���$�O�U�F����U�$=�>��O�O��7�N�3�3�0�4��<�?�
r#�ABCz
not a filer�)r r�s` r!�test_UnknownLinez$FTPFileListingTests.test_UnknownLine.s+���
	��$�$�e�\�%:�;�G�G��N�Nr#c�Z��d}d}�fd�}�j||g�j|�S)ze
        Will parse filenames and linktargets containing unescaped
        space characters.
        z9drw-r--r--   2 root     other        531 Jan  9  2003 A BzDlrw-r--r--   1 root     other          1 Jan 29 03:26 B A -> D C/A Bc����|\}}�jg|d��jd|ddd��jd|ddd��jd|dd	d
�y�Nzunexpected others entrieszA Brr�r�zB Ar�zD C/A Br�r�r�r�s   �r!r�zBFTPFileListingTests.test_filenameWithUnescapedSpace.<locals>.checkG�s���$�O�U�F����R��)D�E����U�E�!�H�Z�$8�:N�O����U�E�!�H�Z�$8�:N�O����Y��a���(>�@V�Wr#r��r r�r�r�s`   r!�test_filenameWithUnescapedSpacez3FTPFileListingTests.test_filenameWithUnescapedSpace=s;���
L��U�	�	X��$�$�e�U�^�4�@�@��G�Gr#c�Z��d}d}�fd�}�j||g�j|�S)zc
        Will parse filenames and linktargets containing escaped
        space characters.
        z:drw-r--r--   2 root     other        531 Jan  9  2003 A\ BzElrw-r--r--   1 root     other          1 Jan 29 03:26 B A -> D\ C/A Bc����|\}}�jg|d��jd|ddd��jd|ddd��jd|dd	d
�yr�r�r�s   �r!r�z@FTPFileListingTests.test_filenameWithEscapedSpace.<locals>.checkZr�r#r�r�s`   r!�test_filenameWithEscapedSpacez1FTPFileListingTests.test_filenameWithEscapedSpacePs;���
N��W�	�	X��$�$�e�U�^�4�@�@��G�Gr#c������tj��d�G�fd�dtj�}��fd�}t	j
|���}|j
|�S)z{
        This example derived from bug description in issue 514.

        @return: L{Deferred} of command response
        s<-rw-r--r--   1 root     other        531 Jan 29 2003 README
c���eZdZ�fd�Zy)�0FTPFileListingTests.test_Year.<locals>.PrintLinec�p��|jj��|jj�yr)r]rr^)r �exampleLines �r!r'z?FTPFileListingTests.test_Year.<locals>.PrintLine.connectionMadems%������$�$�[�1����-�-�/r#N)r5r6r7r')r�s�r!�	PrintLiner�ls���
0r#r�c����jd}�j|ddk(d��j|ddk(d��j|ddk(d�y)	Nrr�r�r�r�zJan 29 2003r�r�)ryr�)r�r�rzr s  ��r!r�z,FTPFileListingTests.test_Year.<locals>.checkqsZ����>�>�!�$�D��O�O�D��L�C�/�1E�F��O�O�D��L�M�9�;O�P��O�O�D��,��8�:N�Or#)rrrr
�Protocolrr{r�)r r�r�r?r�rzs`   @@r!�	test_YearzFTPFileListingTests.test_YearcsU����*�*�,��V��	0��)�)�	0�
	P�
�"�"�9�;��9���}�}�U�#�#r#N)
r5r6r7r|r�r�r�r�r�r�r3r#r!rvrv�s+���@�. O�D
O�H�&H�&$r#rvc��eZdZdZd�Zd�Zy)�1FTPClientFailedRETRAndErrbacksUponDisconnectTestsz:
    FTP client fails and RETR fails and disconnects.
    c����tj�}d|_tjd|d��}|j|j�|j�j}ddddd|d	z	|d
zfzdg��fd�|_	tjttjd
��}|jd|�}d�}|j|�|j|tj �S)z
        RETR fails.
        rrVrWz1220 ready, dude (vsFTPd 1.0.0: beat me, break me)z 331 Please specify the password.z230 Login successful. Have fun.z200 Binary it is, then.z+227 Entering Passive Mode (127,0,0,1,%d,%d)��z550 Failed to open file.c���t��Sr)rj)rc�	responsess �r!r-zSFTPClientFailedRETRAndErrbacksUponDisconnectTests.test_FailedRETR.<locals>.<lambda>�s���z�)�'<�r#r�)�passivec�N�tj�}|jd|�S)Nz/file/that/doesnt/exist)r
r�r�)rhr�s  r!rizTFTPClientFailedRETRAndErrbacksUponDisconnectTests.test_FailedRETR.<locals>.gotClient�s$���!�!�#�A��&�&�'@�!�D�Dr#)r
rP�noisyrr{rbr|r}rLr`r~rr�r�r�r�r�)r r&rLr�r�r?rir�s       @r!�test_FailedRETRzAFTPClientFailedRETRAndErrbacksUponDisconnectTests.test_FailedRETR�s����
��������� � ��A��=������*�*�+��,�,�.�%�%��
@�.�-�%�9��!�|�W�t�^�,�
-�
'�

�	�=���
�
#�
#�G�S�]�]�A�
F���M�M�+�w�/��	E�	
�
�
�i� ��!�!�!�S�%6�%6�7�7r#c�d��tj�}tj�}|j	|�||_|j
dt��}g��fd�}|j|�ddl	m
}|jtj|��|j���|S)zl
        Test the ftp command errbacks when a connection lost happens during
        the operation.
        z	some pathc�(���j|�yr�r))r�ms �r!�_ebzZFTPClientFailedRETRAndErrbacksUponDisconnectTests.test_errbacksUponDisconnect.<locals>._eb�s���
�H�H�W��r#r)�CONNECTION_LOST)rr�rrbrdr
rrr�twisted.internet.mainr�rFr�Failurer�)r �	ftpClient�trr?r�r�r�s      @r!�test_errbacksUponDisconnectzMFTPClientFailedRETRAndErrbacksUponDisconnectTests.test_errbacksUponDisconnect�s����
�M�M�O�	�
�
;�
;�
=��� � ��$�����N�N�;���0����	�	
���S��9�� � �����!A�B�����1���r#N)r5r6r7r�r�r�r3r#r!r�r�{s���"8�Hr#r�c��eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�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+),�FTPClientTestsz,
    Test advanced FTP client commands.
    c���tj�|_tj�|_|jj
|j
�|j|j
_y)zG
        Create a FTP client and connect it to fake transport.
        N)rr�rhrrbr]rdr
rs r!r�zFTPClientTests.setUp�sG���m�m�o���&�G�G�I������"�"�4�>�>�2�"&�+�+����r#c�^�|jjtj��y)z�
        Deliver disconnection notification to the client so that it can
        perform any cleanup which may be required.
        N)rhrFr�ConnectionLostrs r!r.zFTPClientTests.tearDown�s��
	
���"�"�5�#7�#7�#9�:r#c�
�|j|jj�d�|jj	d�|j|jj�d�|jj�|jj	d�|j|jj�d�|jj�|jj	d�y)z&
        Test the login part.
        r#s8331 Guest login ok, type your email address as password.sUSER anonymous
s2230 Anonymous login ok, access restrictions apply.sTYPE I
s200 Type set to I.N)r�r]r�rhr,�clearrs r!�
_testLoginzFTPClientTests._testLogin�s���	
������-�-�/��5���� � �G�	
�	
������-�-�/�1F�G���������� � �!V�W�������-�-�/��?���������� � �!6�7r#c�*�|j|jj�d�|jj	d�|j|jj�d�|jj	d�|j|jj�d�|jj�|jj	d�|j|jj�d�y)z5
        Test encoding behaviour of sendLine
        r#N�r��és�
)r�r]r�rhrer�rs r!�
test_sendLinezFTPClientTests.test_sendLine�s���	
������-�-�/��5������T�"�������-�-�/��5������R� �������-�-�/��9������������V�$�������-�-�/��=r#c�B���fd�}�j��jj�j|�}�j	�j
j
�d��j
j��jjd�|S)a
        Test the CDUP command.

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

        (XXX - This is a bad API)
        c�0���j|dd�y�Nrr<r�r{s �r!�cbCdupz(FTPClientTests.test_CDUP.<locals>.cbCdup��������S��V�%M�Nr#�CDUP
�&250 Requested File Action Completed OK)	r�rh�cdupr�r�r]r�r�r,)r r�r?s`  r!�	test_CDUPzFTPClientTests.test_CDUP�sw���	O�	
�����K�K����*�*�6�2��������-�-�/��=���������� � �!J�K��r#c�X�|j�|jj�}|j|tj
�|j
|jj�d�|jj�|jjd�|S)z�
        Test L{ftp.FTPClient.cdup}'s handling of a failed CDUP command.

        When the CDUP command fails, the returned Deferred should errback
        with L{ftp.CommandFailed}.
        r�s!550 ..: No such file or directory)r�rhr�r�rr�r�r]r�r�r,r�s  r!�test_failedCDUPzFTPClientTests.test_failedCDUPs{��	
�����K�K��������1�c�/�/�0�������-�-�/��=���������� � �!E�F��r#c����fd�}�j��jj�j|�}�j	�j
j
�d��jjd�|S)a
        Test the PWD command.

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

        (XXX - This is a bad API)
        c�V���jtj|d�d�y)Nr�/bar/baz)r�r�parsePWDResponser{s �r!�cbPwdz&FTPClientTests.test_PWD.<locals>.cbPwds"������S�1�1�#�a�&�9�:�Fr#�PWD
�257 "/bar/baz")r�rh�pwdr�r�r]r�r,)r r�r?s`  r!�test_PWDzFTPClientTests.test_PWDse���	G�	
�����K�K�O�O��)�)�%�0��������-�-�/��<���� � �!2�3��r#c�$�|j�|jj�}|j|tj
�|j
|jj�d�|jjd�|S)z�
        Test a failure in PWD command.

        When the PWD command fails, the returned Deferred should errback
        with L{ftp.CommandFailed}.
        r��'550 /bar/baz: No such file or directory)
r�rhr�r�rr�r�r]r�r,r�s  r!�test_failedPWDzFTPClientTests.test_failedPWD%si��	
�����K�K�O�O������1�c�/�/�0�������-�-�/��<���� � �!K�L��r#c����fd�}�j��jjd�j|�}�j	�j
j
�d��jjd�|S)a
        Test the CWD command.

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

        (XXX - This is a bad API)
        c�0���j|dd�yr�r�r{s �r!�cbCwdz&FTPClientTests.test_CWD.<locals>.cbCwd>r�r#�bar/foo�
CWD bar/foo
r�)r�rh�cwdr�r�r]r�r,)r r�r?s`  r!�test_CWDzFTPClientTests.test_CWD3sh���	O�	
�����K�K�O�O�I�&�2�2�5�9��������-�-�/�1C�D���� � �!J�K��r#c�&�|j�|jjd�}|j|tj
�|j
|jj�d�|jjd�|S)z�
        Test a failure in CWD command.

        When the PWD command fails, the returned Deferred should errback
        with L{ftp.CommandFailed}.
        r�r�s&550 bar/foo: No such file or directory)
r�rhr�r�rr�r�r]r�r,r�s  r!�test_failedCWDzFTPClientTests.test_failedCWDGsl��	
�����K�K�O�O�I�&�����1�c�/�/�0�������-�-�/�1C�D���� � �!J�K��r#c�p���fd�}�fd�}|�j_�j�t�}�jj	d|�}|j||��j
�jj�d��jj��jjt�j���j
�jj�d��jj��jjd�|S)aN
        Test the RETR command in passive mode: get a file and verify its
        content.

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

        (XXX - This API should be based on producers and consumers)
        c�>���j|jd�y�N��xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxr��r|r�r s  �r!�cbRetrz/FTPClientTests.test_passiveRETR.<locals>.cbRetra�������U�\�\�;�7r#c����j|d��j|d�|j||f�}|jtj���j
j
d�|jd�|jtjtjd���y)NrV�90�4150 File status okay; about to open data connection.r�r��
r�r`rdr�StringTransportrhr,rBrFrr�r�ConnectionDone�rKrLr%r�r s    �r!�	cbConnectz2FTPClientTests.test_passiveRETR.<locals>.cbConnectds�������T�;�/����T�5�)��)�)�4��,�7�E�� � ��!>�!>�!@�A��K�K�$�$�G�
�
���{�+�� � �����1E�1E�b�1I�!J�Kr#�spam�PASV
�RETR spam
�226 Transfer Complete.)rh�connectFactoryr�r:r�r�r�r]r�r�r,rN)r rr	r�r?s`    r!�test_passiveRETRzFTPClientTests.test_passiveRETRUs����	8�		L�&/����"�����"�$���K�K�$�$�V�U�3��	�
�
�f�e�$�������-�-�/��=���������� � �����!=�>�������-�-�/�1A�B���������� � �!:�;��r#c	����d�j_d�}�fd�}|�j_�j�t	�}�jjd|�}|j
||��j�jj�djtjdd��j�jj���jj��jj!d��j�jj�d	��jj��jj!d
�|S)z�
        Test the RETR command in non-passive mode.

        Like L{test_passiveRETR} but in the configuration where the server
        establishes the data connection to the client, rather than the other
        way around.
        Fc�j�djtjdd��|_|jjt
j��|jjd�|jjtjtjd���y)N�PORT {}rV�&r�r�)�formatrrH�textr
rdrrrBrFrr�rr)�portCmds r!�generatePortz.FTPClientTests.test_RETR.<locals>.generatePort�s{��$�+�+�C�,>�,>�{�D�,Q�R�G�L����+�+�M�,I�,I�,K�L����)�)�+�6����+�+�G�O�O�E�<P�<P�QS�<T�,U�Vr#c�>���j|jd�yr�r�r�s  �r!rz(FTPClientTests.test_RETR.<locals>.cbRetr�rr#r
�	PORT {}
rVr�200 PORT OKrr
)rhr��generatePortCommandr�r:r�r�r�r]r�rrrHrIrJr�r,)r rrr�r?s`    r!�	test_RETRzFTPClientTests.test_RETR|s���$�����	W�	8�+7����'�����"�$���K�K�$�$�V�U�3��	�
�
�f�e�$�����N�N� � �"�
�
!�
!�#�"4�"4�[�$�"G�
H�P�P����%�%�
�	
�	
��������� � ��0�������-�-�/�1A�B���������� � �!:�;��r#c����fd�}|�j_�j�t�}�jj	d|�}�j|tj��j�jj�d��jj��jjt�j���j�jj�d��jj��jjd�|S)z�
        Try to RETR an unexisting file.

        L{ftp.FTPClient.retrieveFile} should return a Deferred which
        errbacks with L{ftp.CommandFailed} if the server indicates the file
        cannot be transferred for some reason.
        c�^���j|d��j|d�|j||f�}|jtj���j
j
d�|jtjtjd���y�NrVrrr��r�r`rdrrrhr,rFrr�rrrs    �r!r	z1FTPClientTests.test_failedRETR.<locals>.cbConnect��������T�;�/����T�5�)��)�)�4��,�7�E�� � ��!>�!>�!@�A��K�K�$�$�G�
�
� � �����1E�1E�b�1I�!J�Kr#r
rrs#550 spam: No such file or directory)rhrr�r:r�r�rr�r�r]r�r�r,rN)r r	r�r?s`   r!�test_failedRETRzFTPClientTests.test_failedRETR�s����	L�&/����"�����"�$���K�K�$�$�V�U�3�����1�c�/�/�0�������-�-�/��=���������� � �����!=�>�������-�-�/�1A�B���������� � �!G�H��r#c	� ��d|j_g��fd�}||j_|j�t	�}|jjd|�}|j
|jj�djtjdd��j|jj��|jj�|jjd�|j
|jj�d�|j!���d	j#�|jj#�|j%|tj&�|S)
z�
        Try a RETR, but disconnect during the transfer.
        L{ftp.FTPClient.retrieveFile} should return a Deferred which
        errbacks with L{ftp.ConnectionLost)
        Fc�2��djtjdd��|_t	j
�}|jj|�|j|_|jjd��j|�y)NrrVrs�xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx)
rrrHrrrbr
rdrBr))rr�r/s  �r!rz2FTPClientTests.test_lostRETR.<locals>.generatePort�sp���$�+�+�C�,>�,>�{�D�,Q�R�G�L��?�?�A�B����+�+�B�/�!�*�*�B�K����)�)�*�5�
�H�H�R�Lr#r
rrVrrrr)rhr�rr�r:r�r�r]r�rrrHrIrJr�r,r�r^r�r�)r rr�r?r/s    @r!�
test_lostRETRzFTPClientTests.test_lostRETR�s+���$�������	�+7����'�����"�$���K�K�$�$�V�U�3������N�N� � �"�
�
!�
!�#�"4�"4�[�$�"G�
H�P�P����%�%�
�	
�	
��������� � ��0�������-�-�/�1A�B������	�!��������%�%�'����1�c�0�0�1��r#c�����tj���fd�}��fd�}��fd�}|�j_�j	��jjd�\}}|j
|�|j
|��j�jj�d��jj��jjt�j���j�jj�d��jj��jjd�tj||g�S)a�
        Test the STOR command: send a file and verify its content.

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

        (XXX - storeFile should take a producer as an argument, instead, and
        only return a Deferred which fires when the upload has succeeded or
        failed).
        c����jjd�|jjd�|j	�|jt
jtjd���y�Nrr�r��
rhr,r]r�finishrFrr�rr��senderr s �r!�cbStorez0FTPClientTests.test_passiveSTOR.<locals>.cbStore��Y����K�K�$�$�G�
�
���"�"�;�/��M�M�O��!�!�'�/�/�%�2F�2F�r�2J�"K�Lr#c�F���j�j�d�yr��r�r���ignr r�s ��r!�cbFinishz1FTPClientTests.test_passiveSTOR.<locals>.cbFinish�������R�X�X�Z��5r#c����j|d��j|d�|j||f�}|j��y�NrVr�r�r`rd�rKrLr%r�r r�s    ��r!r	z2FTPClientTests.test_passiveSTOR.<locals>.cbConnect�E������T�;�/����T�5�)��)�)�4��,�7�E�� � ��$r#r
r�STOR spam
r
)rrrhrr�r~r�r�r]r�r�r,rNrr�)r r-r3r	rdr�r�s`     @r!�test_passiveSTORzFTPClientTests.test_passiveSTOR�s	����
*�
*�
,��	M�	6�	%�&/����"��������&�&�v�.���B�
���w��
���x� �������-�-�/��=���������� � �����!=�>�������-�-�/�1A�B���������� � �!:�;��"�"�B��8�,�,r#c�����tj���fd�}��fd�}|�j_�j	��jjd�\}}|j
|��j|tj��j�jj�d��jj��jjt�j���j�jj�d��jj��jjd�t!j"||g�S)z�
        Test a failure in the STOR command.

        If the server does not acknowledge successful receipt of the
        uploaded file, the second Deferred returned by
        L{ftp.FTPClient.storeFile} should errback with L{ftp.CommandFailed}.
        c����jjd�|jjd�|j	�|jt
jtjd���yr(r)r+s �r!r-z/FTPClientTests.test_failedSTOR.<locals>.cbStore r.r#c����j|d��j|d�|j||f�}|j��yr6r7r8s    ��r!r	z1FTPClientTests.test_failedSTOR.<locals>.cbConnect(r9r#r
rr:s.426 Transfer aborted.  Data connection closed.)rrrhrr�r~r�r�rr�r�r]r�r�r,rNrr�)r r-r	rdr�r�s`    @r!�test_failedSTORzFTPClientTests.test_failedSTORs����
*�
*�
,��	M�	%�&/����"��������&�&�v�.���B�
���w�����2�s�0�0�1�������-�-�/��=���������� � �����!=�>�������-�-�/�1A�B���������� � �!R�S��"�"�B��8�,�,r#c�`���tj��d�j_�fd�}�fd�}��fd�}|�j_�j��jj
d�\}}|j|�|j|�tj||g�S)z�
        Test the STOR command in non-passive mode.

        Like L{test_passiveSTOR} but in the configuration where the server
        establishes the data connection to the client, rather than the other
        way around.
        Fc�x��dtjdd�z|_|jj	��y)Nr)rVr)rrHrr
rd)rr�s �r!rz.FTPClientTests.test_STOR.<locals>.generatePortFs0���"�S�%7�%7��T�%J�J�G�L����+�+�B�/r#c	����j�jj�djt	j
dd��j
�jj���jj��jjd��j�jj�d��jj��jjd�|jjd�|j�|jtjt!j"d����jjd	�y)
NrrVrrr:rr�r�r
)r�r]r�rrrHrIrhrJr�r,rr*rFrr�rrr+s �r!r-z)FTPClientTests.test_STOR.<locals>.cbStoreJs���������$�$�&��%�%�c�&8�&8��d�&K�L�T�T��K�K�)�)��
�
�N�N� � �"��K�K�$�$�^�4����T�^�^�1�1�3�5E�F��N�N� � �"��K�K�$�$�G�
�
���"�"�;�/��M�M�O��!�!�'�/�/�%�2F�2F�r�2J�"K�L��K�K�$�$�%>�?r#c�F���j�j�d�yr�r0r1s ��r!r3z*FTPClientTests.test_STOR.<locals>.cbFinish]r4r#r
)
rrrhr�rr�r~r�rr�)r rr-r3rdr�r�s`     @r!�	test_STORzFTPClientTests.test_STOR;s�����
*�
*�
,��#�����	0�	@�&	6�+7����'��������&�&�v�.���B�
���w��
���x� ��"�"�B��8�,�,r#c�L���fd�}�fd�}|�j_�j�tj�}�jjd|�j
||�}�j�jj�d��jj��jjt�j���j�jj�d��jjd�|S)a{
        Test the LIST command.

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

        (XXX - This is a very unfortunate API; if my understanding is
        correct, the results are always at least line-oriented, so allowing
        a per-line parser function to be specified would make this simpler,
        but a default implementation should really be provided which knows
        how to deal with all the formats used in real servers, so
        application developers never have to care about this insanity.  It
        would also be nice to either get back a Deferred of a list of
        filenames or to be able to consume the files as they are received
        (which the current API does allow, but in a somewhat inconvenient
        fashion) -exarkun)
        c���|jD�cgc]}|d��	}}gd�}|j�|j��j||�ycc}w�Nr��r9r?�baz�ryr�r��r|rzr&�fls�expectedr s     �r!�cbListz/FTPClientTests.test_passiveLIST.<locals>.cbList{�J���*2�.�.�9�Q�1�Z�=�9�C�9�,�H��M�M�O��H�H�J����S�(�+��	:��Ac����j|d��j|d�|j||f�}|jtj���j
j
d�gd�}|D]}|j|��|jtjtjd���y)NrVrr�s8-rw-r--r--    0 spam      egg      100 Oct 10 2006 foo
s8-rw-r--r--    3 spam      egg      100 Oct 10 2006 bar
s8-rw-r--r--    4 spam      egg      100 Oct 10 2006 baz
r�r)rKrLr%r��sendingr%r s      �r!r	z2FTPClientTests.test_passiveLIST.<locals>.cbConnect�s�������T�;�/����T�5�)��)�)�4��,�7�E�� � ��!>�!>�!@�A��K�K�$�$�G�
��G�
�
&���"�"�1�%�
&�� � �����1E�1E�b�1I�!J�Kr#�foo/barr�LIST foo/bar
r
)
rhrr�rrrrr�r�r]r�r�r,rN)r rNr	rzr?s`    r!�test_passiveLISTzFTPClientTests.test_passiveLISTgs����(	,�	L�"&/����"������*�*�,���K�K���Y��1�=�=�f�h�O��������-�-�/��=���������� � �����!=�>�������-�-�/�1D�E���� � �!:�;��r#c	���d�j_�fd�}�fd�}|�j_�j�t	j
�}�jj
d|�j||�}�j�jj�djt	jdd��j�jj���jj��jj!d��j�jj�d	��jj��jj!d
�|S)z�
        Test the LIST command in non-passive mode.

        Like L{test_passiveLIST} but in the configuration where the server
        establishes the data connection to the client, rather than the other
        way around.
        Fc���djtjdd��|_|jjt
j���jjd�gd�}|D]}|jj|��|jjtjtjd���y)NrrVrrrRr��rrrHrr
rdrrrhr,rBrFrr�rr)rrSr%r s   �r!rz.FTPClientTests.test_LIST.<locals>.generatePort�s����$�+�+�C�,>�,>�{�D�,Q�R�G�L����+�+�M�,I�,I�,K�L��K�K�$�$�G�
��G�
�
1��� � �-�-�a�0�
1����+�+�G�O�O�E�<P�<P�QS�<T�,U�Vr#c���|jD�cgc]}|d��	}}gd�}|j�|j��j||�ycc}wrGrJrKs     �r!rNz(FTPClientTests.test_LIST.<locals>.cbList�rOrPrTrrVrrrUr
)rhr�rr�rrrrr�r�r]r�rrHrIrJr�r,)r rrNrzr?s`    r!�	test_LISTzFTPClientTests.test_LIST�s ���$�����
	W�	,�+7����'������*�*�,���K�K���Y��1�=�=�f�h�O������N�N� � �"�
�
!�
!�#�"4�"4�[�$�"G�
H�P�P����%�%�
�	
�	
��������� � ��0�������-�-�/�1D�E���������� � �!:�;��r#c�b���fd�}|�j_�j�tj�}�jjd|�}�j
|tj��j�jj�d��jj��jjt�j���j�jj�d��jjd�|S)z�
        Test a failure in LIST command.

        L{ftp.FTPClient.list} should return a Deferred which fails with
        L{ftp.CommandFailed} if the server indicates the indicated path is
        invalid for some reason.
        c�^���j|d��j|d�|j||f�}|jtj���j
j
d�|jtjtjd���yrr rs    �r!r	z1FTPClientTests.test_failedLIST.<locals>.cbConnect�r!r#rTrrU�&550 foo/bar: No such file or directory)rhrr�rrrrr�r�r�r]r�r�r,rN)r r	rzr?s`   r!�test_failedLISTzFTPClientTests.test_failedLIST�s����	L�&/����"������*�*�,���K�K���Y��1�����1�c�/�/�0�������-�-�/��=���������� � �����!=�>�������-�-�/�1D�E���� � �!J�K��r#c	���d�j_�fd�}�fd�}|�j_�j�t	�}�jjd|�j
||�}�j�jj�djtjdd��j�jj���jj��jj!d��j�jj�d	��jj!d
�|S)z�
        Test the NLST command in non-passive mode.

        L{ftp.FTPClient.nlst} should return a Deferred which fires with a
        list of filenames when the list command has completed.
        Fc���djtjdd��|_|jjt
j���jjd�|jjd�|jjd�|jjd�|jjtjtjd���y)	NrrVrr�foo
�bar
�baz
r�rY)rr s �r!rz.FTPClientTests.test_NLST.<locals>.generatePort�s����$�+�+�C�,>�,>�{�D�,Q�R�G�L����+�+�M�,I�,I�,K�L��K�K�$�$�G�
�
���)�)�*�5����)�)�*�5����)�)�*�5����+�+�G�O�O�E�<P�<P�QS�<T�,U�Vr#c����|jj�jj�j	�}gd�}|j�|j��j
||�y)NrH)r=�decoderhrJr�r�r��r|r�rLrMr s    �r!rNz(FTPClientTests.test_NLST.<locals>.cbList	sQ����,�,�%�%�d�k�k�&;�&;�<�G�G�I�C�,�H��M�M�O��H�H�J����S�(�+r#rTrrVrr�NLST foo/bar
r
)rhr�rr�r:�nlstr�r�r]r�rrrHrIrJr�r,)r rrN�lstprotor?s`    r!�	test_NLSTzFTPClientTests.test_NLST�s
���$�����		W�	,�+7����'�����%�'���K�K���Y��1�=�=�f�h�O������N�N� � �"�
�
!�
!�#�"4�"4�[�$�"G�
H�P�P����%�%�
�	
�	
��������� � ��0�������-�-�/�1D�E���� � �!:�;��r#c�8���fd�}�fd�}|�j_�j�t�}�jj	d|�j||�}�j
�jj�d��jj��jjt�j���j
�jj�d��jjd�|S)z�
        Test the NLST command.

        Like L{test_passiveNLST} but in the configuration where the server
        establishes the data connection to the client, rather than the other
        way around.
        c���|jj�}gd�}|j�|j��j||�y)N)r�r�sbaz)r=r�r�r�rgs    �r!rNz/FTPClientTests.test_passiveNLST.<locals>.cbList"	s<����,�,�)�)�+�C�/�H��M�M�O��H�H�J����S�(�+r#c�����j|d��j|d�|j||f�}|jtj���j
j
d�|jd�|jd�|jd�|jtjtjd���y)NrVrrrbrcrdr�rrs    �r!r	z2FTPClientTests.test_passiveNLST.<locals>.cbConnect)	s�������T�;�/����T�5�)��)�)�4��,�7�E�� � ��!>�!>�!@�A��K�K�$�$�G�
�
���z�*����z�*����z�*�� � �����1E�1E�b�1I�!J�Kr#rTrrhr
)rhrr�r:rir�r�r]r�r�r,rN)r rNr	rjr?s`    r!�test_passiveNLSTzFTPClientTests.test_passiveNLST	s����	,�	L�&/����"�����%�'���K�K���Y��1�=�=�f�h�O��������-�-�/��=���������� � �����!=�>�������-�-�/�1D�E���� � �!:�;��r#c�z���tj����fd�}|�j_�j	�t�}�jj
d|�}�j|tj��j�jj�d��jj��jjt�j���j�jj�d��jjd�|S)z�
        Test a failure in NLST command.

        L{ftp.FTPClient.nlst} should return a Deferred which fails with
        L{ftp.CommandFailed} if the server indicates the indicated path is
        invalid for some reason.
        c�:���j|d��j|d�|j||f�}|j���jj	d�|jt
jtjd���yr)
r�r`rdrhr,rFrr�rrr8s    ��r!r	z1FTPClientTests.test_failedNLST.<locals>.cbConnectK	s~������T�;�/����T�5�)��)�)�4��,�7�E�� � ��$��K�K�$�$�G�
�
� � �����1E�1E�b�1I�!J�Kr#rTrrhr^)rrrhrr�r:rir�rr�r�r]r�r�r,rN)r r	rjr?r�s`   @r!�test_failedNLSTzFTPClientTests.test_failedNLSTA	s�����
*�
*�
,��	L�&/����"�����%�'���K�K���Y��1�����1�c�/�/�0�������-�-�/��=���������� � �����!=�>�������-�-�/�1D�E���� � �!J�K��r#c�z�|j�|jjdd�}|j|jj�d�|jj
�d}|jj|j|jj��|j|jj�d�d}|jj|j|jj��|j|j|g|gf�|S)z�
        L{ftp.FTPClient.rename} issues I{RNTO} and I{RNFR} commands and returns
        a L{Deferred} which fires when a file has successfully been renamed.
        �/spam�/ham�RNFR /spam
z8350 Requested file action pending further information.
�RNTO /ham
r<)r�rh�renamer�r]r�r�r,rIrJr�)r r?�fromResponse�
toResponses    r!�test_renameFromToz FTPClientTests.test_renameFromToa	s���
	
�����K�K���w��/��������-�-�/�1B�C�������S����� � ��!4�!4�T�[�[�5J�5J�!K�L�������-�-�/�1A�B�=�
���� � ��!2�!2�4�;�;�3H�3H�!I�J�	�
�
�d�&�&�,��*��(F�G��r#c�$�|j�d}d}|jj||�|jjd�|jjd�|j	|j
j
�d�y)z�
        L{ftp.FTPClient.rename} issues I{RNTO} and I{RNFR} commands with paths
        escaped according to U{http://cr.yp.to/ftp/filesystem.html}.
        z
/foo/ba
r/bazz/qu
uxs350 s250 s!RNFR /foo/bar/baz
RNTO /quux
N)r�rhrxr,r�r]r�)r �fromFile�toFiles   r!�test_renameFromToEscapesPathsz,FTPClientTests.test_renameFromToEscapesPathsu	sq��
	
����#���������8�V�,���� � ��)���� � ��)�����N�N� � �"�$V�	
r#c��|j�|jjdd�}|j|jj�d�|jj
�|jjd�|j|jj�d�|j|tj�S)z�
        The L{Deferred} returned by L{ftp.FTPClient.rename} is errbacked with
        L{CommandFailed} if the I{RNFR} command receives an error response code
        (for example, because the file does not exist).
        rtrurv�!550 Requested file unavailable.
r#�r�rhrxr�r]r�r�r,r�rr�r�s  r!�$test_renameFromToFailingOnFirstErrorz3FTPClientTests.test_renameFromToFailingOnFirstError�	s���	
�����K�K���w��/��������-�-�/�1B�C���������� � �!G�H�������-�-�/��5��!�!�!�S�%6�%6�7�7r#c���|j�|jjdd�}|j|jj�d�|jj
�|jjd�|j|jj�d�|jjd�|j|tj�S)z�
        The L{Deferred} returned by L{ftp.FTPClient.rename} is errbacked with
        L{CommandFailed} if the I{RNTO} command receives an error response code
        (for example, because the destination directory does not exist).
        rtrurvs8350 Requested file action pending further information.
rwr�r�r�s  r!�"test_renameFromToFailingOnRenameToz1FTPClientTests.test_renameFromToFailingOnRenameTo�	s���	
�����K�K���w��/��������-�-�/�1B�C���������� � �I�	
�	
������-�-�/�1A�B���� � �!G�H��!�!�!�S�%6�%6�7�7r#c��|j�|jjd�}|j|jj�d�|jj
d�|j|jdg�S)z�
        L{ftp.FTPClient.makeDirectory} issues a I{MKD} command and returns a
        L{Deferred} which is called back with the server's response if the
        directory is created.
        rt�MKD /spam
s257 "/spam" created.z257 "/spam" created.)r�rh�
makeDirectoryr�r]r�r,r�r�s  r!�test_makeDirectoryz!FTPClientTests.test_makeDirectory�	sn��	
�����K�K�%�%�g�.��������-�-�/�1A�B���� � �!8�9��}�}�T�-�-�0F�/G�H�Hr#c���|j�|jjd�}|j|jj�d�|jj
d�|S)z�
        L{ftp.FTPClient.makeDirectory} escapes the path name it sends according
        to U{http://cr.yp.to/ftp/filesystem.html}.
        z/sp
amsMKD /spam
s257 win)r�rhr�r�r]r�r,r�s  r!�test_makeDirectoryPathEscapez+FTPClientTests.test_makeDirectoryPathEscape�	sY��
	
�����K�K�%�%�i�0��������-�-�/�1E�F�	
��� � ��,��r#c�"�|j�|jjd�}|j|jj�d�|jj
d�|j|tj�S)z�
        L{ftp.FTPClient.makeDirectory} returns a L{Deferred} which is errbacked
        with L{CommandFailed} if the server returns an error response code.
        rtr�s550 PERMISSION DENIED)
r�rhr�r�r]r�r,r�rr�r�s  r!�test_failedMakeDirectoryz'FTPClientTests.test_failedMakeDirectory�	sl��
	
�����K�K�%�%�g�.��������-�-�/�1A�B���� � �!9�:��!�!�!�S�%6�%6�7�7r#c����fd�}�j��jj�j|�}�j	�j
j
�d��jjd�|S)z�
        Test the getDirectory method.

        L{ftp.FTPClient.getDirectory} should return a Deferred which fires with
        the current directory on the server. It wraps PWD command.
        c�*���j|d�y)Nr�r�r{s �r!�cbGetz/FTPClientTests.test_getDirectory.<locals>.cbGet�	s������S�*�-r#r�r�)r�rh�getDirectoryr�r�r]r�r,)r r�r?s`  r!�test_getDirectoryz FTPClientTests.test_getDirectory�	sf���	.�	
�����K�K�$�$�&�2�2�5�9��������-�-�/��<���� � �!2�3��r#c�$�|j�|jj�}|j|tj
�|j
|jj�d�|jjd�|S)zj
        Test a failure in getDirectory method.

        The behaviour should be the same as PWD.
        r�r��
r�rhr�r�rr�r�r]r�r,r�s  r!�test_failedGetDirectoryz&FTPClientTests.test_failedGetDirectory�	sk��	
�����K�K�$�$�&�����1�c�/�/�0�������-�-�/��<���� � �!K�L��r#c�$�|j�|jj�}|j|tj
�|j
|jj�d�|jjd�|S)z�
        Test a different failure in getDirectory method.

        The response should be quoted to be parsed, so it returns an error
        otherwise.
        r�s257 /bar/bazr�r�s  r!�test_anotherFailedGetDirectoryz-FTPClientTests.test_anotherFailedGetDirectory�	sj��	
�����K�K�$�$�&�����1�c�/�/�0�������-�-�/��<���� � ��1��r#c�f�|j�|jjd�}|j|jj�d�d}|jj
|j|jj��|j|j|g�S)z�
        L{ftp.FTPClient.removeFile} sends a I{DELE} command to the server for
        the indicated file and returns a Deferred which fires after the server
        sends a 250 response code.
        �	/tmp/test�DELE /tmp/test
�*250 Requested file action okay, completed.)
r�rh�
removeFiler�r]r�r,rIrJr��r r?�responses   r!�test_removeFilezFTPClientTests.test_removeFile�	s���	
�����K�K�"�"�;�/��������-�-�/�1F�G�?����� � �������1F�1F�!G�H��}�}�T�-�-��z�:�:r#c�����j��jjd�}�j�jj�d�d��jj
�j�jj���j|tj�}|j��fd��|S)a
        If the server returns a response code other than 250 in response to a
        I{DELE} sent by L{ftp.FTPClient.removeFile}, the L{Deferred} returned
        by C{removeFile} is errbacked with a L{Failure} wrapping a
        L{CommandFailed}.
        r�r��,501 Syntax error in parameters or arguments.c�@���j|j�gf�Srr���excr�r s ��r!r-z6FTPClientTests.test_failedRemoveFile.<locals>.<lambda>
����$�"2�"2�3�8�8�x�j�]�"K�r#)
r�rhr�r�r]r�r,rIrJr�rr�r�r�s` @r!�test_failedRemoveFilez$FTPClientTests.test_failedRemoveFile

s����	
�����K�K�"�"�;�/��������-�-�/�1F�G�A����� � �������1F�1F�!G�H����q�#�"3�"3�4��	�
�
�K�L��r#c�J����j��jjd�}d��jj�j	�jj
���j
|tj�}|j��fd��|S)z�
        If the server returns a response line which cannot be parsed, the
        L{Deferred} returned by L{ftp.FTPClient.removeFile} is errbacked with a
        L{BadResponse} containing the response.
        r��765 blah blah blahc�@���j|j�gf�Srr�r�s ��r!r-zBFTPClientTests.test_unparsableRemoveFileResponse.<locals>.<lambda>%
r�r#)
r�rhr�r,rIrJr�r�BadResponser�r�s` @r!�!test_unparsableRemoveFileResponsez0FTPClientTests.test_unparsableRemoveFileResponse
su���	
�����K�K�"�"�;�/��'����� � �������1F�1F�!G�H����q�#�/�/�2��	�
�
�K�L��r#c��|j�|jjd�}|jjd�|jjd�|j	|j
�S)z�
        If the server returns multiple response lines, the L{Deferred} returned
        by L{ftp.FTPClient.removeFile} is still fired with a true value if the
        ultimate response code is 250.
        r��250-perhaps a progress report�250 okay)r�rhr�r,r�r�r�s  r!� test_multilineRemoveFileResponsez/FTPClientTests.test_multilineRemoveFileResponse(
sZ��	
�����K�K�"�"�;�/����� � �!A�B���� � ��-��}�}�T�_�_�-�-r#c�f�|j�|jjd�}|j|jj�d�d}|jj
|j|jj��|j|j|g�S)z�
        L{ftp.FTPClient.removeDirectory} sends a I{RMD} command to the server
        for the indicated directory and returns a Deferred which fires after
        the server sends a 250 response code.
        r��RMD /tmp/test
r�)
r�rh�removeDirectoryr�r]r�r,rIrJr�r�s   r!�test_removeDirectoryz#FTPClientTests.test_removeDirectory4
s���	
�����K�K�'�'��4��������-�-�/�1E�F�?����� � �������1F�1F�!G�H��}�}�T�-�-��z�:�:r#c�����j��jjd�}�j�jj�d�d��jj
�j�jj���j|tj�}|j��fd��|S)a
        If the server returns a response code other than 250 in response to a
        I{RMD} sent by L{ftp.FTPClient.removeDirectory}, the L{Deferred}
        returned by C{removeDirectory} is errbacked with a L{Failure} wrapping
        a L{CommandFailed}.
        r�r�r�c�@���j|j�gf�Srr�r�s ��r!r-z;FTPClientTests.test_failedRemoveDirectory.<locals>.<lambda>N
r�r#)
r�rhr�r�r]r�r,rIrJr�rr�r�r�s` @r!�test_failedRemoveDirectoryz)FTPClientTests.test_failedRemoveDirectoryA
s����	
�����K�K�'�'��4��������-�-�/�1E�F�A����� � �������1F�1F�!G�H����q�#�"3�"3�4��	�
�
�K�L��r#c�J����j��jjd�}d��jj�j	�jj
���j
|tj�}|j��fd��|S)z�
        If the server returns a response line which cannot be parsed, the
        L{Deferred} returned by L{ftp.FTPClient.removeDirectory} is errbacked
        with a L{BadResponse} containing the response.
        r�r�c�@���j|j�gf�Srr�r�s ��r!r-zGFTPClientTests.test_unparsableRemoveDirectoryResponse.<locals>.<lambda>\
r�r#)
r�rhr�r,rIrJr�rr�r�r�s` @r!�&test_unparsableRemoveDirectoryResponsez5FTPClientTests.test_unparsableRemoveDirectoryResponseQ
su���	
�����K�K�'�'��4��'����� � �������1F�1F�!G�H����q�#�/�/�2��	�
�
�K�L��r#c��|j�|jjd�}|jjd�|jjd�|j	|j
�S)z�
        If the server returns multiple response lines, the L{Deferred} returned
        by L{ftp.FTPClient.removeDirectory} is still fired with a true value
         if the ultimate response code is 250.
        r�r�r�)r�rhr�r,r�r�r�s  r!�%test_multilineRemoveDirectoryResponsez4FTPClientTests.test_multilineRemoveDirectoryResponse_
sZ��	
�����K�K�'�'��4����� � �!A�B���� � ��-��}�}�T�_�_�-�-r#N)-r5r6r7r�r�r.r�r�r�r�r�r�r�r�rrr"r%r;r?rDrVr[r_rkrorrr{rr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r3r#r!r�r��s����.�;�
8�>��*
��(��(�%�N#�J�@$�L--�^#-�J*-�X5�n/�b�>)�V&�P�@�(
� 8�$8�&I��
8��"��;�� �
.�;�� �
.r#r�c�.�eZdZdZd�Zd�Zd�Zd�Zd�Zy)�FTPClientBasicTestsz
    FTP client
    c��tj�}|jd�|jdg|j�y)z?
        The first response is captured as a greeting.
        �220 Imaginary FTP.z220 Imaginary FTP.N�rr�r,r��greeting�r r�s  r!�
test_greetingz!FTPClientBasicTests.test_greetingq
s;���&�&�(�	����4�5����.�/��1C�1C�Dr#c��tj�}|jd�|jdg|j�y)z�
        Responses with no message are still valid, i.e. three digits
        followed by a space is complete response.
        s220 z220 Nr�r�s  r!�test_responseWithNoMessagez.FTPClientBasicTests.test_responseWithNoMessagey
s8��
�&�&�(�	����w�'����&��9�#5�#5�6r#c��tj�}tj�|_|jd�|j
d�}g}|j|j�|j|j�|jd�|jg|�|jd�|jg|�|jd�|jg|�|jd�|jg|�|jd�|jg|�|jd�|jg|�|jd	�|jgd
�|d�y)
z$
        Multiline response
        r��BLAHs210-First line.s123-Second line.sJust some text.sHir#s321s	210 Done.)z210-First line.z123-Second line.zJust some text.�Hir��321z	210 Done.rN)rr�rrr]r,r�r�r)rr�r�)r r�r�r�s    r!�test_MultilineResponsez*FTPClientBasicTests.test_MultilineResponse�
s\���&�&�(�	�+�;�;�=�	�����4�5��/�/��7�������V�]�]�+����D�I�I�&�	���1�2�����V�$�	���2�3�����V�$�	���1�2�����V�$�	���u�%�����V�$�	���s�#�����V�$�	���v�&�����V�$�	���|�,����
�
�1�I�	
r#c��tj�}tj�|_|jd�|j
dd�|jd|jj��|jj�|jd�|jd|jj��y)zO
        Passing None as the password avoids sending the PASS command.
        �220 Welcome to Imaginary FTP.�bobN�
USER bob
s200 Hello bob.r#�
rr�rrr]r,�
queueLoginr�r�r�r�s  r!�test_noPasswordGivenz(FTPClientBasicTests.test_noPasswordGiven�
s���
�&�&�(�	�+�;�;�=�	�����?�@�	���U�D�)�����)�*=�*=�*C�*C�*E�F�	���!�!�#����0�1�	
����i�1�1�7�7�9�:r#c��tj�}tj�|_|jd�|j
dd�|jd|jj��|jj�|jd�|jd|jj��y)zQ
        Receiving a 230 response to USER prevents PASS from being sent.
        r�r��secretr�s#230 Hello bob.  No password needed.r#Nr�r�s  r!�test_noPasswordNeededz)FTPClientBasicTests.test_noPasswordNeeded�
s���
�&�&�(�	�+�;�;�=�	�����?�@�	���U�H�-�����)�*=�*=�*C�*C�*E�F�	���!�!�#����E�F�	
����i�1�1�7�7�9�:r#N)	r5r6r7r�r�r�r�r�r�r3r#r!r�r�l
s"���E�7�4
�l;�*;r#r�c��eZdZdZd�Zy)�PathHandlingTestsz
    Handling paths.
    c
���ddgfddgfdgfdgd�fdgd�fddgfddgffD]+\}}|jtjg|�|��-d	dd	gfd
dd	gfdd	gfdd	gfd
gd�fdgd�fdd	dgfdd	dgffD],\}}|jtjdg|�|��.dgfddgfddgfddd	gffD]+\}}|jtjg|�|��-dgfdd	gfdgd�ffD],\}}|jtjdg|�|��.dgfdgfddgfdgfddgfddgfdddgfd ddgfd!dgfd"dgfd#gfd$gffD],\}}|jtjdg|�|��.d%D]2}|jtjtjg|��4d&D]3}|jtjtjdg|��5y')(z"
        Normalize paths.
        r�z/a�/za/b/c)r�r��cz/a/b/cz/a/za/r�zb/z/bz/b/zb/czb/c/z/b/cr�z/b/c/z//z//aza//za//bz//bzb//c�..�../za/..�xz/a/..z/a/b/..z/a/b/../z	/a/b/../cz
/a/b/../c/z/a/b/../../cz
/a/b/../../c/z/a/b/../../c/..z/a/b/../../c/../)	r�r�za/../..za/../../z/..z/../z/a/../..z	/a/../../z
/a/b/../../..)z../..z../../z
../a/../..N)r�r�
toSegmentsr"�InvalidPath)r �inp�outps   r!�test_Normalizerz!PathHandlingTests.test_Normalizer�
s���
�3�%�L�
�C�5�M�
�"�I�
�o�&�
��'�
�S�E�N�
�C�5�M�
�		<�I�C��
���S�^�^�B��4�d�;�		<��3��*��
�C��:��
�C�5�M�
�S�E�N�
�O�$�
�_�%�
�c�3�Z� �
�s�C�j�!�	
�
	?�I�C��
���S�^�^�S�E�3�7��>�
	?��2�J�
�S�E�N�
�S�E�N�
�c�3�Z� �	
�	<�I�C��
���S�^�^�B��4�d�;�
	<� ��*�u�s�e�n�v��6O�P�	?�I�C�����S�^�^�S�E�3�7��>�	?��2�J�
�B�K�
�c�U�O�
�b�M�
����
�#���
�3��*�%�
�C��:�&�
�c�U�#�
�s�e�$�
��#�
��$�

�	?�I�C��
���S�^�^�S�E�3�7��>�	?� 

�	H�C�
���c�o�o�s�~�~�r�3�G�	H�5�	K�C����c�o�o�s�~�~��u�c�J�	Kr#N)r5r6r7r�r�r3r#r!r�r��
s���DKr#r�c�"�eZdZdZd�Zd�Zd�Zy)�IsGlobbingExpressionTestsz;
    Tests for _isGlobbingExpression utility function.
    c���|jtj��|jtjg��|jtjd��y)z^
        _isGlobbingExpression will return False for None, or empty
        segments.
        N�r�r�_isGlobbingExpressionrs r!�&test_isGlobbingExpressionEmptySegmentsz@IsGlobbingExpressionTests.test_isGlobbingExpressionEmptySegments5sM��
	
����2�2�4�5�����2�2�2�6�7�����2�2�4�8�9r#c��|jtjddg��|jtjddg��y)z�
        _isGlobbingExpression will return False for plain segments.

        Also, it only checks the last segment part (filename) and will not
        check the path name.
        rn�expr�*.txtNr�rs r!�test_isGlobbingExpressionNoGlobz9IsGlobbingExpressionTests.test_isGlobbingExpressionNoGlob>s@��	
����2�2�H�f�3E�F�G�����2�2�G�V�3D�E�Fr#c���|jtjddg��|jtjddg��|jtjddg��y)z�
        _isGlobbingExpression will return True for segments which contains
        globbing characters in the last segment part (filename).
        rnr�z	[a-b].txtzfil?.txtN)r�rr�rs r!�test_isGlobbingExpressionGlobz7IsGlobbingExpressionTests.test_isGlobbingExpressionGlobHsX��
	
����1�1�8�W�2E�F�G�����1�1�8�[�2I�J�K�����1�1�8�Z�2H�I�Jr#N)r5r6r7r�r�r�r�r3r#r!r�r�0s���:�G�Kr#r�c�(�eZdZdZd�Zd�Zd�Zd�Zy)�BaseFTPRealmTestsz�
    Tests for L{ftp.BaseFTPRealm}, a base class to help define L{IFTPShell}
    realms with different user home directory policies.
    c�^�|jtttj��y)z;
        L{ftp.BaseFTPRealm} implements L{IRealm}.
        N)r�rr
r�BaseFTPRealmrs r!�test_interfacez BaseFTPRealmTests.test_interfaceXs��	
����F�C�,<�,<�=�>r#c�x���tj|j���g�G��fd�dtj�}||j��}|jddtj�\}}}|j|tj�|j|j��y)z�
        L{ftp.BaseFTPRealm} calls its C{getHomeDirectory} method with the
        avatarId being requested to determine the home directory for that
        avatar.
        c���eZdZ��fd�Zy)�:BaseFTPRealmTests.test_getHomeDirectory.<locals>.TestRealmc�*���j|��Srr�)r �avatarId�avatarsr�s  ��r!�getHomeDirectoryzKBaseFTPRealmTests.test_getHomeDirectory.<locals>.TestRealm.getHomeDirectoryhs������x�(��
r#N)r5r6r7r�)r�r�s��r!�	TestRealmr�gs���
r#r��alice@example.comN)rrnrjrr��
requestAvatar�	IFTPShellr��FTPShellr��filesystemRoot)r r��realm�iface�avatar�logoutr�r�s      @@r!�test_getHomeDirectoryz'BaseFTPRealmTests.test_getHomeDirectory^s�����"�"�4�;�;�=�1����	��(�(�	�
�$�+�+�-�(�� %� 3� 3���s�}�}�!
���v�v�	
���f�c�l�l�3�����.�.��7r#c�R�|j�}tj|�}|jtj
dtj�\}}}|j|tj�|j|jtj|��y)zy
        L{ftp.BaseFTPRealm} returns an L{ftp.FTPAnonymousShell} instance for
        anonymous avatar requests.
        N)
rjrr�r�r�	ANONYMOUSr�r�r�r�r�rrn)r rQrrrrs      r!�test_anonymousz BaseFTPRealmTests.test_anonymousss���
�K�K�M�	�� � ��+�� %� 3� 3�����c�m�m�!
���v�v�	
���f�c�&;�&;�<�����.�.��0A�0A�)�0L�Mr#c��tj|j��}|jt|j
t
��y)z�
        L{ftp.BaseFTPRealm.getHomeDirectory} should be overridden by a subclass
        and raises L{NotImplementedError} if it is not.
        N)rr�rjr"�NotImplementedErrorr�rh)r rs  r!�test_notImplementedz%BaseFTPRealmTests.test_notImplemented�s5��
� � �����/�����-�u�/E�/E�v�x�Pr#N)r5r6r7r�r�rrr
r3r#r!r�r�Rs���
?�8�*N�Qr#r�c��eZdZdZd�Zd�Zy)�
FTPRealmTestsz$
    Tests for L{ftp.FTPRealm}.
    c���d}tj|j�|�}|jd�}|j	tj|�jd�|�y)z�
        L{ftp.FTPRealm} accepts an extra directory to its initializer and treats
        the avatarId passed to L{ftp.FTPRealm.getHomeDirectory} as a single path
        segment to construct a child of that directory.
        z
/path/to/homer�N)rrqrjr�r�rrnr@)r �baser�homes    r!rz#FTPRealmTests.test_getHomeDirectory�sW�������T�[�[�]�D�1���%�%�&9�:������*�*�4�0�6�6�7J�K�T�Rr#c��tj|j��}|jd�}|j	tjd�|�y)z�
        If no extra directory is passed to L{ftp.FTPRealm}, it uses C{"/home"}
        as the base directory containing all user home directories.
        r�z/home/alice@example.comN)rrqrjr�r�rrn)r rrs   r!�test_defaultHomeDirectoryz'FTPRealmTests.test_defaultHomeDirectory�sE��
���T�[�[�]�+���%�%�&9�:������*�*�+D�E�t�Lr#N)r5r6r7r�rrr3r#r!rr�s���	S�Mr#rc� �eZdZdZeZd�Zd�Zy)�SystemFTPRealmTestsz*
    Tests for L{ftp.SystemFTPRealm}.
    c��tj�}ddl}|j|�j}tj|j��}|j|�}|j|tj|��y)z�
        L{ftp.SystemFTPRealm.getHomeDirectory} treats the avatarId passed to it
        as a username in the underlying platform and returns that account's home
        directory.
        rN)�getpass�getuserr��getpwnam�pw_dirr�SystemFTPRealmrjr�r�rrn)r r�r�rMrrs      r!rz)SystemFTPRealmTests.test_getHomeDirectory�sj����� ��
	��<�<��%�,�,���"�"�4�;�;�=�1���%�%�d�+������x�0�0��:�;r#c��tjtj�dj	d�td�D��z}t
j|j��}|jt|j|�y)z�
        L{ftp.SystemFTPRealm.getHomeDirectory} raises L{UnauthorizedLogin} when
        passed a username which has no corresponding home directory in the
        system's accounts database.
        r�c3�K�|]8}tjtjtjz����:y�wr)�random�choice�string�
ascii_letters�digits)�.0r,s  r!�	<genexpr>z6SystemFTPRealmTests.test_noSuchUser.<locals>.<genexpr>�s-����=
�DE�F�M�M�&�.�.����>�?�=
�s�>Ar/N)rrrrrrrrrjr"r	r�)r r�rs   r!�test_noSuchUserz#SystemFTPRealmTests.test_noSuchUser�sj���}�}�V�1�1�2�R�W�W�=
�IN�q��=
�6
�
���"�"�4�;�;�=�1�����+�U�-C�-C�T�Jr#N)r5r6r7r��nonPOSIXSkip�skiprr#r3r#r!rr�s����D�<�(Kr#rc�:�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
y	)
�ErrnoToFailureTestsz9
    Tests for L{ftp.errnoToFailure} errno checking.
    c��tjtjd�}|j	|tj
�S)zS
        C{errno.ENOENT} should be translated to L{ftp.FileNotFoundError}.
        r9)r�errnoToFailure�errno�ENOENTr��FileNotFoundErrorr�s  r!�
test_notFoundz!ErrnoToFailureTests.test_notFound��3��
���u�|�|�U�3���!�!�!�S�%:�%:�;�;r#c��tjtjd�}|j	|tj
�S)zV
        C{errno.EPERM} should be translated to L{ftp.PermissionDeniedError}.
        r9)rr)r*�EPERMr��PermissionDeniedErrorr�s  r!�test_permissionDeniedz)ErrnoToFailureTests.test_permissionDenied�s3��
���u�{�{�E�2���!�!�!�S�%>�%>�?�?r#c��tjtjd�}|j	|tj
�S)zW
        C{errno.EACCES} should be translated to L{ftp.PermissionDeniedError}.
        r9)rr)r*�EACCESr�r1r�s  r!�test_accessDeniedz%ErrnoToFailureTests.test_accessDenied�s3��
���u�|�|�U�3���!�!�!�S�%>�%>�?�?r#c��tjtjd�}|j	|tj
�S)zW
        C{errno.ENOTDIR} should be translated to L{ftp.IsNotADirectoryError}.
        r9)rr)r*�ENOTDIRr��IsNotADirectoryErrorr�s  r!�test_notDirectoryz%ErrnoToFailureTests.test_notDirectory�s3��
���u�}�}�e�4���!�!�!�S�%=�%=�>�>r#c��tjtjd�}|j	|tj
�S)zQ
        C{errno.EEXIST} should be translated to L{ftp.FileExistsError}.
        r9)rr)r*�EEXISTr��FileExistsErrorr�s  r!�test_fileExistsz#ErrnoToFailureTests.test_fileExists�s3��
���u�|�|�U�3���!�!�!�S�%8�%8�9�9r#c��tjtjd�}|j	|tj
�S)zS
        C{errno.EISDIR} should be translated to L{ftp.IsADirectoryError}.
        r9)rr)r*�EISDIRr�r�r�s  r!�test_isDirectoryz$ErrnoToFailureTests.test_isDirectory�r.r#c��	td��#t$r/tjdd�}|j	|t�cYSwxYw)z�
        If an unknown errno is passed to L{ftp.errnoToFailure}, it should let
        the originating exception pass through.
        r?r�r9)rK�
BaseExceptionrr)r�r�s  r!�test_passThroughz$ErrnoToFailureTests.test_passThrough�sF��
	7��u�%�%���	7��"�"�2�u�-�A��%�%�a��6�6�	7�s�
�5A�AN)r5r6r7r�r-r2r5r9r=r@rCr3r#r!r'r'�s,���<�@�@�?�:�<�	7r#r'c��eZdZdZd�Zy)�AnonymousFTPShellTestsz*
    Test anonymous shell properties.
    c��tjd�}|jd�}|j|tj�|S)zt
        Check that L{ftp.FTPAnonymousShell} returns an error when trying to
        open it in write mode.
        r��r9)rr�rsr�r1)r rrr?s   r!�test_anonymousWritez*AnonymousFTPShellTests.test_anonymousWrites?��
�%�%�b�)��� � ��*�����1�c�7�7�8��r#N)r5r6r7r�rHr3r#r!rErEs���r#rEc���eZdZdZd�Zd�Zd�Zd'd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z d�Z!d �Z"d!�Z#d"�Z$d#�Z%d$�Z&d%�Z'y&)(�IFTPShellTestsMixinz7
    Generic tests for the C{IFTPShell} interface.
    c��t��)a

        Test if the directory exists at C{path}.

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

        @return: C{True} if C{path} exists and is a directory, C{False} if
            it's not the case
        @rtype: C{bool}
        �r	�r r�s  r!�directoryExistsz#IFTPShellTestsMixin.directoryExists�
��"�#�#r#c��t��)z�
        Create a directory in C{path}.

        @param path: the relative path of the directory to create, with one
            segment.
        @type path: C{str}
        rLrMs  r!rDz#IFTPShellTestsMixin.createDirectory)s
��"�#�#r#c��t��)a
        Test if the file exists at C{path}.

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

        @return: C{True} if C{path} exists and is a file, C{False} if it's not
            the case.
        @rtype: C{bool}
        rLrMs  r!�
fileExistszIFTPShellTestsMixin.fileExists3rOr#c��t��)a
        Create a file named C{path} with some content.

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

        @param fileContent: the content of the file.
        @type fileContent: C{str}
        rL�r r��fileContents   r!�
createFilezIFTPShellTestsMixin.createFile@rOr#c��|j|jd��|jd�|j|jd��y)z�
        C{directoryExists} should report correctly about directory existence,
        and C{createDirectory} should create a directory detectable by
        C{directoryExists}.
        r?N)r�rNrDr�rs r!�test_createDirectoryz(IFTPShellTestsMixin.test_createDirectoryMsB��	
����-�-�e�4�5����U�#�����,�,�U�3�4r#c��|j|jd��|jd�|j|jd��y)z�
        C{fileExists} should report correctly about file existence, and
        C{createFile} should create a file detectable by C{fileExists}.
        �file.txtN)r�rRrVr�rs r!�test_createFilez#IFTPShellTestsMixin.test_createFileWs<��
	
�������4�5����
�#�������
�3�4r#c�f���jjd�}�fd�}|j|�S)zI
        Create a directory and check it ends in the filesystem.
        rGc�F���j�jd��y)Nr9)r�rNrBs �r!r1z2IFTPShellTestsMixin.test_makeDirectory.<locals>.cbfs����O�O�D�0�0��7�8r#)rrr�r�r4s`  r!r�z&IFTPShellTestsMixin.test_makeDirectory`s/���
�J�J�$�$�X�.��	9��}�}�R� � r#c��|jd�|jjd�}|j|tj
�S)zm
        Creating a directory that already exists should fail with a
        C{ftp.FileExistsError}.
        r9rG)rDrrr�r�rr<r�s  r!�test_makeDirectoryErrorz+IFTPShellTestsMixin.test_makeDirectoryErrorks?��
	
���U�#��J�J�$�$�X�.���!�!�!�S�%8�%8�9�9r#c����jd��jjd�}�fd�}|j|�S)zW
        Try to remove a directory and check it's removed from the filesystem.
        r?�r?c�F���j�jd��yr>)r�rNrBs �r!r1z4IFTPShellTestsMixin.test_removeDirectory.<locals>.cb{s������T�1�1�%�8�9r#)rDrrr�r�r4s`  r!r�z(IFTPShellTestsMixin.test_removeDirectoryts=���	
���U�#��J�J�&�&�x�0��	:��}�}�R� � r#c��|jd�|jjd�}|j|tj
�S)zn
        removeDirectory should not work in file and fail with a
        C{ftp.IsNotADirectoryError}.
        rZ�rZ)rVrrr�r�rr8r�s  r!�test_removeDirectoryOnFilez.IFTPShellTestsMixin.test_removeDirectoryOnFile�s=��
	
���
�#��J�J�&�&�}�5���!�!�!�S�%=�%=�>�>r#c�x�|jjd�}|j|tj�S)zl
        Removing directory that doesn't exist should fail with a
        C{ftp.FileNotFoundError}.
        ra)rrr�r�rr,r�s  r!�test_removeNotExistingDirectoryz3IFTPShellTestsMixin.test_removeNotExistingDirectory�s1��

�J�J�&�&�x�0���!�!�!�S�%:�%:�;�;r#c����jd��jjd�}�fd�}|j|�|S)zR
        Try to remove a file and check it's removed from the filesystem.
        rZrdc�F���j�jd��y�NrZ)r�rRr{s �r!r1z/IFTPShellTestsMixin.test_removeFile.<locals>.cb�s������T�_�_�Z�8�9r#)rVrrr�r�r4s`  r!r�z#IFTPShellTestsMixin.test_removeFile�s=���	
���
�#��J�J�!�!�-�0��	:�	
�
�
�b���r#c��|jd�|jjd�}|j|tj
�S)z:
        removeFile should not work on directory.
        �ned�rl)rDrrr�r�rr�r�s  r!�test_removeFileOnDirectoryz.IFTPShellTestsMixin.test_removeFileOnDirectory�s?��	
���U�#��J�J�!�!�(�+���!�!�!�S�%:�%:�;�;r#c�x�|jjd�}|j|tj�S)zl
        Try to remove a non existent file, and check it raises a
        L{ftp.FileNotFoundError}.
        rG)rrr�r�rr,r�s  r!�test_removeNotExistingFilez.IFTPShellTestsMixin.test_removeNotExistingFile�s1��

�J�J�!�!�(�+���!�!�!�S�%:�%:�;�;r#c����jd��jd��jjd�}�fd�}|j	|�S)z6
        Check the output of the list method.
        rlrZ��.c�V��|j��j|dgfdgfg�y)NrZrl�r�r��r/r s �r!r1z)IFTPShellTestsMixin.test_list.<locals>.cb�s*���
�F�F�H����Q�*�b�!1�E�2�;� ?�@r#�rDrVrrrr�r4s`  r!�	test_listzIFTPShellTestsMixin.test_list�sH���	
���U�#����
�#��J�J�O�O�F�#��	A��}�}�R� � r#c����jd��jd��jjdd�}�fd�}|j	|�S)z<
        Check the output of list with asked stats.
        rlrZrr)r��permissionsc�@��|j��jt|�d��j|ddd��j|ddd��jt|dd�d��jt|dd�d�y)Nr�rrZr�rl)r�r�r�rvs �r!r1z1IFTPShellTestsMixin.test_listWithStat.<locals>.cb�s����
�F�F�H����S��V�Q�'����Q�q�T�!�W�j�1����Q�q�T�!�W�e�,�
���S��1��a��\�1�-����S��1��a��\�1�-r#rwr4s`  r!�test_listWithStatz%IFTPShellTestsMixin.test_listWithStat�sO���	
���U�#����
�#��J�J�O�O��
�
��	.��}�}�R� � r#c��|jd�|jjdd�}|j|t�S)�P
        Querying an invalid stat should result to a C{AttributeError}.
        rlrr�r��whateverstat)rDrrrr��AttributeErrorr�s  r!�test_listWithInvalidStatz,IFTPShellTestsMixin.test_listWithInvalidStat�sA��	
���U�#��J�J�O�O��
�
���!�!�!�^�4�4r#c����jd��jjd�}�fd�}|j|�S)z@
        Check the output of the list method on a file.
        rZrdc�P��|j��j|dgfg�yrjrurvs �r!r1z-IFTPShellTestsMixin.test_listFile.<locals>.cb�s$���
�F�F�H����Q�*�b�!1� 2�3r#)rVrrrr�r4s`  r!�
test_listFilez!IFTPShellTestsMixin.test_listFile�s9���	
���
�#��J�J�O�O�M�*��	4��}�}�R� � r#c�x�|jjd�}|j|tj�S)zm
        list on a directory that doesn't exist should fail with a
        L{ftp.FileNotFoundError}.
        rG)rrrr�rr,r�s  r!�test_listNotExistingDirectoryz1IFTPShellTestsMixin.test_listNotExistingDirectory�s/��

�J�J�O�O�H�%���!�!�!�S�%:�%:�;�;r#c�^�|jd�|jjd�}|S)z+
        Try to access a resource.
        rlrm)rDrr�accessr�s  r!�test_accesszIFTPShellTestsMixin.test_access�s+��	
���U�#��J�J���h�'���r#c�x�|jjd�}|j|tj�S)zF
        access should fail on a resource that doesn't exist.
        rG)rrr�r�rr,r�s  r!�test_accessNotFoundz'IFTPShellTestsMixin.test_accessNotFound
s1��
�J�J���h�'���!�!�!�S�%:�%:�;�;r#c����jd��jjd�}�fd�}|j|�|S)zY
        Check that openForReading returns an object providing C{ftp.IReadFile}.
        rZrdc�b���jtjj|��yr)r�r�	IReadFile�
providedByr{s �r!r1z3IFTPShellTestsMixin.test_openForReading.<locals>.cb
s����O�O�C�M�M�4�4�S�9�:r#)rVrrr�r�r4s`  r!�test_openForReadingz'IFTPShellTestsMixin.test_openForReading
s=���	
���
�#��J�J�%�%�m�4��	;�	
�
�
�b���r#c�x�|jjd�}|j|tj�S)zr
        openForReading should fail with a C{ftp.FileNotFoundError} on a file
        that doesn't exist.
        rm)rrr�r�rr,r�s  r!�test_openForReadingNotFoundz/IFTPShellTestsMixin.test_openForReadingNotFound
s1��

�J�J�%�%�h�/���!�!�!�S�%:�%:�;�;r#c��|jd�|jjd�}|j|tj
�S)z>
        openForReading should not work on directory.
        rlrm)rDrrr�r�rr�r�s  r!�test_openForReadingOnDirectoryz2IFTPShellTestsMixin.test_openForReadingOnDirectory
s?��	
���U�#��J�J�%�%�h�/���!�!�!�S�%:�%:�;�;r#c�x����jjd�}��fd�}�fd��|j|�|S)zZ
        Check that openForWriting returns an object providing C{ftp.IWriteFile}.
        rGc����jtjj|��|j	�j��Sr)r�r�
IWriteFiler�r�r�)r|�cb2r s ��r!�cb1z4IFTPShellTestsMixin.test_openForWriting.<locals>.cb1+
s5����O�O�C�N�N�5�5�c�:�;��;�;�=�,�,�S�1�1r#c�N���jtj|��yr)r�rr�r{s �r!r�z4IFTPShellTestsMixin.test_openForWriting.<locals>.cb2/
s����O�O�I�0�0��5�6r#)rrrsr�)r r?r�r�s`  @r!�test_openForWritingz'IFTPShellTestsMixin.test_openForWriting%
s6���
�J�J�%�%�h�/��	2�	7�	
�
�
�c���r#c��|jd�|jjd�}|j|tj
�S)zd
        openForWriting should not be able to open a directory that already
        exists.
        rlrm)rDrrrsr�rr�r�s  r!�$test_openForWritingExistingDirectoryz8IFTPShellTestsMixin.test_openForWritingExistingDirectory5
s?��
	
���U�#��J�J�%�%�h�/���!�!�!�S�%:�%:�;�;r#c��|jd�|jjd�}|j|tj
�S)z�
        openForWring should fail with a L{ftp.FileNotFoundError} if you specify
        a file in a directory that doesn't exist.
        rl)rl�idonotexistr9)rDrrrsr�rr,r�s  r!�)test_openForWritingInNotExistingDirectoryz=IFTPShellTestsMixin.test_openForWritingInNotExistingDirectory>
s@��
	
���U�#��J�J�%�%�&C�D���!�!�!�S�%:�%:�;�;r#c����d��jd���jjdd�}��fd�}|j|�|S)z@
        Check the output of the stat method on a file.
        �wobble
rZrd�r�rkc�j���j|dt����j|d�y)Nrr�)r�r�r�)r|rUr s ��r!r1z-IFTPShellTestsMixin.test_statFile.<locals>.cbO
s.������S��V�S��%5�6����S��V�$r#)rVrr�statr�)r r?r1rUs`  @r!�
test_statFilez!IFTPShellTestsMixin.test_statFileG
sE���"�����
�K�0��J�J�O�O�M�+@�A��	%�	
�
�
�b���r#c����jd��jjdd�}�fd�}|j|�|S)zE
        Check the output of the stat method on a directory.
        rlrmr�c�.���j|d�y)Nr�)r�r{s �r!r1z2IFTPShellTestsMixin.test_statDirectory.<locals>.cb]
s����O�O�C��F�#r#�rDrrr�r�r4s`  r!�test_statDirectoryz&IFTPShellTestsMixin.test_statDirectoryV
s@���	
���U�#��J�J�O�O�H�&;�<��	$�	
�
�
�b���r#c����jd��jjdd�}�fd�}|j|�|S)z3
        Check the owner and groups stats.
        rlrm�r�r�c�<���jt|�d�y)Nr�r�r{s �r!r1z3IFTPShellTestsMixin.test_statOwnerGroup.<locals>.cbj
s������S��X�q�)r#r�r4s`  r!�test_statOwnerGroupz'IFTPShellTestsMixin.test_statOwnerGroupc
s@���	
���U�#��J�J�O�O�H�&8�9��	*�	
�
�
�b���r#c����|jj�d����fd�}||j_|jd�|jjdd�}|j	|j|�dg�y)z�
        If L{twisted.python.filepath.FilePath.getNumberOfHardLinks} is not
        implemented, the number returned is 0
        c��t�rrLr3r#r!�raiseNotImplementedzQIFTPShellTestsMixin.test_statHardlinksNotImplemented.<locals>.raiseNotImplementedw
���%�%r#c�&���|�}�|_|Sr)�getNumberOfHardLinks�r�r&�pathFuncr�s  ��r!�notImplementedFilePathzTIFTPShellTestsMixin.test_statHardlinksNotImplemented.<locals>.notImplementedFilePathz
s������A�%8�A�"��Hr#rlrm)�	hardlinksrN�rr�_pathrDr�r��successResultOf�r r�r?r�r�s   @@r!� test_statHardlinksNotImplementedz4IFTPShellTestsMixin.test_statHardlinksNotImplementedp
sk���
�:�:�#�#��	&�	�
2��
�
�����U�#��J�J�O�O�H�n�5������-�-�a�0�1�#�6r#c����|jj�d����fd�}||j_|jd�|jjdd�}|j	|j|�ddg�y)z�
        If L{twisted.python.filepath.FilePath.getUserID} or
        L{twisted.python.filepath.FilePath.getGroupID} are not implemented,
        the owner returned is "0" and the group is returned as "0"
        c��t�rrLr3r#r!r�zRIFTPShellTestsMixin.test_statOwnerGroupNotImplemented.<locals>.raiseNotImplemented�
r�r#c�4���|�}�|_�|_|Sr)�	getUserID�
getGroupIDr�s  ��r!r�zUIFTPShellTestsMixin.test_statOwnerGroupNotImplemented.<locals>.notImplementedFilePath�
s������A�-�A�K�.�A�L��Hr#rlrmr��0Nr�r�s   @@r!�!test_statOwnerGroupNotImplementedz5IFTPShellTestsMixin.test_statOwnerGroupNotImplemented�
sn����:�:�#�#��	&�	�2��
�
�����U�#��J�J�O�O�H�&8�9������-�-�a�0�3��*�=r#c�z�|jjdd�}|j|tj�S)zf
        stat should fail with L{ftp.FileNotFoundError} on a file that doesn't
        exist.
        rGr�)rrr�r�rr,r�s  r!�test_statNotExistingz(IFTPShellTestsMixin.test_statNotExisting�
s2��

�J�J�O�O�H�&;�<���!�!�!�S�%:�%:�;�;r#c��|jd�|jjdd�}|j|t�S)r~rlrmr)rDrrr�r�r�r�s  r!�test_invalidStatz$IFTPShellTestsMixin.test_invalidStat�
s:��	
���U�#��J�J�O�O�H�&>�?���!�!�!�^�4�4r#c����jd��jjdd�}�fd�}|j|�S)z,
        Try to rename a directory.
        rlrmrGc����j�jd���j�jd��y)Nr9rl)r�rNr�r{s �r!r1z+IFTPShellTestsMixin.test_rename.<locals>.cb�
s3����O�O�D�0�0��7�8����T�1�1�%�8�9r#)rDrrrxr�r4s`  r!�test_renamezIFTPShellTestsMixin.test_rename�
s?���	
���U�#��J�J���h��1��	:��}�}�R� � r#c�z�|jjdd�}|j|tj�S)zl
        Renaming a directory that doesn't exist should fail with
        L{ftp.FileNotFoundError}.
        rGra)rrrxr�rr,r�s  r!�test_renameNotExistingz*IFTPShellTestsMixin.test_renameNotExisting�
s3��

�J�J���h��1���!�!�!�S�%:�%:�;�;r#N�r#)(r5r6r7r�rNrDrRrVrXr[r�r_r�rergr�rnrprxr|r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r3r#r!rJrJs����$�$�$�$�5�5�	!�:�
!�?�<��<�<�!�!�45�!�<��<��<�<�� <�<�
���7�*>�.<�5�!�<r#rJc�0�eZdZdZd�Zd�Zd�Zd�Zdd�Zy)	�
FTPShellTestsz/
    Tests for the C{ftp.FTPShell} object.
    c���tj|j��|_|jj	�tj|j�|_y)zB
        Create a root directory and instantiate a shell.
        N)rrnrjr�rDrr�rrrs r!r�zFTPShellTests.setUp�
s@���%�%�d�k�k�m�4��	��	�	�!�!�#��\�\�$�)�)�,��
r#c�T�|jj|�j�S)z:
        Test if the directory exists at C{path}.
        )r�r@�isdirrMs  r!rNzFTPShellTests.directoryExists�
s ���y�y���t�$�*�*�,�,r#c�T�|jj|�j�S)z0
        Create a directory in C{path}.
        )r�r@rDrMs  r!rDzFTPShellTests.createDirectory�
s ���y�y���t�$�4�4�6�6r#c�T�|jj|�j�S)z5
        Test if the file exists at C{path}.
        )r�r@�isfilerMs  r!rRzFTPShellTests.fileExists�
s ���y�y���t�$�+�+�-�-r#c�V�|jj|�j|�S)z@
        Create a file named C{path} with some content.
        )r�r@�
setContentrTs   r!rVzFTPShellTests.createFile�
s"���y�y���t�$�/�/��<�<r#Nr�)	r5r6r7r�r�rNrDrRrVr3r#r!r�r��
s ���-�-�7�.�=r#r�c�&�eZdZdZdZd�Zd�Zd�Zy)�TestConsumerz�
    A simple consumer for tests. It only works with non-streaming producers.

    @ivar producer: an object providing
        L{twisted.internet.interfaces.IPullProducer}.
    Nc�p�|j�J�g|_||_|jj�y)z�
        Simple register of producer, checks that no register has happened
        before.

        @param producer: pull producer to use
        @param streaming: unused
        N)�producerr=�resumeProducing)r r��	streamings   r!�registerProducerzTestConsumer.registerProducer�
s2���}�}�$�$�$���� ��
��
�
�%�%�'r#c�.�|j�J�d|_y)zN
        Unregister the producer, it should be done after a register.
        N)r�rs r!�unregisterProducerzTestConsumer.unregisterProducers���}�}�(�(�(���
r#c�n�|jj|�|jj�y)zN
        Save the data received.

        @param data: data to append
        N)r=r)r�r�r/s  r!rzTestConsumer.writes&��	
�����4� ��
�
�%�%�'r#)r5r6r7r�r�r�r�rr3r#r!r�r��
s����H�(��(r#r�c��eZdZdZd�Zd�Zy)�TestProducerz
    A dumb producer.
    c� �||_||_y)z�
        @param toProduce: data to write
        @type toProduce: C{str}
        @param consumer: the consumer of data.
        @type consumer: C{IConsumer}
        N)�	toProducer�)r r�r�s   r!r"zTestProducer.__init__s��#��� ��
r#c�N�|jj|j�y)z+
        Send the data to consume.
        N)r�rr�rs r!�startzTestProducer.start s��	
�
�
���D�N�N�+r#N)r5r6r7r�r"r�r3r#r!r�r�s���!�,r#r�c�.�eZdZdZd�Zd�Zd�Zd�Zd�Zy)�IReadWriteTestsMixinzJ
    Generic tests for the C{IReadFile} and C{IWriteFile} interfaces.
    c��t��)z
        Return an object providing C{IReadFile}, ready to send data C{content}.

        @param content: data to send
        rL�r �contents  r!�
getFileReaderz"IReadWriteTestsMixin.getFileReader,s
��"�#�#r#c��t��)zR
        Return an object providing C{IWriteFile}, ready to receive data.
        rLrs r!�
getFileWriterz"IReadWriteTestsMixin.getFileWriter4�
��"�#�#r#c��t��)z6
        Return the content of the file used.
        rLrs r!�getFileContentz#IReadWriteTestsMixin.getFileContent:r�r#c�|�����d�t����fd�}���fd���j��j|�S)z�
        Test L{ftp.IReadFile}: the implementation should have a send method
        returning a C{Deferred} which fires when all the data has been sent
        to the consumer, and the data should be correctly send to the consumer.
        r�c�D��|j��j��Sr)r�r�)�reader�cbSendr�s ��r!r�z-IReadWriteTestsMixin.test_read.<locals>.cbGetIs����;�;�x�(�4�4�V�<�<r#c�\���jdj�j���yr<)r�rr=)r|r�r�r s ���r!r�z.IReadWriteTestsMixin.test_read.<locals>.cbSendLs ������S�X�X�h�o�o�6��@r#)r�r�r�)r r�r�r�r�s` @@@r!�	test_readzIReadWriteTestsMixin.test_read@s:������>��	=�	A��!�!�'�*�6�6�u�=�=r#c�n�����d��fd�}��fd����fd���j�j|�S)a
        Test L{ftp.IWriteFile}: the implementation should have a receive
        method returning a C{Deferred} which fires with a consumer ready to
        receive data to be written. It should also have a close() method that
        returns a Deferred.
        selbbow
c�D��|j�j�|�Sr)r�r�)�writer�	cbReceives �r!r�z.IReadWriteTestsMixin.test_write.<locals>.cbGetZs����>�>�#�/�/�	�6�B�Br#c���t�|�}|jdd�|j�|j�|j	�j��S)NT)r�r�r�r��closer�)r�r�r��cbCloser�s   ��r!r�z2IReadWriteTestsMixin.test_write.<locals>.cbReceive]sL���#�G�X�6�H��%�%�d�D�1��N�N���'�'�)��<�<�>�-�-�g�6�6r#c�F���j�j���yr)r�r�)r�r�r s ��r!rz0IReadWriteTestsMixin.test_write.<locals>.cbCloseds������T�0�0�2�G�<r#)r�r�)r r�rr�r�s` @@@r!�
test_writezIReadWriteTestsMixin.test_writeQs6�����	C�	7�	=��!�!�#�/�/��6�6r#N)	r5r6r7r�r�r�r�r�rr3r#r!r�r�'s ���$�$�$�>�"7r#r�c�(�eZdZdZd�Zd�Zd�Zd�Zy)�FTPReadWriteTestsz�
    Tests for C{ftp._FileReader} and C{ftp._FileWriter}, the objects returned
    by the shell in C{openForReading}/C{openForWriting}.
    c���tj|j��|_|jj	�tj|j�|_d|_y)z5
        Create a temporary file used later.
        rZN)	rrnrjr�rDrr�rrr�rs r!r�zFTPReadWriteTests.setUppsG���%�%�d�k�k�m�4��	��	�	�!�!�#��\�\�$�)�)�,��
�"��
r#c��|jj|j�j|�|jj|jf�S)zV
        Return a C{ftp._FileReader} instance with a file opened for reading.
        )r�r@r�r�rrr�r�s  r!r�zFTPReadWriteTests.getFileReaderys?��	
�	�	����
�
�&�1�1�'�:��z�z�(�(�$�-�-�)9�:�:r#c�N�|jj|jf�S)zV
        Return a C{ftp._FileWriter} instance with a file opened for writing.
        )rrrsr�rs r!r�zFTPReadWriteTests.getFileWriter�s ���z�z�(�(�$�-�-�)9�:�:r#c�h�|jj|j�j�S)z;
        Return the content of the temporary file.
        )r�r@r��
getContentrs r!r�z FTPReadWriteTests.getFileContent�s$���y�y���t�}�}�-�8�8�:�:r#N)r5r6r7r�r�r�r�r�r3r#r!rrjs���
#�;�;�;r#rc� �eZdZdZdZd�Zd�Zy)�CloseTestWriterz"
    Close writing to a file.
    Fc��t�|_tj|j�}t	j
|�S)z>
        Receive bytes.

        @return: L{Deferred}
        )rr=r�FileConsumerrr�)r �fcs  r!r�zCloseTestWriter.receive�s0���i���
�
�
�d�k�k�
*���}�}�R� � r#c�(�d|_|jS)z<
        Close bytes.

        @return: L{Deferred}
        T)�closeStartedr?rs r!rzCloseTestWriter.close�s��!����v�v�
r#N)r5r6r7r�rr�rr3r#r!rr�s����L�!�r#rc��eZdZdZd�Zy)�CloseTestShellz
    Close writing shell.
    c�@�tj|j�Sr)rr�r�)r �segss  r!rszCloseTestShell.openForWriting�s���}�}�T�[�[�)�)r#N)r5r6r7r�rsr3r#r!rr�s���*r#rc��eZdZdZd�Zy)�
FTPCloseTestsz8
    Tests that the server invokes IWriteFile.close
    c�\�tj�}dg|_t�|_t�|j_tj�|jj_	tj�|_d|j_|jt��tj�}tj |�|_||_|jd�g}|j%d�}|j'|j(�|j+|jjj,d�|j/d�|j+|jjj,d�|j1d�|j3|jjj,d�|j+|�|jjjj5d�|j3|�|S)	z�
        Confirm that FTP uploads (i.e. ftp_STOR) correctly call and wait
        upon the IWriteFile object's close() method
        r�Nr�zclose() called earlyssome data herezreason is ignoredzclose() not calledzallow close() to finish)r�FTP�workingDirectoryrrrrr�rr>r?rzr%�timeOutrdrrOrCri�ftp_STORr�r)r�rrBrFr�rD)r r&�di�	stor_doner?s     r!rzFTPCloseTests.test_write�sz��

�G�G�I��$�X��� �"���(�*����� �>�>�+��������N�N�$��	� ��	�	��	�����#�
�W�W�Y���^�^�A�&��
���
�
���$���	�
�J�J�v���	�
�
�i�&�&�'���������4�4�6L�M�
���)�*���������4�4�6L�M�
���-�.���������3�3�5I�J�����#�	�������!�!�";�<����	�"��r#N)r5r6r7r�rr3r#r!rr�s���!r#rc��eZdZdZd�Zy)�FTPResponseCodeTestsz4
    Tests relating directly to response codes.
    c	�r�ttj�}t�}tt�j	�D]t\}}t|t�s�|j�s�(|j||dj||��|j||d|�d|���|j|��vy)z�
        All of the response code globals (for example C{RESTART_MARKER_REPLY} or
        C{USR_NAME_OK_NEED_PASS}) have unique values and are present in the
        C{RESPONSE} dictionary.
        z4Code {!r} with value {!r} missing from RESPONSE dictzDuplicate code z with value N)�setr�RESPONSE�vars�items�
isinstancer!�isupperr^r�assertNotIn�add)r �	allValues�
seenValues�keyr�s     r!�test_uniquez FTPResponseCodeTests.test_unique�s�������%�	��U�
��s�)�/�/�+�	&�J�C���%��%�#�+�+�-��
�
���J�Q�Q��U���� � ���%�c�W�L��	�B��
���u�%�	&r#N)r5r6r7r�r-r3r#r!r r �s���&r#r )rVr)Qr�r*rrlrr�ior�zope.interfacer�zope.interface.verifyr�twisted.credrrr�twisted.cred.errorr	�twisted.cred.portalr
�twisted.internetrrr
rr�twisted.internet.interfacesr�twisted.protocolsrrr�twisted.pythonrrr�twisted.testr�twisted.trial.unittestr�platform�	isWindowsr$�LineReceiverrr�r:rNrPr�r�rwr�rr:r^rjrrrorvr�r�r�r�r�r�rrr'rErJr�r�r�r�rr�rrrr r3r#r!�<module>r=ss���
��	�
�
��&�-�6�6�0�&�B�B�1�2�2�5�5�&�+����!�!�#��L�*�L�
�E���
�(	��*�*�	�
*�K
��K
�\
�)�
�2G�+�G�Tp�#4�p�ff,�'8�f,�RO,�'G�O,�d~�h�~�B":�x�":�P(��"�"�(� �C�3�3� �J$�(�J$�Z>��>�Bm.�X�m.�`u;�(�u;�pIK��IK�XK��K�D4Q��4Q�nM�H�M�4&K�(�&K�R87�(�87�v
�X�
� h<�h<�V
#=�H�1�#=�L
�Y��%(�%(��%(�P,�,�,@7�@7�F ;��"6� ;�F
�S�^�^������6*�*�&�H�&�R&�8�&r#

Zerion Mini Shell 1.0