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_udp.cpython-310.pyc
o

�b�a�@s<dZddlZddlmZddlmZmZmZmZm	Z	m
Z
ddlmZm
Z
mZddlmZddlmZGdd	�d	�ZGd
d�deej�ZGdd
�d
eej�ZGdd�de�ZGdd�de�ZGdd�dej�Zee�e	d�d�Gdd�de��Zee�e	d�d�Gdd�de��Zee�e	d�d�Gdd�de��Z dS)zG
Tests for implementations of L{IReactorUDP} and L{IReactorMulticast}.
�N)�skipIf)�defer�error�
interfaces�protocol�reactor�udp)�Deferred�
gatherResults�
maybeDeferred)�runtime)�TestCasec@s0eZdZdZdZdZdd�Zdd�Zdd�ZdS)	�MixinrNcCs
g|_dS�N)�packets��self�r�7/usr/lib/python3/dist-packages/twisted/test/test_udp.py�__init__�
zMixin.__init__cCs0d|_|jdur|jd}|_|�d�dSdS�N�)�started�startedDeferred�callback�r�drrr�
startProtocols

�zMixin.startProtocolcCs
d|_dSr)�stoppedrrrr�stopProtocol#rzMixin.stopProtocol)	�__name__�
__module__�__qualname__rrrrrr rrrrrsrc@seZdZdZdZdd�ZdS)�ServerNrcCs:|j�||f�|jdur|jd}|_|�d�dSdSr�r�append�packetReceivedr)r�data�addrrrrr�datagramReceived+s

�zServer.datagramReceived)r!r"r#r'�refusedr*rrrrr$'sr$c@s,eZdZdZdZdd�Zdd�Zdd�ZdS)	�ClientNrcCs6|j�|�|jdur|jd}|_|�d�dSdSrr%)rr(rrrrr*7s

�zClient.datagramReceivedcCs,|jdur|jd}|_|�|�||_dSr)r�errback�failure)rr.rrrr�connectionFailed=s


zClient.connectionFailedcC�2|jdur|jd}|_|�t�d��d|_dS�N�yupr�rr-r�ConnectionRefusedErrorr+rrrr�connectionRefusedC�

zClient.connectionRefused)r!r"r#r'r+r*r/r5rrrrr,2sr,c@�eZdZdd�ZdS)�
GoodClientcCr0r1r3rrrrr5Kr6zGoodClient.connectionRefusedN)r!r"r#r5rrrrr8J�r8c@seZdZdZdS)�BadClientErrorzf
    Raised by BadClient at the end of every datagramReceived call to try and
    screw stuff up.
    N)r!r"r#�__doc__rrrrr:Rsr:c@s$eZdZdZdZdd�Zdd�ZdS)�	BadClientz�
    A DatagramProtocol which always raises an exception from datagramReceived.
    Used to test error handling behavior in the reactor for that method.
    NcCs
||_dS)ze
        Set the Deferred which will be called back when datagramReceived is
        called.
        N)rrrrr�setDeferredas
zBadClient.setDeferredcCs*|jdur|jd}|_|�|�td��)NzApplication code is very buggy!)rrr:)r�bytesr)rrrrr*hs

zBadClient.datagramReceived)r!r"r#r;rr=r*rrrrr<Ys
r<�!This reactor does not support UDPc@sjeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zee	j
�d�dkd
�dd��Zdd�Z
dd�Zdd�ZdS)�UDPTestscs<t�}t��}|_tjd|dd����fdd�}|�|�S)zu
        The C{type} of the host address of a listening L{DatagramProtocol}'s
        transport is C{"UDP"}.
        r�	127.0.0.1��	interfacecs���}��|jd����S)N�UDP)�getHost�assertEqual�type�
stopListening)�ignoredr)��prrr�	cbStartedzsz+UDPTests.test_oldAddress.<locals>.cbStarted�r$rr	rr�	listenUDP�addCallback)r�serverrrLrrJr�test_oldAddressqs

