%PDF- %PDF-
Mini Shell

Mini Shell

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

�

Ϫ�fZ����dZddlZddlZddlZddlmZ	ddlZddlm	Z	ddl
mZmZm
Z
mZddlmZddlmZmZmZmZddlmZdd	lmZdd
lmZddlmZmZddlm Z dd
l!m"Z"ddl#m$Z$ddl%m&Z&m'Z'Gd�d�Z(Gd�de'�Z)e*ed�r#ejV�Z,ejZ�Z.ndxZ,Z.Gd�de'�Z/Gd�de'�Z0Gd�de'�Z1Gd�de'�Z2Gd�de'�Z3Gd�d ejh�Z5Gd!�d"�Z6Gd#�d$�Z7Gd%�d&ejp�Z9Gd'�d(e'�Z:Gd)�d*e'�Z;Gd+�d,e
jx�Z=Gd-�d.e$e'�Z>Gd/�d0e'�Z?Gd1�d2e'�Z@y#e$rdZY��jwxYw)3zU
Tests for L{twisted.application} and its interaction with
L{twisted.persisted.sob}.
�N)�StringIO)�skipIf)�app�internet�reactors�service)�
backoffPolicy)�defer�
interfaces�protocol�reactor)�
MemoryReactor)�sob)�twisted_reactors)�basic�wire)�usage)�platformType)�TwistedModulesMixin)�SkipTest�TestCasec��eZdZdZy)�DummyN)�__name__�
__module__�__qualname__�processName���?/usr/lib/python3/dist-packages/twisted/test/test_application.pyrr#s���Krrc�Z�eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zy)�ServiceTestsc��tj�}|jd�|j|jd�y�N�hello)r�Service�setName�assertEqual�name��self�ss  r �testNamezServiceTests.testName(s.���O�O���	�	�	�'���������)rc���tj�}tj�}|j|�|j	t|�|g�|j	|j|�y�N)rr&�MultiService�setServiceParentr(�list�parent�r+r,�ps   r �
testParentzServiceTests.testParent-sT���O�O���� � �"��	���1������a��1�#�&�������1�%rc�4�tj�}tjd�}|j|�|j	ttj|��|g�|j	|jtj|��y)N�)rr&�Applicationr1r(r2�IServiceCollectionr3r4s   r �testApplicationAsParentz$ServiceTests.testApplicationAsParent4sm���O�O�������#��	���1������g�8�8��;�<�q�c�B�������7�#=�#=�a�#@�Arc�J�tj�}tj�}|jd�|j	|�|jt
|�|g�|j|j|�|j|jd�|�yr$)	rr&r0r'r1r(r2r3�getServiceNamedr4s   r �testNamedChildzServiceTests.testNamedChild;s{���O�O���� � �"��	�	�	�'��	���1������a��1�#�&�������1�%�����*�*�7�3�Q�7rc���tj�}tj�}|jd�|j	|�|jt|jd�y)Nr%�lala�rr&r0r'r1�assertRaises�RuntimeErrorr4s   r �testDoublyNamedChildz!ServiceTests.testDoublyNamedChildDsL���O�O���� � �"��	�	�	�'��	���1�����,��	�	�6�:rc�$�tj�}tj�}|jd�|j	|�tj�}|jd�|jt|j|�yr$rAr4s   r �testDuplicateNamedChildz$ServiceTests.testDuplicateNamedChildKsf���O�O���� � �"��	�	�	�'��	���1���O�O���	�	�	�'�����,��(:�(:�A�>rc�r�tj�}tj�}|j|�|j	t|�|g�|j	|j|�|j�|j	t|�g�|j|j�yr/)	rr&r0r1r(r2r3�disownServiceParent�assertIsNoner4s   r �
testDisowningzServiceTests.testDisowningTs����O�O���� � �"��	���1������a��1�#�&�������1�%�	��������a��"�%����!�(�(�#rc��tj�}|j|j�|j	�|j|j�|j
�|j|j�yr/)rr&�assertFalse�running�startService�
assertTrue�stopServicer*s  r �testRunningzServiceTests.testRunning^sU���O�O���������#�	��������	�	�"�	�
�
��������#rc��tj�}tj�}|j|�|j	|j
�|j	|j
�|j
�|j|j
�|j|j
�|j�|j	|j
�|j	|j
�yr/)	rr&r0r1rLrMrNrOrPr4s   r �testRunningChildren1z!ServiceTests.testRunningChildren1fs����O�O���� � �"��	���1��������#�������#�	��������	�	�"�����	�	�"�	�
�
��������#�������#rc�,���tj����fd�}tj�}||_||_tj�}�j|�|j|�|j�|j�y)Nc�<���j�j�yr/)rOrM)r,r+s��r �checkRunningz7ServiceTests.testRunningChildren2.<locals>.checkRunningvs����O�O�A�I�I�&r)rr&rPrNr0r1)r+rV�tr5r,s`   @r �testRunningChildren2z!ServiceTests.testRunningChildren2ssm����O�O���	'�
�O�O���$��
�%���� � �"��	���1��	���1��	����	�
�
�rc�X�tj�}|j�tj�}|j	|j
�|j
|�|j|j
�|j�|j	|j
�yr/)	rr0rNr&rLrMr1rOrH)r+r5r,s   r �testAddingIntoRunningz"ServiceTests.testAddingIntoRunning�st��� � �"��	�����O�O���������#�	���1������	�	�"�	����������#rc�0��tj���fd�}|�_tj�}tj�}�j	|�|j	|�|j�|j�j�y)Nc���d�_y�N�)�privilegedStarted)r,s�r �pssz(ServiceTests.testPrivileged.<locals>.pss�s���"#�A�r)rr&�privilegedStartServicer0r1rOr_)r+r`�s1r5r,s    @r �testPrivilegedzServiceTests.testPrivileged�sr����O�O���	$�$'�� �
�_�_�
��� � �"��	���1��
���A��	� � �"�����+�+�,rc���tj�}|j�tj|�}|j	|j
�|j
|j
�yr/)rr&rN�copyrLrMrO)r+r,rbs   r �testCopyingzServiceTests.testCopying�sG���O�O���	����
�Y�Y�q�\��������$�����	�	�"rN)rrrr-r6r;r>rDrFrJrQrSrXrZrcrfrrr r"r"'sD��*�
&�B�8�;�?�$�$�$�
�$�-�#rr"�getuidc��eZdZd�Zd�Zd�Zy)�ProcessTestsc��tjdd�}|j|jd�|j|jd�y)N��)r�Processr(�uid�gid�r+r5s  r �testIDzProcessTests.testID�s:���O�O�A�q�!���������"��������"rc���tjd�}|j|jd�|j	|j
�tjd��}|j	|j�|j|j
d�tj�}|j	|j�|j	|j
�y)Nrk)ro)rrmr(rnrIrorps  r �testDefaultszProcessTests.testDefaults�s����O�O�A����������"����!�%�%� ��O�O��"�����!�%�%� ��������"��O�O������!�%�%� ����!�%�%� rc��tj�}|j|j�d|_|j	|jd�yr$)rrmrIrr(rps  r �testProcessNamezProcessTests.testProcessName�s;���O�O������!�-�-�(���
��������0rN)rrrrqrsrurrr riri�s��#�
	!�1rric��eZdZd�Zd�Zd�Zy)�InterfacesTestsc��|jtjjtj���yr/)rOr�IService�
