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/words/test/__pycache__/test_xishutil.cpython-38.pyc
U


W[�$�@s�dZddlmZmZddlmZddlmZddlm	Z	ddl
mZddlm
Z
Gdd	�d	�ZGd
d�d�ZGdd
�d
ej�ZGdd�dej�ZdS)z+
Test cases for twisted.words.xish.utility
�)�absolute_import�division)�OrderedDict)�unittest)�utility)�Element)�EventDispatcherc@s eZdZdZdd�Zdd�ZdS)�CallbackTrackerz�
    Test helper for tracking callbacks.

    Increases a counter on each call to L{call} and stores the object
    passed in the call.
    cCsd|_d|_dS)Nr��called�obj��self�r�B/usr/lib/python3/dist-packages/twisted/words/test/test_xishutil.py�__init__szCallbackTracker.__init__cCs|jd|_||_dS)N�r
)rrrrr�callszCallbackTracker.callN)�__name__�
__module__�__qualname__�__doc__rrrrrrr	sr	c@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�OrderedCallbackTrackerz=
    Test helper for tracking callbacks and their order.
    cCs
g|_dS�N)�callListr
rrrr*szOrderedCallbackTracker.__init__cCs|j�|j�dSr)r�append�call1�r�objectrrrr.szOrderedCallbackTracker.call1cCs|j�|j�dSr)rr�call2rrrrr2szOrderedCallbackTracker.call2cCs|j�|j�dSr)rr�call3rrrrr 6szOrderedCallbackTracker.call3N)rrrrrrrr rrrrr%s
rc@speZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�ZdS)�EventDispatcherTestsz'
    Tests for L{EventDispatcher}.
    cCs<t�}t�}t�}t�}|�d|j�|�d|j�|�d|j�|�d|j�td�}|�d�td�}|�d�|�|�|�|jd	�|�|j	|�|�|jd
�|�|�|�|jd	�|�|jd�|�|j	|�|�|jd
�|�|d�|�|jd�|�|j	|�|�
d|j�|�|�|�|jd�dS)N�
/message/body�/message�	/presence�//event/testevent��ns�message�body�r'�presencer+�rr)rr	�addObserverrr�
addElement�dispatch�assertEqualrr�removeObserver)r�d�cb1�cb2Zcb3�msg�presrrr�	testStuff@s6




zEventDispatcherTests.testStuffcCsvt�}t�}t�}|�d|j�|�d|j�|�|d�|�|jd�|�|j|�|�|jd�|�|j|�dS)z�
        Test adding two observers for the same query.

        When the event is dispatched both of the observers need to be called.
        r%rN)rr	r-rr/r0rr)rr2r3r4rrr�test_addObserverTwiceesz*EventDispatcherTests.test_addObserverTwicecszt��td�}t����fdd�}��d|���|�|��jd���|�|��jd���|�|��jd�dS)	zG
        Test for registration of an observer during dispatch.
        r&cs��d�j�dS�Nr#)r-r��_��cbr2rr�	onMessage�szBEventDispatcherTests.test_addObserverInDispatch.<locals>.onMessager#rrr,N�rrr	�addOnetimeObserverr/r0r�rr5r>rr<r�test_addObserverInDispatchys


z/EventDispatcherTests.test_addObserverInDispatchcszt��td�}t����fdd�}��d|���|�|��jd���|�|��jd���|�|��jd�dS)zN
        Test for registration of a onetime observer during dispatch.
        r&cs��d�j�dSr9)r@r)r5r<rrr>�szIEventDispatcherTests.test_addOnetimeObserverInDispatch.<locals>.onMessager#rrNr?rArr<r�!test_addOnetimeObserverInDispatch�s


z6EventDispatcherTests.test_addOnetimeObserverInDispatchcCsVt�}td�}t�}|�d|j�|�|�|�|jd�|�|�|�|jd�dS)Nr&r#r)rrr	r@rr/r0r)rr2r5r=rrr�testOnetimeDispatch�s

z(EventDispatcherTests.testOnetimeDispatchcCsZt�}td�}td�}t�}|�d|j�|�|�}|�d|�|�|�}|�d|�dS)Nr&r*r$FT)rrr	r-rr/r0)rr2r5r6r=�resultrrr�testDispatcherResult�s

z)EventDispatcherTests.testDispatcherResultcCs�t�}t�}|�d|j�|�d|jd�|�d|jd�td�}|�d�|�|�|�	|j
|j|j|jgdtdd	�|j
D���dS)
Nr"r#���rr&r)zCalls out of order: %scSsg|]
}|j�qSr)r)�.0�crrr�
<listcomp>�szAEventDispatcherTests.testOrderedXPathDispatch.<locals>.<listcomp>)rrr-rr rrr.r/r0r�repr�rr2r=r5rrr�testOrderedXPathDispatch�s