zUDPTests.test_oldAddresscsRt��t��}�_tjd�dd�����fdd�}��fdd�}|�|��|�S)z�
        The L{DatagramProtocol}'s C{startProtocol} and C{stopProtocol}
        methods are called when its transports starts and stops listening,
        respectively.
        rrArBcs$���jd����jd����S)Nrr)rFrrrH�rI��port1rrPrrrL�sz*UDPTests.test_startStop.<locals>.cbStartedcs���jd�dSr)rFrrR)rrPrr�	cbStopped�sz*UDPTests.test_startStop.<locals>.cbStoppedrM)rrrLrUrrSr�test_startStop�szUDPTests.test_startStopcsFt��t��}�_tjd�dd�}dd����fdd�}|��|�S)zr
        Re-listening with the same L{DatagramProtocol} re-invokes the
        C{startProtocol} callback.
        rrArBcSs|��Sr�rH)rI�portrrrrL��z'UDPTests.test_rebind.<locals>.cbStartedcs*t��}�_tjd�dd�}|��|�S�NrrArB)rr	rrrNrO)rIrrK�rLrPrrrU�sz'UDPTests.test_rebind.<locals>.cbStoppedrM)rrrKrUrr[r�test_rebind�szUDPTests.test_rebindcsXt��t��}�_tjd�dd�����fdd�}|�|��fdd�}|�|�|S)z�
        A L{CannotListenError} exception is raised when attempting to bind a
        second protocol instance to an already bound port
        rrArBcs>������j���t�}�jtjtj���j	|dd�dS)NrArB)
rFrE�	transportr$�assertRaisesr�CannotListenErrorrrNrX)rI�server2�rXrrPrrrL�s
�z*UDPTests.test_bindError.<locals>.cbStartedcs���SrrWrR�rXrr�
cbFinished�rYz+UDPTests.test_bindError.<locals>.cbFinishedrM)rrrLrcrrar�test_bindError�s

zUDPTests.test_bindErrorcs�t��t��}�_tjd�dd��t��t����_���fdd�}|�|�}��fdd�}|�|����fdd	�}|�|���fd
d�}|�|�|S)z�
        Datagrams can be sent with the transport's C{write} method and
        received via the C{datagramReceived} callback method.
        rrArBcstjd�dd��_�SrZ)rrN�port2rR)�client�
clientStartedrrr�cbServerStarted�sz2UDPTests.test_sendPackets.<locals>.cbServerStartedcs��j�d�j��j��j��}�j��}t��}�_�j�d|j|jf�ddd|j|jffg�����fdd��tj	�d�|gdd	�S)
NrA�hello)�a)�bN�ccs6�rt��}�_|����jj��d��|SdS�Nr)rr	r'rOr]�write�pop)rI�nextClientWrite)�cbClientSendrf�clientWritesrPrrrq�s
�zHUDPTests.test_sendPackets.<locals>.cbClientStarted.<locals>.cbClientSendT��fireOnOneErrback)
r]�connectrErXrr	r'rn�host�DeferredList)rI�cAddr�sAddr�
serverSend)rfrP)rqrrr�cbClientStarted�s