providedByr&�r+s r �testServicezInterfacesTests.testService��&������(�(�3�3�G�O�O�4E�F�Grc��|jtjjtj���|jtj
jtj���yr/)rOrryrzr0r:r{s r �testMultiServicez InterfacesTests.testMultiService�sN������(�(�3�3�G�4H�4H�4J�K�L�����2�2�=�=�g�>R�>R�>T�U�Vrc��|jtjjtj���yr/)rOr�IProcessrzrmr{s r �testProcesszInterfacesTests.testProcess�r}rN)rrrr|rr�rrr rwrw�s��H�W�Hrrwc�$�eZdZd�Zd�Zd�Zd�Zy)�ApplicationTestsc��tjd�tjdd�tjddd�y�Nr%rkrl)rr9r{s r �testConstructorz ApplicationTests.testConstructor�s2�����G�$����G�Q�'����G�Q��*rc��tjd�}|jtj|�j�|jtj|�j
�tjdd�}|j
tj|�jd�|jtj|�j
�tjddd�}|j
tj|�jd�|j
tj|�j
d�yr�)rr9rIr�rnror(�r+�as  r �testProcessComponentz%ApplicationTests.testProcessComponent�s�������(�����'�*�*�1�-�1�1�2����'�*�*�1�-�1�1�2������+������)�)�!�,�0�0�!�4����'�*�*�1�-�1�1�2������A�.������)�)�!�,�0�0�!�4�����)�)�!�,�0�0�!�4rc�X�tjd�}|jtj|�tj|��|jtj|�jd�|jtj|�j�yr$)	rr9�assertIsryr:r(r)rIr3r�s  r �testServiceComponentz%ApplicationTests.testServiceComponent�sv������(���
�
�g�&�&�q�)�7�+E�+E�a�+H�I�����)�)�!�,�1�1�7�;����'�*�*�1�-�4�4�5rc��tjd�}tj|�}|j	|j
d�|j	|jd�|j|j|�y)Nr%�pickle)	rr9r�IPersistabler(�styler)r��original)r+r�r5s   r �testPersistableComponentz)ApplicationTests.testPersistableComponent�s\������(�����Q���������(�+��������)��
�
�a�j�j�!�$rN)rrrr�r�r�r�rrr r�r��s��+�
	5�6�%rr�c��eZdZd�Zy)�LoadingTestsc�L�tjd�}tj|�}dj	�D]n}|j|�|j
�tjd|dz|�}|jtj|�jd��ptdd�5}|jddg�ddd�tjdd	�}|jtj|�jd�y#1swY�OxYw)
Nr%�
source picklezhello.tarz	hello.tac�w�(from twisted.application import service
�+application = service.Application('hello')
�python)
rr9rr��split�setStyle�save�loadApplicationr(ryr)�open�
writelines)r+r�r5r��a1�fs      r �test_simpleStoreAndLoadz$LoadingTests.test_simpleStoreAndLoad�s�������(�����Q���$�*�*�,�	A�E�
�J�J�u��
�F�F�H��(�(��e�A�h�)>��F�B����W�-�-�b�1�6�6��@�		A�
�+�s�
#�	�q�
�L�L�?�B��
�	��
$�
$�[�(�
;������)�)�"�-�2�2�G�<�	�	�s�8D�D#N)rrrr�rrr r�r��s��=rr�c�$�eZdZd�Zd�Zd�Zd�Zy)�AppSupportTestsc�L�|jtjd��y)Nr)rIr�
getPassphraser{s r �testPassphrasezAppSupportTests.testPassphrases�����#�+�+�A�.�/rc���tjd�}dddd�}dj�D]�}|j�}d|ddij	||�<tj|�j|�tj|�jd��tj|d�}|jtj|�jd���|j�}d|d	<tdd
�5}|jddg�ddd�tj|d�}|jtj|�jd�y#1swY�OxYw)
zL
        Test loading an application file in different dump format.
        r%N)�file�sourcer�r��helloapplicationr�r���filenamer�r�r�r�)rr9r�re�getrr�r�r�r�getApplicationr(ryr)r�r�)r+r��
baseconfigr��configr�r�s       r �testLoadApplicationz#AppSupportTests.testLoadApplicationsQ��
����(��"�d�d�C�
�$�*�*�,�	A�E��_�_�&�F�;M�F�H�f�%�)�)�%��7�8����Q��(�(��/����Q��$�$�.@�$�A��#�#�F�D�1�B����W�-�-�b�1�6�6��@�
	A����"��-��x��
�$�c�
*�	�a�
�L�L�?�B��
�	��
�
���
-������)�)�"�-�2�2�G�<�	�	�s�E)�)E2c
���tjd�}dj�D]�}dj�D]�}tj|�j|�tj|�j
d��tjd|dd|d�tjd|�}|jtj|�jd�����y)Nr@r��converttestr�zconverttest.outr)
rr9r�rr�r�r�r�convertStyler�r(ryr))r+�appl�instyle�outstyle�appl2s     r �test_convertStylez!AppSupportTests.test_convertStyles����"�"�6�*��&�,�,�.�	G�G�+�1�1�3�
G��� � ��&�/�/��8�� � ��&�+�+�]�+�C�� � �!�7�D�2C�X�q�� �/�/�0A�8�L��� � ��!1�!1�%�!8�!=�!=�v�F�
G�	Grc��tjd�}tj|d�|j	tj
|�j�y)Nr@r)rr9r�startApplicationrOryrM)r+r�s  r �test_startApplicationz%AppSupportTests.test_startApplication)s?���"�"�6�*�����T�1�%�����(�(��.�6�6�7rN)rrrr�r�r�r�rrr r�r�s��0�=�2
G�8rr�c��eZdZd�Zd�Zd�Zy)�Fooc�:�|jjd�y)Nslalala
)�	transport�writer{s r �connectionMadezFoo.connectionMade0s�������]�+rc�Z�||j_|jj�yr/)�factory�liner��loseConnection)r+r�s  r �lineReceivedzFoo.lineReceived3s�� ��������%�%�'rc�v�|jjj|jj�yr/)r��d�callbackr��r+�reasons  r �connectionLostzFoo.connectionLost7s"������������ 1� 1�2rN)rrrr�r�r�rrr r�r�/s��,�(�3rr�c��eZdZdZd�Zd�Zy)�DummyAppNc�6�||j|j<yr/��servicesr)�r+rs  r �
addServicezDummyApp.addService>s��&-��
�
�g�l�l�#rc�2�|j|j=yr/r�r�s  r �
removeServicezDummyApp.removeServiceAs���M�M�'�,�,�'r)rrrrr�r�rrr r�r�;s���K�.�(rr�c��eZdZd�Zd�Zy)�TimerTargetc��g|_yr/)�lr{s r �__init__zTimerTarget.__init__Fs	����rc�:�|jj|�yr/)r��append)r+�whats  r r�zTimerTarget.appendIs�����
�
�d�rN)rrrr�r�rrr r�r�Es���rr�c��eZdZd�Zy)�TestEchoc�:�|jjd�y�NT)r�r�r�s  r r�zTestEcho.connectionLostNs��������rN)rrrr�rrr r�r�Ms��rr�c� �eZdZd�Zd�Zd�Zd�Zeeje
d�d�d��Zd�Zeeje
d�d�d	��Z
eeje
d�d�d
��Zd�Zd�Zd
�Zd�Zd�Zd�Zd�Zd�Zy)�
InternetTestsc���tj���j�tj�}t
|_t
j�t
_tjd|�}|j��|jj�j}tj�}t
j�|_t |_d|_tj$d||�j��|jj'|j(d�|jj'�fd��|jj'd��|jS)Nr�	127.0.0.1�lalalac�$���j�Sr/�rP��xr,s �r �<lambda>z'InternetTests.testTCP.<locals>.<lambda>b�
����
�
��rc�"�tjSr/�r�r��r�s r r�z'InternetTests.testTCP.<locals>.<lambda>c�
���
�
�r)rr0rNr�
ServerFactoryr�r
�Deferredr�r�	TCPServerr1�_port�getHost�port�
ClientFactoryr�r��	TCPClient�addCallbackr()r+r�rW�numr,s    @r �testTCPzInternetTests.testTCPSs���� � �"��	�����(�(�*��#����^�^�%��
����q�'�*��	���1���g�g�o�o��$�$���(�(�*���N�N�$��	����������;��W�5�F�F�q�I��	�	���d�.�.�	�:��	�	���7�8��	�	���2�3��y�y�rc����tjtd�std��t	j
��t
jd��}|j�|jj�j�|j�d���fd�}tj|j�j!|�S)z�
        Test L{internet.UDPServer} with a random port: starting the service
        should give it valid port, and stopService should free it so that we
        can start a server on the same port again.
        Nz)This reactor does not support UDP socketsrc�p��tj���}|j�|j�Sr/)r�	UDPServerrNrP)�ignoredrWr�r5s  ��r �onStopz&InternetTests.test_UDP.<locals>.onStopts+����"�"�3��*�A�
�N�N���=�=�?�"r)r�IReactorUDPr
rr�DatagramProtocolrrrNr�r�r��assertNotEqualr
�
maybeDeferredrPr�)r+rWrr�r5s   @@r �test_UDPzInternetTests.test_UDPfs�����%�%�g�t�4��F�G�G��%�%�'�����q�!�$��	�����g�g�o�o��$�$�����C��#�	#�
�"�"�1�=�=�1�=�=�f�E�Erc����tj�}t|_tj�t_t
jd|��d�_�j��jj�j}tj�}tj�|_t|_d|_t
j d||���j#�|j
j%|j&d�|j
j%�fd��|j
j%�fd��|j
j%d��|j
S)Nrr^r�r�c�$���j�Sr/r�)r��cs �r r�z.InternetTests.testPrivileged.<locals>.<lambda>�r�rc�$���j�Sr/r��r�rWs �r r�z.InternetTests.testPrivileged.<locals>.<lambda>�r�rc�"�tjSr/r�r�s r r�z.InternetTests.testPrivileged.<locals>.<lambda>�r�r)rr�r�r
r�r�rr��
privilegedrar�r�r�r�r�r�r�rNr�r()r+r�r�r
rWs   @@r rczInternetTests.testPrivileged{s����(�(�*��#����^�^�%��
����q�'�*�����	� � �"��g�g�o�o��$�$���(�(�*���N�N�$��	����������{�C��9��	�����	�	���d�.�.�	�:��	�	���7�8��	�	���7�8��	�	���2�3��y�y�rc���tj�}tj|_t	j
d|�}|j
�|jj�j}|j�tj��tj�}�fd�|_t	jd||�}|j
��S)Nrc�&���jd�Sr/�r���argsr�s �r r�z<InternetTests.testConnectionGettingRefused.<locals>.<lambda>�����q�z�z�$�7G�rr�)rr�r�Echorr�rNr�r�r�rPr
r�r��clientConnectionFailedr�)r+r�rWr�r
r�s     @r �testConnectionGettingRefusedz*InternetTests.testConnectionGettingRefused�s�����(�(�*���9�9������q�'�*��	�����g�g�o�o��$�$��	�
�
���N�N����(�(�*��)G��&����{�C��9��	�����rNz1This reactor does not support UNIX domain socketsc���tj���j�tj�}t
|_t
j�t
_tjd|�}|j��tj�}t|_t
j�|_d|_tjd|�j��|jj!|j"d�|jj!�fd��|jj!d��|jj!|j$|��|jS)N�echo.sktr�c�$���j�Sr/r�r�s �r r�z(InternetTests.testUNIX.<locals>.<lambda>�r�rc�"�tjSr/r�r�s r r�z(InternetTests.testUNIX.<locals>.<lambda>�r�r)rr0rNrr�r�r
r�r�r�
UNIXServerr1r�r�r��
UNIXClientr�r(�_cbTestUnix)r+r�rWr,s   @r �testUNIXzInternetTests.testUNIX�s
���
� � �"��	�����(�(�*��#����^�^�%��
����
�G�4��	���1���(�(�*������N�N�$��	�������J��0�A�A�!�D��	�	���d�.�.�	�:��	�	���7�8��	�	���2�3��	�	���d�.�.���;��y�y�rc�v��tj�t_d|_tj�|_�j�|jj
|jd�|jj
�fd��|jj
d��|jS)Nr�c�$���j�Sr/r�r�s �r r�z+InternetTests._cbTestUnix.<locals>.<lambda>�r�rc�"�tjSr/r�r�s r r�z+InternetTests._cbTestUnix.<locals>.<lambda>�r�r)r
r�r�r�r�rNr�r()r+rr�r,s   `r r!zInternetTests._cbTestUnix�sz����^�^�%��
�����N�N�$��	�	�����	�	���d�.�.�	�:��	�	���7�8��	�	���2�3��y�y�rc��tj�}tj|_t	j
d|�}|j
�|j|jd�tj|�}|j|j�|j�|j|j�|j|j�tj�}tj|_t	jd|�}|j
�|j|j d�tj|�}|j|j �|j�|j|j �|j|j�y)Nr)rr�rrrrrN�failIfIdenticalr�rerIrPrLrMr�r �_connection)r+r�rW�t1s    r �testVolatilezInternetTests.testVolatile�s0��
�(�(�*���9�9������
�G�4��	�������Q�W�W�d�+�
�Y�Y�q�\�����"�(�(�#�	�
�
�����!�'�'�"�������#��(�(�*���9�9������
�G�4��	�������Q�]�]�D�1�
�Y�Y�q�\�����"�.�.�)�	�
�
�����!�-�-�(�������#rc���tj�}tj|_t	j
d|�}|j
�|j�|j|j�tj�}tj���fd�|_
tjd|��S)Nrc�&���jd�Sr/rrs �r r�z2InternetTests.testStoppingServer.<locals>.<lambda>�rr)rr�rrrrrNrPrLrMr�r
r�rr
�connectUNIX)r+r�rWr�s   @r �testStoppingServerz InternetTests.testStoppingServer�s����
�(�(�*���9�9������
�G�4��	����	�
�
��������#��(�(�*���N�N���)G��&����J��0��rc�$�t�}tjd|jd�}|j	�tj|�}|j�tj|�}|j|j�y)Nr^r%)r�r�TimerServicer�rNr��dumpsrP�loadsrLrM)r+�target�t0r,rWs     r �testPickledTimerzInternetTests.testPickledTimer�sb�����
�
"�
"�1�f�m�m�W�
=��
�����L�L����
�����L�L��O��������#rc������tj��tjdd����j���fd�}|�_�j��j
�fd���j
�fd���S)Nr^c��ddzS)Nr^rrrrr r�z/InternetTests.testBrokenTimer.<locals>.<lambda>�s
��Q�!�V�rc�8���|��jd�yr/r)�whyr��	oldFaileds ��r �_failedz.InternetTests.testBrokenTimer.<locals>._failed�s����c�N�
�J�J�t�rc����jSr/r�rs �r r�z/InternetTests.testBrokenTimer.<locals>.<lambda>s����
�
�rc����jtg�jt�D�cgc]}|jj��c}�Scc}wr/)r(�ZeroDivisionError�flushLoggedErrors�value�	__class__)r��or+s  �r r�z/InternetTests.testBrokenTimer.<locals>.<lambda>s?���d�&�&�"�#�,0�,B�,B�CT�,U�V�q����"�"�V����Vs�A
)r
r�rr0r;rNr�)r+r;r�r:rWs` @@@r �testBrokenTimerzInternetTests.testBrokenTimer�sg����N�N����!�!�!�^�4���I�I�	�	���	�	����	�
�
�-�.�	�
�
�
�	
��rc	�0�gd�}|ddD]2}ttd|z�td�r�"|j|��4|D]�}dD]�}|dk(r|dk(r�|dk(r|dk(r�|j	tt||z��tt||z�j}dd	d�|}|j	tt||z�xs|d	k(xr|dk(�tt||z��}|jtj|�|�����y)
z�
        L{twisted.application.internet} dynamically defines a set of
        L{service.Service} subclasses that in general have corresponding
        reactor.listenXXX or reactor.connectXXX calls.
        )�TCP�UNIX�SSL�UDP�UNIXDatagram�	MulticastN�IReactor)�Server�ClientrJrMrH�listen�connect)�getattrrr