��z-EventDispatcherTests.testOrderedXPathDispatchcCs^t�}t�}|�d|j�|�dd�|�d|j�|�d|j�|�dt|j	�
d���dS)zO
        Test observer clean-up after removeObserver for named events.
        �//event/testNrr)rr	r-rr/r0rr1�len�_eventObservers�pop�rr2r=rrr�test_cleanUpRemoveEventObserver�sz4EventDispatcherTests.test_cleanUpRemoveEventObservercCsdt�}t�}td�}|�d|j�|�|�|�d|j�|�d|j�|�dt	|j
�d���dS)zO
        Test observer clean-up after removeObserver for XPath events.
        �Nr(r#rrN)rr	rr-rr/r0rr1rO�_xpathObserversrQrLrrr�test_cleanUpRemoveXPathObserver�s
z4EventDispatcherTests.test_cleanUpRemoveXPathObservercCsPt�}t�}|�d|j�|�dd�|�d|j�|�dt|j�	d���dS)zD
        Test observer clean-up after onetime named events.
        rNNrr)
rr	r@rr/r0rrOrPrQrRrrr� test_cleanUpOnetimeEventObserver�sz5EventDispatcherTests.test_cleanUpOnetimeEventObservercCsVt�}t�}td�}|�d|j�|�|�|�d|j�|�dt|j	�
d���dS)zD
        Test observer clean-up after onetime XPath events.
        rTr#rrN)rr	rr@rr/r0rrOrUrQrLrrr� test_cleanUpOnetimeXPathObservers
z5EventDispatcherTests.test_cleanUpOnetimeXPathObservercs�Gdd�dtj�}Gdd�dt���fdd�}t�}t�}tj}zx|t_|�d|�|�d|j�z|�dd�Wn�k
r�|�d	�YnX|�	d
t
|�����|�	d
|j�W5|t_XdS)z�
        Test that exceptions in observers do not bubble up to dispatch.

        The exceptions raised in observers should be logged and other
        observers should be called as if nothing happened.
        c@seZdZdd�ZdS)zOEventDispatcherTests.test_observerRaisingException.<locals>.OrderedCallbackListcSst�|_dSr)rZ	callbacksr
rrrrszXEventDispatcherTests.test_observerRaisingException.<locals>.OrderedCallbackList.__init__N)rrrrrrrr�OrderedCallbackListsrYc@seZdZdS)zEEventDispatcherTests.test_observerRaisingException.<locals>.TestErrorN)rrrrrrr�	TestErrorsrZcs
���dSrrr:�rZrr�
raiseError!szFEventDispatcherTests.test_observerRaisingException.<locals>.raiseErrorrNNz2TestError raised. Should have been logged instead.r)
rZCallbackList�	Exceptionrr	r-rr/Zfailr0rOZflushLoggedErrorsr)rrYr\r2r=ZoriginalCallbackListrr[r�test_observerRaisingExceptions"z2EventDispatcherTests.test_observerRaisingExceptionN)rrrrr7r8rBrCrDrFrMrSrVrWrXr^rrrrr!;s%r!c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�XmlPipeTestsz:
    Tests for L{twisted.words.xish.utility.XmlPipe}.
    cCst��|_dSr)rZXmlPipe�piper
rrr�setUp?szXmlPipeTests.setUpcsH�fdd�}g�|jj�d|�td�}|jj�|�|�|g��dS)zO
        Send an element from the source and observe it from the sink.
        cs��|�dSr�r�r�rrrr=Gsz,XmlPipeTests.test_sendFromSource.<locals>.cb�/test[@xmlns="testns"]�ZtestnsZtestN)r`�sinkr-r�source�sendr0�rr=�elementrrdr�test_sendFromSourceCsz XmlPipeTests.test_sendFromSourcecsH�fdd�}g�|jj�d|�td�}|jj�|�|�|g��dS)zO
        Send an element from the sink and observe it from the source.
        cs��|�dSrrbrcrdrrr=Usz*XmlPipeTests.test_sendFromSink.<locals>.cbrerfN)r`rhr-rrgrir0rjrrdr�test_sendFromSinkQszXmlPipeTests.test_sendFromSinkN)rrrrrarlrmrrrrr_:sr_N)rZ
__future__rr�collectionsrZ
twisted.trialrZtwisted.words.xishrZtwisted.words.xish.domishrZtwisted.words.xish.utilityrr	rZTestCaser!r_rrrr�<module>s