�z2UDPTests.test_sendPackets.<locals>.cbClientStartedcs`�j��}�j��}���jd|j|jffg�|j|jf}���jd|fd|fd|fg�dS)Nrirjrkrl)r]rErFrrvrX)rIrxry�
clientAddr�rfrrPrr�cbSendsFinished�s

�z2UDPTests.test_sendPackets.<locals>.cbSendsFinishedcs$tjt��j�t��jj�gdd�S�NTrs)rrwrrHrerR)rTrrrrc�s
��z-UDPTests.test_sendPackets.<locals>.cbFinished)r$rr	rrrNr8rO)r�
serverStartedrhrr{r~rcr)rfrgrTrrPr�test_sendPackets�s




	zUDPTests.test_sendPackets�INFRASTRUCTURE�AZUREPIPELINESz"Hangs on Pipelines due to firewallcs�t��t��}�_tjd�dd��t��t��}�_tjd�dd��tj||gdd�}���fdd�}|�|���fdd	�}|�|�|S)
z�
        A L{ConnectionRefusedError} exception is raised when a connection
        attempt is actively refused by the other end.

        Note: This test assumes no one is listening on port 80 UDP.
        rrArBTrscs^t��}�_�j�dd�td�D]}�j�d|f��j�d|fd�q��|tj	�S)NrA�P�
�%d)rAr�)
rr	rr]ru�rangern�
assertFailurerr4)rIr5�ir}rrrLsz2UDPTests.test_connectionRefused.<locals>.cbStartedcs"tjt��j�t��j�gdd�Sr)rrwrrHrR)rXrerrrc)s

��z3UDPTests.test_connectionRefused.<locals>.cbFinished)	r8rr	rrrNr$rwrO)rrgr�rrLrcr)rfrXrerrPr�test_connectionRefuseds


	zUDPTests.test_connectionRefusedcCsVt�}tjd|dd�}|�tj|jjdd�|j�dd�|�t|jjdd�|�	�S)a 
        A call to the transport's connect method fails with an
        L{InvalidAddressError} when a non-IP address is passed as the host
        value.

        A call to a transport's connect method fails with a L{RuntimeError}
        when the transport is already connected.
        rrArB�	localhostr�)
r8rrNr^r�InvalidAddressErrorr]ru�RuntimeErrorrH)rrfrXrrr�test_badConnect5s	�zUDPTests.test_badConnectcs�t����fdd�}��|�t��tjd�dd���fdd�}��|�����tt	d���g��������fd	d
�����S)zr
        When datagramReceived raises an exception it is logged but the port
        is not disconnected.
        cs*��t�}��t|�ddt|�f�dS)z�
            Flush the exceptions which the reactor should have logged and make
            sure they're actually there.
            �z'Incorrectly found %d errors, expected 2N)�flushLoggedErrorsr:rF�len)�ign�errsrrr�cbCompletedNs
�z8UDPTests.test_datagramReceivedError.<locals>.cbCompletedrrArBcst��j���fdd��S)z�
            Disconnect the port we started and pass on whatever was given to us
            in case it was a Failure.
            c��Srr�r���resultrr�<lambda>b�zHUDPTests.test_datagramReceivedError.<locals>.cbCleanup.<locals>.<lambda>)rrrH�addBothr�rbr�r�	cbCleanup]sz6UDPTests.test_datagramReceivedError.<locals>.cbCleanup�<cs��sz��d�Wn
ty���Ynw���jdd�d��d�f}t��}��|��j�	|�j
�jf�����fdd�}�fdd	�}|�||�|�
�j�t�d
|jt�d���dS)a6
            Send one packet to the listening BadClient.  Set up a 0.1 second
            timeout to do re-transmits in case the packet is dropped.  When two
            packets have been received by the BadClient, stop sending and let
            the finalDeferred's callbacks do some assertions.
            zNot enough packets receivedNzUDP Protocol lost its transportr�rcs<�����|�t��dkrt�d�jd�dS��dS)z�
                A packet arrived.  Cancel the timeout for it, record it, and
                maybe finish the test.
                r�rN)�cancelr&r�r�	callLaterr)�packet)�
finalDeferred�makeAttempt�succeededAttempts�timeoutCallrr�cbPacketReceived�s


zRUDPTests.test_datagramReceivedError.<locals>.makeAttempt.<locals>.cbPacketReceivedcs
��dS)a�
                The packet wasn't received quickly enough.  Try sending another
                one.  It doesn't matter if the packet for which this was the
                timeout eventually arrives: makeAttempt throws away the
                Deferred on which this function is the errback, so when
                datagramReceived callbacks, so it won't be on this Deferred, so
                it won't raise an AlreadyCalledError.
                Nr)�err)r�rr�ebPacketTimeout�s
	zQUDPTests.test_datagramReceivedError.<locals>.makeAttempt.<locals>.ebPacketTimeoutg�������?z&Timed out in testDatagramReceivedError)�fail�	Exceptionr-�failIfIdenticalr]rorr	r=rnrvrX�addCallbacks�
addErrbackrr�r�TimeoutError)r��packetDeferredr�r�)r)�attemptsrfr�r�rr�)r�rr�ss,��
�z8UDPTests.test_datagramReceivedError.<locals>.makeAttempt)
rr	rOr<rrNr�rE�listr�)rr�r�r)r)r�rfr�r�rXrr�r�test_datagramReceivedErrorGs



:z#UDPTests.test_datagramReceivedErrorcCsRGdd�d�}t�dt��}|�|_|�dd�|�|jg�}|�t|�d�dS)ai
        C{'<broadcast>'} is an alternative way to say C{'255.255.255.255'}
        ({socket.gethostbyname("<broadcast>")} returns C{'255.255.255.255'}),
        so because it becomes a valid IP address, no deprecation warning about
        passing hostnames to L{twisted.internet.udp.Port.write} needs to be
        emitted by C{write()} in this case.
        c@r7)z6UDPTests.test_NoWarningOnBroadcast.<locals>.fakeSocketcSsdSrr)r�foo�barrrr�sendto�sz=UDPTests.test_NoWarningOnBroadcast.<locals>.fakeSocket.sendtoN)r!r"r#r�rrrr�
fakeSocket�r9r�rstest)z<broadcast>i�N)	r�Portr$�socketrn�
flushWarnings�test_NoWarningOnBroadcastrFr�)rr�rK�warningsrrrr��s	z"UDPTests.test_NoWarningOnBroadcastN)r!r"r#rQrVr\rdr�r�os�environ�getr�r�r�r�rrrrr@osD�
)ir@c@s8eZdZdZe�ed�sdZdd�Zdd�Z	dd	�Z
dS)
�ReactorShutdownInteractionTestsz!Test reactor shutdown interactionNr?cCs t�|_tjd|jdd�|_dS)zStart a UDP portrrArBN)r$rPrrNrXrrrr�setUp�sz%ReactorShutdownInteractionTests.setUpcCs
|j��S)zStop the UDP port)rXrHrrrr�tearDown�s
z(ReactorShutdownInteractionTests.tearDowncsht���t��}�j_��fdd�}|�|��fdd�}��|��jj�dd�jj��jf��S)z0Test reactor shutdown while in a recvfrom() loopcs �jj��t�d�jd�dSrm)rPr]�connectionLostrr�rrR��finishedrrr�pktRece�szQReactorShutdownInteractionTests.testShutdownFromDatagramReceived.<locals>.pktRececs���dSr)r�rRrrr�flushErrors�szUReactorShutdownInteractionTests.testShutdownFromDatagramReceived.<locals>.flushErrorss@rA)	rr	rPr'rOr]rnrErX)r�prr�r�rr�r� testShutdownFromDatagramReceived�s

�z@ReactorShutdownInteractionTests.testShutdownFromDatagramReceived)r!r"r#r;r�IReactorUDPr�skipr�r�r�rrrrr��sr��'This reactor does not support multicastc@s�eZdZej�d�dkrej��rdZ	e
�ed�sdZ	dd�Z
dd	�Zd
d�Zdd
�Zdd�Zdd�Zeej��o>ej��d�dd��Zdd�Zeej��d�dd��ZdS)�MulticastTestsr�r�z Does not work on Azure PipelinesNr�cCsNt�|_t�|_t�d|j�|_t�d|j�|_|jj�	d|jj�
�j�dS)NrrA)r$rPr,rfr�listenMulticastrTrer]rurErXrrrrr�s
zMulticastTests.setUpcCstt|jj�t|jj�g�Sr)r
rrTrHrerrrrr�s


��zMulticastTests.tearDowncCsF|j|jfD]}|�|j��d�|j�d�|�|j��d�qdS)Nrr�)rfrPrFr]�getTTL�setTTL)r�orrr�testTTLs
�zMulticastTests.testTTLcsx���jj��d��jj����jj�d�}��fdd�}|�|���fdd�}|�|��fdd�}|�|�|S)	zv
        Test that after loopback mode has been set, multicast packets are
        delivered to their sender.
        r�225.0.0.250cs(t�}�j_�jj�dd�jf�|S)Nrir��r	rPr'r]rnrX�rIr�r)rrr�cbJoined*sz.MulticastTests.test_loopback.<locals>.cbJoinedcsf��t�jj�d��jj�d����jj��d��jj�dd�jf�t	�}t
�d|jd�|S)Nrrrir�)
rFr�rPrr]�setLoopbackMode�getLoopbackModernrXr	rr�rr�r�rr�cbPacket1sz.MulticastTests.test_loopback.<locals>.cbPacketcs��t�jj�d�dSr)rFr�rPrrRrrr�
cbNoPacket>sz0MulticastTests.test_loopback.<locals>.cbNoPacket)rFrPr]r�rE�	joinGrouprO)r�joinedr�r�r�rr�r�
test_loopback!s


zMulticastTests.test_loopbackcsj���jj��d����jj��d��jj�d�}�jj�d�}t||g�}�fdd�}|�|�|S)zK
        Test C{getOutgoingInterface} and C{setOutgoingInterface}.
        z0.0.0.0rAcs,���jj��d����jj��d�dS)NrA)rFrfr]�getOutgoingInterfacerPrRrrr�cbInterfacesPsz3MulticastTests.test_interface.<locals>.cbInterfaces)rFrfr]r�rP�setOutgoingInterfacer
rO)r�d1�d2r�r�rrr�test_interfaceEs
zMulticastTests.test_interfacecsT�jj�d�}�fdd�}|�|��fdd�}|�|��fdd�}|�|�|S)zE
        Test that multicast a group can be joined and left.
        r�c��jj�d�S�Nr�)rfr]�
leaveGrouprRrrr�clientJoined]�z3MulticastTests.test_joinLeave.<locals>.clientJoinedcr�r�)rPr]r�rRrrr�
clientLeftbr�z1MulticastTests.test_joinLeave.<locals>.clientLeftcr�r�)rPr]r�rRrrr�serverJoinedgr�z3MulticastTests.test_joinLeave.<locals>.serverJoined)rfr]r�rO)rrr�r�r�rrr�test_joinLeaveWs


zMulticastTests.test_joinLeavez2Windows' UDP multicast is not yet fully supported.cCs|�|jj�d�tj�S)z�
        Test that an attempt to join an address which is not a multicast
        address fails with L{error.MulticastJoinError}.
        rA)r�rfr]r�r�MulticastJoinErrorrrrr�test_joinFailureos
�zMulticastTests.test_joinFailurecsvt��t�d����jj����jj�d�}���fdd�}|�|��fdd�}|�|��fdd�}|�|�|S)	zn
        Test that a multicast group can be joined and messages sent to and
        received from it.
        rr�cs&t�}�j_�j�dd�jf�|S)N�hello worldr�r�r�)r)�crrrr��sz/MulticastTests.test_multicast.<locals>.cbJoinedcs���jjddd�dS�Nrr�)rFrPrrRrrrr��sz/MulticastTests.test_multicast.<locals>.cbPacketcs t�j�}|��fdd��|S)Ncr�rrr���passthroughrrr��r�z@MulticastTests.test_multicast.<locals>.cleanup.<locals>.<lambda>)rrHrO�r�r�)rKr�r�cleanup�s
z.MulticastTests.test_multicast.<locals>.cleanup)r$rr�rPr]rEr�rO)rr�r�r�r�r)r)r�rKrr�test_multicast}s


zMulticastTests.test_multicastzjon non-linux platforms it appears multiple processes can listen, but not multiple sockets in same process?cs�t��tjd�dd�����j�t��tj��dd��d�t�jj�����������g�}����fdd�}|�	|����fdd�}|�	|���fd	d
�}|�
|�|S)z�
        Test that multiple sockets can listen on the same multicast port and
        that they both receive multicast messages directed to that address.
        rT)�listenMultipler�cs6t�}�_t�}�_�j�d��f�t||g�S)Nr�)r	r'r]rnr
)rIr�r�)�firstClient�portno�secondClient�theGrouprrr��sz5MulticastTests.test_multiListen.<locals>.serverJoinedcs0���jddd����jddd�dSr�)rFrrR)r�r�rrr�
gotPackets�sz3MulticastTests.test_multiListen.<locals>.gotPacketscs.tt�j�t�j�g�}|��fdd��|S)Ncr�rrr�r�rrr��r�zBMulticastTests.test_multiListen.<locals>.cleanup.<locals>.<lambda>)r
rrHrOr�)�	firstPort�
secondPortr�rr��s��z0MulticastTests.test_multiListen.<locals>.cleanup)r$rr�rErXr
rPr]r�rOr�)rr�r�r�r�r)r�r�r�r�r�rr�r�test_multiListen�s&
��



zMulticastTests.test_multiListen)r!r"r#r�r�r�r�platform�isMacOSXr�r�IReactorMulticastrr�r�r�r�r�r�r�	isWindows�isVistar�r�r�rrrrr��s0�$�

 �r�)!r;r��unittestr�twisted.internetrrrrrr�twisted.internet.deferr	r
r�twisted.pythonr�twisted.trial.unittestr
r�DatagramProtocolr$�ConnectedDatagramProtocolr,r8r�r:r<r�r@r�rr�rrrr�<module>s0 W6�

Anon7 - 2022
AnonSec Team