�removerO�hasattrr�methodr(rry)r+�trans�tran�siderS�prefixrBs       r �test_everythingTherez"InternetTests.test_everythingThere
s#��K���!�H�	#�D�9�7�:�z�D�'8�9�'�4�H����T�"�	#��	9�D�,�

9���;�&�4�8�+;���5�=�T�X�%5�������$��+� >�?� ��4�$�;�7�>�>��$,�	�B�4�H������G�V�f�_�5�A��)�+�?��%���3�G�H�d�T�k�2�4��� � ��!1�!1�!�!4�a�8�

9�	9rc�t�tjD]%}|jtt|�|�d���'y)z�
        L{twisted.application.internet} dynamically defines L{service.Service}
        subclasses. This test ensures that the subclasses exposed by C{__all__}
        are valid attributes of the module.
        z1 not importable from twisted.application.internetN)r�__all__rOrR)r+�clss  r �test_importAllzInternetTests.test_importAll$s:���#�#�	�C��O�O���#�&��%�H�I�
�	rc���t�}t�}tjd||��}|j	�|j|jj�ddd|f�y)z�
        L{internet._AbstractServer} supports a C{reactor} keyword argument
        that can be used to parametrize the reactor used to listen for
        connections.
        ���r
N�)r�objectrr�rNr(�
tcpServers�pop�r+r
r�rWs    r �#test_reactorParametrizationInServerz1InternetTests.test_reactorParametrizationInServer0sZ�� �/���(�����t�W�g�>��	��������+�+�/�/�1�"�1�5��g��Grc���t�}tj�}tjdd||��}|j�|j
|jj�dddd|f�y)z�
        L{internet._AbstractClient} supports a C{reactor} keyword arguments
        that can be used to parametrize the reactor used to create new client
        connections.
        r�r^r_N�)	rrr�rr�rNr(�
tcpClientsrcrds    r �#test_reactorParametrizationInClientz1InternetTests.test_reactorParametrizationInClient=sf�� �/���(�(�*�����{�D�'�7�K��	��������+�+�/�/�1�"�1�5��T�7�7S�Trc��t�}tj�}tjd||��}|j�|j
|jj�ddd|f�|j�|j�|j
|jj�ddd|f�y)z�
        Like L{test_reactorParametrizationInServer}, but stop and restart the
        service and check that the given reactor is still used.
        r^r_Nr`)
rr�Factoryrr�rNr(rbrcrPrds    r �0test_reactorParametrizationInServerMultipleStartz>InternetTests.test_reactorParametrizationInServerMultipleStartJs���
 �/���"�"�$�����t�W�g�>��	��������+�+�/�/�1�"�1�5��g��G�	�
�
��	��������+�+�/�/�1�"�1�5��g��Grc��t�}tj�}tjdd||��}|j�|j
|jj�dddd|f�|j�|j�|j
|jj�dddd|f�y)z�
        Like L{test_reactorParametrizationInClient}, but stop and restart the
        service and check that the given reactor is still used.
        r�r^r_Nrg)
rrr�rr�rNr(rhrcrPrds    r �0test_reactorParametrizationInClientMultipleStartz>InternetTests.test_reactorParametrizationInClientMultipleStartYs���
 �/���(�(�*�����{�D�'�7�K��	��������+�+�/�/�1�"�1�5��T�7�7S�T�	�
�
��	��������+�+�/�/�1�"�1�5��T�7�7S�Tr)rrrrr
rcrrr�IReactorUNIXr
r"r!r*r.r5rCrXr\rerirlrnrrr r�r�Rs����&F�*�(��#�J�#�#�G�T�2�2�;���	��*��#�J�#�#�G�T�2�2�;��$�	�$�.�#�J�#�#�G�T�2�2�;���	��$��(9�4
�H�U�
H�
Urr�c�$�eZdZd�Zd�Zd�Zd�Zy)�TimerBasicTestsc�8��tj�}tjd|jd��_�j
j
�|j�jd�|j�fd��|j�fd��|S)Nr^r%c�8���jj�Sr/�rWrP�r�r+s �r r�z/TimerBasicTests.testTimerRuns.<locals>.<lambda>o������� 2� 2� 4�rc�N���j�jj�Sr/)rLrWrMrus �r r�z/TimerBasicTests.testTimerRuns.<locals>.<lambda>ps���� 0� 0������ @�r)	r
r�rr0r�rWrNr�r()r+r�s` r �
testTimerRunszTimerBasicTests.testTimerRunsjsl����N�N����&�&�q�!�*�*�g�>���������	�
�
�d�&�&��0�	�
�
�4�5�	�
�
�@�A��rc�6�|jj�Sr/rtr{s r �tearDownzTimerBasicTests.tearDownss���v�v�!�!�#�#rc�f����tj�}tj���df|dfg��fd�}tjd|��_�jj��fd�}��fd�}�fd�}|j
|�|j
|�|j
|�|S)N�bar�fooc�N���j�\}}|j|�yr/)rcr�)r��arg�works  �r �triggerz1TimerBasicTests.testTimerRestart.<locals>.trigger|s����X�X�Z�F�A�s�
�J�J�s�Orr^c�\���j|d��jj�S)Nr}�r(rWrP��resultr+s �r �
onFirstResultz7TimerBasicTests.testTimerRestart.<locals>.onFirstResult�s&������V�U�+��6�6�%�%�'�'rc����j�jj��jj��Sr/)rLrWrMrN)r�d2r+s ��r �onFirstStopz5TimerBasicTests.testTimerRestart.<locals>.onFirstStop�s.������T�V�V�^�^�,��F�F���!��Irc�^���j|d��jj�y)Nr|r�r�s �r �onSecondResultz8TimerBasicTests.testTimerRestart.<locals>.onSecondResult�s#������V�U�+��F�F��� r)r
r�rr0rWrNr�)r+�d1r�r�r�r�r�r�s`     @@r �testTimerRestartz TimerBasicTests.testTimerRestartvs����
�^�^�
��
�^�^�
���U��b�%�[�)��	��&�&�q�'�2���������	(�	�
	!�	���}�%�
���{�#�
���~�&��	rc����g��fd�}tj�}tjd|dd|��_�jj�|j
�jdgdz�|j
�fd��|S)Nc�h���j|�t��|k(r|j��yyr/)r��lenr�)�data�numberr�r�s   �r r�z/TimerBasicTests.testTimerLoops.<locals>.trigger�s*���
�H�H�T�N��1�v����
�
�1�
� rg{�G�z�?r%�
c�8���jj�Sr/rtrus �r r�z0TimerBasicTests.testTimerLoops.<locals>.<lambda>�rvr)r
r�rr0rWrNr�r()r+r�r�r�s`  @r �testTimerLoopszTimerBasicTests.testTimerLoops�sq�����	�

�N�N����&�&�t�W�g�r�1�E���������	�
�
�d�&�&��	�B��7�	�
�
�4�5��rN)rrrrxrzr�r�rrr rqrqis���$��>
rrqc��eZdZdZd�Zy)�FakeReactorz6
    A fake reactor with a hooked install method.
    c�X�tjj|g|��i|��||_y)zv
        @param install: any callable that will be used as install method.
        @type install: C{callable}
        N)r�Reactorr��install)r+r�r�kwargss    r r�zFakeReactor.__init__�s)��
	���!�!�$�8��8��8���rN)rrr�__doc__r�rrr r�r��s���rr�c�`�eZdZdZd�Zd�Zdd�Zd�Zd�Zd�Z	d	�Z
d
�Zd�Zd�Z
d
�Zd�Zd�Zy)�PluggableReactorTestsz:
    Tests for the reactor discovery/inspection APIs.
    c�t�g|_g|_tj|_|j
t_y)aI
        Override the L{reactors.getPlugins} function, normally bound to
        L{twisted.plugin.getPlugins}, in order to control which
        L{IReactorInstaller} plugins are seen as available.

        C{self.pluginResults} can be customized and will be used as the
        result of calls to C{reactors.getPlugins}.
        N)�pluginCalls�
pluginResultsr�
getPlugins�originalFunction�_getPluginsr{s r �setUpzPluggableReactorTests.setUp�s0�������� (� 3� 3���"�.�.��rc�.�|jt_y)z>
        Restore the original L{reactors.getPlugins}.
        N)r�rr�r{s r rzzPluggableReactorTests.tearDown�s��#�3�3��rNc�f�|jj||f�t|j�S)zy
        Stand-in for the real getPlugins method which records its arguments
        and returns a fixed result.
        )r�r�r2r�)r+�	interface�packages   r r�z!PluggableReactorTests._getPlugins�s.��
	
������G� 4�5��D�&�&�'�'rc�d�d}tdz}d}tj|||�g|_tj�}|j|jtjdfg�|D]/}|j|k(s�|j|j|�y|jd�y)zP
        Test that reactor plugins are returned from L{getReactorTypes}
        �fakereactortestz.fakereactor�descriptionNz6Reactor plugin not present in getReactorTypes() result)rrr�r��getReactorTypesr(r��IReactorInstaller�	shortNamer��fail)r+r)r�r��reactorTypes�rs      r �test_getPluginReactorTypesz0PluggableReactorTests.test_getPluginReactorTypes�s���!���^�+��#��&�.�.�t�W�k�J�K����/�/�1������)�)�X�-G�-G��,N�+O�P��	P�A��{�{�d�"�� � �����<��	P�

�I�I�N�Orc����g��fd�}t|dtd�}d|i}|j|�tjddd�}|j�|j
�dg�y)zy
        Test that L{reactors.Reactor.install} loads the correct module and
        calls its install attribute.
        c�(���jd�yr��r���	installeds�r r�z?PluggableReactorTests.test_reactorInstallation.<locals>.install��������T�"rr��	described�fakereactorTN)r�r�replaceSysModulesrr�r�r()r+r��fakeReactor�modules�	installerr�s     @r �test_reactorInstallationz.PluggableReactorTests.test_reactorInstallation�sm���
�	�	#�"�'�+<�h��T��$�k�2�����w�'��$�$�]�4E�{�S�	���������T�F�+rc���g��fd�}d}t}d}t||||�g|_tj|�|j�dg�y)zu
        Test that the L{reactors.installReactor} function correctly installs
        the specified reactor.
        c�(���jd�yr�r�r�s�r r�z:PluggableReactorTests.test_installReactor.<locals>.install�r�rr�r�TN�rr�r�r�installReactorr()r+r�r)r�r�r�s     @r �test_installReactorz)PluggableReactorTests.test_installReactor�sV���
�	�	#�!����#��)�'�4��+�N�O�������%�����T�F�+rc����t����fd�}d}t}d}t||||�g�_t	j
|�}�j
|��y)zt
        Test that the L{reactors.installReactor} function correctly returns
        the installed reactor.
        c�8��ddlm}�j|d��y)Nr)rr
)�twistedr�patch)rr
r+s ��r r�zHPluggableReactorTests.test_installReactorReturnsReactor.<locals>.installs���(��J�J�x��G�4rr�r�N)rarr�r�rr�r�)r+r�r)r�r�r�r
s`     @r �!test_installReactorReturnsReactorz7PluggableReactorTests.test_installReactorReturnsReactor	sV���
�(��	5�
!����#��)�'�4��+�N�O����+�+�D�1�	��
�
�i��)rc����g��fd�}d}t}d}t||||�}td�d||�}||g|_tj|�|j�dg�y)z�
        Test that the L{reactors.installReactor} function correctly installs
        the specified reactor when there are multiple reactor plugins.
        c�(���jd�yr�r�r�s�r r�zIPluggableReactorTests.test_installReactorMultiplePlugins.<locals>.install#r�rr�r�c��yr/rrrr r�zJPluggableReactorTests.test_installReactorMultiplePlugins.<locals>.<lambda>*��r�otherreactorTNr�)r+r�r)r�r�r��otherReactorr�s       @r �"test_installReactorMultiplePluginsz8PluggableReactorTests.test_installReactorMultiplePluginssm���
�	�	#�!����#��!�'�4��+�F��"�<���+�V��*�K�8�������%�����T�F�+rc�p�g|_|jtjtjd�y)z�
        Test that L{reactors.installReactor} raises L{reactors.NoSuchReactor}
        when asked to install a reactor which it cannot find.
        �somereactorN)r�rBr�
