HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //usr/lib/python3/dist-packages/twisted/internet/test/__pycache__/test_base.cpython-38.pyc
U

�q�[94�@srdZddlZzddlmZWn ek
r<ddlmZYnXddlmZddlmZddl	m
Z
mZmZddl
mZddlmZdd	lmZdd
lmZmZmZddlmZddlmZmZee
e�Gd
d�de��ZGdd�de�Zdd�ZGdd�de�Z Gdd�de e�Z!Gdd�de e�Z"Gdd�de�Z#Gdd�de�Z$zddl%Z%Wnek
�rlde$_&YnXdS)z%
Tests for L{twisted.internet.base}.
�N)�Queue)�implementer)�
ThreadPool)�IReactorTime�IReactorThreads�IResolverSimple)�DNSLookupError)�FirstOneWins)�Deferred)�ThreadedResolver�DelayedCall�ReactorBase)�Clock)�TestCase�SkipTestc@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�FakeReactorzl
    A fake reactor implementation which just supports enough reactor APIs for
    L{ThreadedResolver}.
    cs>t��_�jj�_t��_�j���fdd��_t��_dS)Ncs�jS�N)�_threadpool���selfr�A/usr/lib/python3/dist-packages/twisted/internet/test/test_base.py�<lambda>(�z&FakeReactor.__init__.<locals>.<lambda>)	r�_clockZ	callLaterrr�startZ
getThreadPoolr�_threadCallsrrrr�__init__"s

zFakeReactor.__init__cOs|j�|||f�dSr)r�put�r�f�args�kwargsrrr�callFromThread-szFakeReactor.callFromThreadcCs|j��\}}}|||�dSr)r�getrrrr�_runThreadCalls1szFakeReactor._runThreadCallscCs|j��dSr)r�stoprrrr�_stop6szFakeReactor._stopN)�__name__�
__module__�__qualname__�__doc__rr#r%r'rrrrrs
rc@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�ThreadedResolverTestsz(
    Tests for L{ThreadedResolver}.
    cs�d�d}d}t�}|�|j�g�g}��fdd�}|�td|�t|�}|�||f�}|�|j�|�	�|�
�|g�|�
|�g�|j�|d�|�
|jj
g�dS)	z�
        L{ThreadedResolver.getHostByName} returns a L{Deferred} which fires
        with the value returned by the call to L{socket.gethostbyname} in the
        threadpool of the reactor passed to L{ThreadedResolver.__init__}.
        z	10.0.0.17zfoo.bar.example.com�cs��|��Sr)�append��name�ZipZlookedUprr�fakeGetHostByNameNs
z=ThreadedResolverTests.test_success.<locals>.fakeGetHostByName�
gethostbyname�N)r�
addCleanupr'�patch�socketr�
getHostByName�addCallbackr.r%�assertEqualr�advance�calls)rr0�timeout�reactorZ
resolvedTor2�resolver�drr1r�test_success?s"z"ThreadedResolverTests.test_successcCs�d}t�}|�|j�dd�}|�td|�g}t|�}|�d|f�}|�|t�|�	|j
�|��|�t
|�d�|j�|d�|�|jjg�dS)z�
        L{ThreadedResolver.getHostByName} returns a L{Deferred} which fires a
        L{Failure} if the call to L{socket.gethostbyname} raises an exception.
        r-cSstd��dS)NzENOBUFS (this is a funny joke))�IOErrorr/rrrr2lsz=ThreadedResolverTests.test_failure.<locals>.fakeGetHostByNamer3�	some.namer4N)rr5r'r6r7rr8�
assertFailurerr9r.r%r:�lenrr;r<�rr=r>r2Z
failedWithr?r@rrr�test_failurebsz"ThreadedResolverTests.test_failurecs�d}t�}|�|j�t���fdd�}|�td|�g}t|�}|�d|f�}|�|t	�|�
|j�|j�
|d�|�|g�|j�
d�|�t|�d���td��dS)	z�
        If L{socket.gethostbyname} does not complete before the specified
        timeout elapsed, the L{Deferred} returned by
        L{ThreadedResolver.getHostByName} fails with L{DNSLookupError}.
        �
cs����dSr)r$r/��resultrrr2�sz=ThreadedResolverTests.test_timeout.<locals>.fakeGetHostByNamer3rCr4zThe I/O was errorfulN)rr5r'rr6r7rr8rDrr9r.rr;r:rErrBrFrrIr�test_timeout�s z"ThreadedResolverTests.test_timeoutcsg�tt�G�fdd�dt��}Gdd�dt�}|�}|�}|�|�tt��}|j�|d�|j�|d�|j�|d�|j�|d�|j�|d�|�	t
��d	�|�	ttt
���tgd	�|�	d�d
�|�	d�d�|�	d�d
�|�	d�d�|�	d�d�dS)zm
        L{ThreadedResolver.getHostByName} is passed L{str}, encoded using IDNA
        if required.
        cseZdZd�fdd�	ZdS)zAThreadedResolverTests.test_resolverGivenStr.<locals>.FakeResolverrcs��|�t�Sr)r.r
)rr0Ztimeouts�r<rrr8�s
zOThreadedResolverTests.test_resolverGivenStr.<locals>.FakeResolver.getHostByNameN)r)r(r)r*r8rrLrr�FakeResolver�srMc@seZdZdd�ZdS)zFThreadedResolverTests.test_resolverGivenStr.<locals>.JustEnoughReactorcSsdSrrrrrr�installWaker�szSThreadedResolverTests.test_resolverGivenStr.<locals>.JustEnoughReactor.installWakerN)r(r)r*rNrrrr�JustEnoughReactor�srOzexample.exampleuvääntynyt.exampleuрф.examplezxn----7sbb4ac0ad0be6cf.xn--p1ai�rr4zxn--vntynyt-5waa.example�zxn--p1ai.example��N)rr�objectr
ZinstallResolverr	r
ZnameResolverZresolveHostNamer:rE�list�map�type�str)rrMrOZfaker>ZrecrrLr�test_resolverGivenStr�sF

�����z+ThreadedResolverTests.test_resolverGivenStrN)r(r)r*r+rArGrKrYrrrrr,;s
#!r,cCsdS)z8
    Function used by L{DelayedCallTests.test_str}.
    Nrrrrr�nothing�srZc@s`eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dS)�DelayedCallMixin�
    L{DelayedCall}
    cCs dd�}t|dd�di||d�S)z�
        Get a L{DelayedCall} instance at a given C{time}.

        @param time: The absolute time at which the returned L{DelayedCall}
            will be scheduled.
        cSsdSrr)�callrrr�noop�sz0DelayedCallMixin._getDelayedCallAt.<locals>.noopcSsdSrrrrrrr�rz4DelayedCallMixin._getDelayedCallAt.<locals>.<lambda>rN)r)r�timer^rrr�_getDelayedCallAt�sz"DelayedCallMixin._getDelayedCallAtcCs|�d�|_|�d�|_dS)zb
        Create two L{DelayedCall} instanced scheduled to run at different
        times.
        rr4N)r`�zero�onerrrr�setUp�szDelayedCallMixin.setUpc	Cs:tdtdddidddd��}|�t|�dt|�f�dS)	��
        The string representation of a L{DelayedCall} instance, as returned by
        L{str}, includes the unsigned id of the instance, as well as its state,
        the function to be called, and the function arguments.
        ��rR�ArPNcSsdS�Ng�?rrrrrr�rz+DelayedCallMixin.test_str.<locals>.<lambda>z?<DelayedCall 0x%x [10.5s] called=0 cancelled=0 nothing(3, A=5)>)rrZr:rX�id�r�dcrrr�test_str�s��zDelayedCallMixin.test_strc	Cs4tdtdddidddd��}|�t|�t|��dS)z�
        The string representation of a L{DelayedCall} instance, as returned by
        {repr}, is identical to that returned by L{str}.
        �
)�rg�	NcSsdS)Ng�������?rrrrrr�rz,DelayedCallMixin.test_repr.<locals>.<lambda>)rrZr:rX�reprrjrrr�	test_repr�szDelayedCallMixin.test_reprcCsJ|j|j}}|�||k�|�||k�|�||k�|�||k�dS)z�
        For two instances of L{DelayedCall} C{a} and C{b}, C{a < b} is true
        if and only if C{a} is scheduled to run before C{b}.
        N�rarb�
assertTrue�assertFalse�rrarbrrr�test_lts
zDelayedCallMixin.test_ltcCsJ|j|j}}|�||k�|�||k�|�||k�|�||k�dS)z�
        For two instances of L{DelayedCall} C{a} and C{b}, C{a <= b} is true
        if and only if C{a} is scheduled to run before C{b} or at the same
        time as C{b}.
        Nrrrurrr�test_les
zDelayedCallMixin.test_lecCsJ|j|j}}|�||k�|�||k�|�||k�|�||k�dS)z�
        For two instances of L{DelayedCall} C{a} and C{b}, C{a > b} is true
        if and only if C{a} is scheduled to run after C{b}.
        Nrrrurrr�test_gts