NoSuchReactorr�r{s r �test_installNonExistentReactorz4PluggableReactorTests.test_installNonExistentReactor/s-��
 �������"�"�H�$;�$;�]�	
rc��d�}d}t}d}t||||�g|_|jtt
j|�y)z�
        Test that L{reactors.installReactor} raises an exception when asked to
        install a reactor which doesn't work in this environment.
        c��td��)N�Missing foo bar��ImportErrorrrr r�zFPluggableReactorTests.test_installNotAvailableReactor.<locals>.install?s���/�0�0rr�r�N)rr�r�rBr�rr�)r+r�r)r�r�s     r �test_installNotAvailableReactorz5PluggableReactorTests.test_installNotAvailableReactor9sF��	1�!����#��)�'�4��+�N�O������+�x�'>�'>��Erc�r����g�d�d�G��fd�dtjtj�}��fd�}t	|dt
d�g|_|�}|jgd��|j�d	��|j�j��d
�|j|dd�y)
zx
        Test that the reactor selected is installed as soon as possible, ie
        when the option is parsed.
        zreactor installedzsubcommands loadedc�$��eZdZe��fd��Zy)�QPluggableReactorTests.test_reactorSelectionMixin.<locals>.ReactorSelectionOptionsc�<����j��dd�fd�dfgS)N�
subcommandc����Sr/rr{s�r r�zoPluggableReactorTests.test_reactorSelectionMixin.<locals>.ReactorSelectionOptions.subCommands.<locals>.<lambda>Us���T�rztest subcommandr�)r+�SUBCOMMAND_EVENT�executeds`��r �subCommandsz]PluggableReactorTests.test_reactorSelectionMixin.<locals>.ReactorSelectionOptions.subCommandsRs#������ 0�1�%�t�\�;L�M�N�NrN)rrr�propertyr�)r�r�s��r �ReactorSelectionOptionsr�Qs���
�
O��
Orr�c�(���j��yr/r�)�
INSTALL_EVENTr�s��r r�zAPluggableReactorTests.test_reactorSelectionMixin.<locals>.installWs����O�O�M�*rr�r��z	--reactorr�r�rr^r
N)
r�Optionsr�ReactorSelectionMixinr�rr��parseOptionsr(�count)r+r�r��optionsr�r�r�s    @@@r �test_reactorSelectionMixinz0PluggableReactorTests.test_reactorSelectionMixinHs����
��+�
�/��	O�e�m�m�S�5N�5N�	O�	+�
��!2�H�k�J�
���*�+�����K�L�����!��m�4�������
�6��:������+�->�?rc�d�Gd�dtjtj�}g|_|�}t�|_|jtj|jgd��}|jd|jd�|jd|jd�y)z�
        Test that the usage mixin exits when trying to use a non existent
        reactor (the name not matching to any reactor), giving an error
        message.
        c��eZdZy)�\PluggableReactorTests.test_reactorSelectionMixinNonExistent.<locals>.ReactorSelectionOptionsN�rrrrrr r�r�k���rr�r�r�r�
help-reactorsN)rr�rr�r�r�
messageOutputrB�
UsageErrorr��assertInr)r+r�r��es    r �%test_reactorSelectionMixinNonExistentz;PluggableReactorTests.test_reactorSelectionMixinNonExistentds���	�e�m�m�S�5N�5N�	� ���)�+�� (�
���������� � �:�
��
	
�
�
�'������3��
�
�o�q�v�v�a�y�1rc���Gd�dtjtj�}d��fd�}d}t}d}t||||�g|_|�}t�|_|jtj|jgd��}|j�|jd�|jd	|jd�y
)z�
        Test that the usage mixin exits when trying to use a reactor not
        available (the reactor raises an error at installation), giving an
        error message.
        c��eZdZy)�]PluggableReactorTests.test_reactorSelectionMixinNotAvailable.<locals>.ReactorSelectionOptionsNr�rrr r�r��r�rr�r�c���t���r/r�)�messages�r r�zMPluggableReactorTests.test_reactorSelectionMixinNotAvailable.<locals>.install�s����g�&�&rr�r�r�rr�N)rr�rr�rr�r�rr�rBr�r�r�r)	r+r�r�r)r�r�r�r�r�s	        @r �&test_reactorSelectionMixinNotAvailablez<PluggableReactorTests.test_reactorSelectionMixinNotAvailablezs����	�e�m�m�S�5N�5N�	�$��	'�!����#��)�'�4��+�N�O���)�+�� (�
���������� � �:�
��
	
�
�
�g�q�v�v�a�y�)��
�
�o�q�v�v�a�y�1rr/)rrrr�r�rzr�r�r�r�r�r�r�r�r�r�rrrr r�r��sK���/�4�(�P�&,�",�"*�&,�&
�
F�@�82�,2rr�c��eZdZdZd�Zeed�d��Zeed�d��Zee	dk7d�d	��Z
ee	dk(d
�d��Zd�Zy
)�HelpReactorsTestsz6
    --help-reactors lists the available reactors
    c��tj�|_t�|j_|jt|jj�|jjj�|_	y)z3
        Get the text from --help-reactors
        N)
rr�r�rr�rB�
SystemExit�opt_help_reactors�getvaluer�r{s r r�zHelpReactorsTests.setUp�sV���0�0�2���%-�Z����"����*�d�l�l�&D�&D�E��|�|�1�1�:�:�<��rz$Not applicable, asyncio is availablec���|jtjj|j�|jdtjj
z|j�y)zX
        --help-reactors should NOT display the asyncio reactor on Python < 3.4
        �!N)r�r�asyncior�r�r�r{s r �test_lacksAsyncIOz#HelpReactorsTests.test_lacksAsyncIO�sG��
	
�
�
�&�.�.�:�:�D�L�L�I��
�
�c�,�4�4�>�>�>����Mrzasyncio library not availablec���|jtjj|j�|jdtjjz|j�y)zU
        --help-reactors should display the asyncio reactor on Python >= 3.4
        rN)r�rr	r�r��assertNotInr�r{s r �test_hasAsyncIOz!HelpReactorsTests.test_hasAsyncIO�sI��
	
�
�
�&�.�.�:�:�D�L�L�I�����/�7�7�A�A�A�4�<�<�Pr�win32zTest only applicable on Windowsc���|jtjj|j�|jdtjjz|j�y)zL
        --help-reactors should display the iocp reactor on Windows
        rN)r�r�iocpr�r�rr�r{s r �test_iocpWin32z HelpReactorsTests.test_iocpWin32�sI��
	
�
�
�&�+�+�7�7����F�����/�4�4�>�>�>����MrzTest not applicable on Windowsc���|jtjj|j�|jdtjj
z|j�y)zP
        --help-reactors should NOT display the iocp reactor on Windows
        rN)r�rrr�r�r�r{s r �test_iocpNotWin32z#HelpReactorsTests.test_iocpNotWin32�sG��
	
�
�
�&�+�+�7�7����F��
�
�c�,�1�1�;�;�;�T�\�\�Jrc��d�}tj�}||_t�|_|jt|j�|jj�}|jd|�y)z>
        --help-reactors with only supported reactors
        c3�0K�tj��y�wr/)r�defaultrrr r�zEHelpReactorsTests.test_onlySupportedReactors.<locals>.getReactorTypes�s����"�*�*�*�s�zreactors not availableN)
rr��_getReactorTypesrr�rBrrrr)r+r�r�r�s    r �test_onlySupportedReactorsz,HelpReactorsTests.test_onlySupportedReactors�sd��
	+��+�+�-��#2�� � (�
������*�g�&?�&?�@��'�'�0�0�2�����1�7�;rN)
rrrr�r�rr	r
r
rrrrrrr rr�s����=��G�;�<�N�=�N���K�8�9�Q�:�Q��L�G�#�%F�G�N�H�N��L�G�#�%E�F�K�G�K�
<rrc�"�eZdZdZd�Zd�Zd�Zy)�BackoffPolicyTestsz@
    Tests of L{twisted.application.internet.backoffPolicy}
    c��tdddd���}|j|d�d�|j|d�d	�|j|d
�d�|j|d�d
�|j|d�d
�y)zI
        Test that L{backoffPolicy()} calculates expected values
        ��?�N@��?c��yr]rrrr r�zCBackoffPolicyTests.test_calculates_correct_values.<locals>.<lambda>�r�r��jitterrr`r^g@r�g UM@��=�dN)r	�assertAlmostEqualr(�r+�pols  r �test_calculates_correct_valuesz1BackoffPolicyTests.test_calculates_correct_values�sx���C��s�9�=�����s�1�v�q�)����s�1�v�s�+����s�2�w�
�6�����R��"�%�����S��2�&rc��tdddd���}|j|d�d�|j|d�d�y	)
z�
        L{backoffPolicy()} does not fail for large values of the attempt
        parameter. In previous versions, this test failed when attempt was
        larger than 1750.

        See https://twistedmatrix.com/trac/ticket/9476
        rrrc��yr]rrrr r�zLBackoffPolicyTests.test_does_not_overflow_on_high_attempts.<locals>.<lambda>�r�rr ��r#i@BN�r	r(r&s  r �'test_does_not_overflow_on_high_attemptsz:BackoffPolicyTests.test_does_not_overflow_on_high_attempts�s<���C��s�9�=������T��B�'�����W��r�*rc�T�tdddd���}|j|d�d�y)	z�
        Even with unusual parameters, any L{OverflowError} within
        L{backoffPolicy()} will be caught and L{maxDelay} will be returned
        instead
        rrg _�Bc��yr]rrrr r�zSBackoffPolicyTests.test_does_not_overflow_with_large_factor_value.<locals>.<lambda>�r�rr r+r#Nr,r&s  r �.test_does_not_overflow_with_large_factor_valuezABackoffPolicyTests.test_does_not_overflow_with_large_factor_value�s(���C��t�I�>������T��B�'rN)rrrr�r(r-r0rrr rr�s���	'�
+�(rr)Ar�re�osr��iorr	r��unittestr�twisted.applicationrrrr�twisted.application.internetr	�twisted.internetr
rrr
�twisted.internet.testingr�twisted.persistedr�twisted.pluginsr�twisted.protocolsrr�twisted.pythonr�twisted.python.runtimer�#twisted.python.test.modules_helpersr�twisted.trial.unittestrrrr"rRrg�curuid�getgid�curgidrirwr�r�r��LineReceiverr�r�r�rr�r�rqr�r�r�rrrrr �<module>rCs|����	�
�����@�@�6�A�A�2�!�,�)� �/�C�5���x#�8�x#�v�2�x��
�R�Y�Y�[�F�
�R�Y�Y�[�F���F�V�1�8�1�0	H�h�	H�%�x�%�>=�8�=�(,8�h�,8�^	3�%�
�
�	3�(�(����t�y�y��
TU�H�TU�n9�h�9�x�(�"�"��c2�/��c2�L;<��;<�|#(��#(��M���G��s�E:�:F�F

Zerion Mini Shell 1.0