zDelayedCallMixin.test_gtcCsJ|j|j}}|�||k�|�||k�|�||k�|�||k�dS)z�
        For two instances of L{DelayedCall} C{a} and C{b}, C{a > b} is true
        if and only if C{a} is scheduled to run after C{b} or at the same
        time as C{b}.
        Nrrrurrr�test_ge's
zDelayedCallMixin.test_gecCs:|�|j|jk�|�|j|jk�|�|j|jk�dS)zD
        A L{DelayedCall} instance is only equal to itself.
        N)rtrarbrsrrrr�test_eq4szDelayedCallMixin.test_eqcCs:|�|j|jk�|�|j|jk�|�|j|jk�dS)zM
        A L{DelayedCall} instance is not equal to any other object.
        N)rsrarbrtrrrr�test_ne?szDelayedCallMixin.test_neN)r(r)r*r+r`rcrlrqrvrwrxryrzr{rrrrr[�s		

r[c@s eZdZdZdd�Zdd�ZdS)�DelayedCallNoDebugTestsr\cCs|�tdd�t�|�dS)z!
        Turn debug off.
        �debugFN�r6rr[rcrrrrrcOszDelayedCallNoDebugTests.setUpc	Cs>tdtdddidddd��}d�t|��}|�t|�|�dS)	rdrerfrgrPNcSsdSrhrrrrrr]rz2DelayedCallNoDebugTests.test_str.<locals>.<lambda>zA<DelayedCall 0x{:x} [10.5s] called=0 cancelled=0 nothing(3, A=5)>)rrZ�formatrir:rX)rrkZexpectedrrrrlWs��z DelayedCallNoDebugTests.test_strN�r(r)r*r+rcrlrrrrr|Ksr|c@s eZdZdZdd�Zdd�ZdS)�DelayedCallDebugTestsr\cCs|�tdd�t�|�dS)z 
        Turn debug on.
        r}TNr~rrrrrciszDelayedCallDebugTests.setUpc	Cs>tdtdddidddd��}d�t|��}|�t|�|�dS)	rdrerfrgrPNcSsdSrhrrrrrrwrz0DelayedCallDebugTests.test_str.<locals>.<lambda>z\<DelayedCall 0x{:x} \[10.5s\] called=0 cancelled=0 nothing\(3, A=5\)

traceback at creation:)rrZrriZassertRegexrX)rrkZexpectedRegexprrrrlqs���zDelayedCallDebugTests.test_strNr�rrrrr�esr�c@seZdZdZdd�ZdS)�TestSpySignalCapturingReactorza
    Subclass of ReactorBase to capture signals delivered to the
    reactor for inspection.
    cCsdS)z*
        Required method, unused.
        NrrrrrrN�sz*TestSpySignalCapturingReactor.installWakerN)r(r)r*r+rNrrrrr��sr�c@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�ReactorBaseSignalTestszE
    Tests to exercise ReactorBase's signal exit reporting path.
    cCst�}|�d|j�dS)zI
        The default value of the _exitSignal attribute is None.
        N)r�ZassertIs�_exitSignal�rr>rrr�test_exitSignalDefaultsToNone�sz4ReactorBaseSignalTests.test_exitSignalDefaultsToNonecCs(t�}|�tjd�|�tj|j�dS)zn
        ReactorBase's SIGINT handler saves the value of SIGINT to the
        _exitSignal attribute.
        N)r�ZsigInt�signal�SIGINT�assertEqualsr�r�rrr�test_captureSIGINT�sz)ReactorBaseSignalTests.test_captureSIGINTcCs(t�}|�tjd�|�tj|j�dS)zp
        ReactorBase's SIGTERM handler saves the value of SIGTERM to the
        _exitSignal attribute.
        N)r�ZsigTermr��SIGTERMr�r�r�rrr�test_captureSIGTERM�sz*ReactorBaseSignalTests.test_captureSIGTERMcCs:ttd�std��t�}|�tjd�|�tj|j�dS)zr
        ReactorBase's SIGBREAK handler saves the value of SIGBREAK to the
        _exitSignal attribute.
        �SIGBREAKz$signal module does not have SIGBREAKN)�hasattrr�rr�ZsigBreakr�r�r�r�rrr�test_captureSIGBREAK�s

z+ReactorBaseSignalTests.test_captureSIGBREAKN)r(r)r*r+r�r�r�r�rrrrr��s


r�zsignal module not available)'r+r7r�ImportErrorZqueueZzope.interfacerZtwisted.python.threadpoolrZtwisted.internet.interfacesrrrZtwisted.internet.errorrZtwisted.internet._resolverr	Ztwisted.internet.deferr
Ztwisted.internet.baserrr
Ztwisted.internet.taskrZtwisted.trial.unittestrrrTrr,rZr[r|r�r�r�r��skiprrrr�<module>s8y0