Your IP : 216.73.216.213


Current Path : /opt/alt/python37/lib64/python3.7/site-packages/twisted/test/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib64/python3.7/site-packages/twisted/test/__pycache__/test_unix.cpython-37.pyc

B

;��]5;�@s*dZddlmZmZddlZddlZddlZddlZddlm	Z	m
Z
mZmZm
Z
ddlmZmZddlmZddlmZmZddlmZdd	lmZdd
lmZmZGdd�dej�ZGd
d�dej�ZGdd�dej �Z!Gdd�dej"�Z#Gdd�dej�Z$e	�%e
d��sde_&e	�'e
d��s&de$_&dS)zK
Tests for implementations of L{IReactorUNIX} and L{IReactorUNIXDatagram}.
�)�division�absolute_importN)�
interfaces�reactor�protocol�error�address)�defer�utils)�lockfile)�_PY3�
networkString)�FilePath)�unittest)�MyServerFactory�MyClientFactoryc@seZdZdd�Zdd�ZdS)�FailedConnectionClientFactorycCs
||_dS)N)�onFail)�selfr�r�I/opt/alt/python37/lib64/python3.7/site-packages/twisted/test/test_unix.py�__init__sz&FailedConnectionClientFactory.__init__cCs|j�|�dS)N)rZerrback)rZ	connector�reasonrrr�clientConnectionFailedsz4FailedConnectionClientFactory.clientConnectionFailedN)�__name__�
__module__�__qualname__rrrrrrrsrc@sjeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Ze
r^de_dd�ZdS)�UnixSocketTestsz
    Test unix sockets.
    cs����}����t��t��}�_t�|��}��|j�t	�	t	j
t	j�}��|j�|�
��|�|����fdd�}|�|�|S)z�
        The address passed to the server factory's C{buildProtocol} method and
        the address returned by the connected protocol's transport's C{getPeer}
        method match the address the client socket is bound to.
        cs0t���}���j|g���|j��|�dS)N)r�UNIXAddress�assertEqual�
peerAddresses�	transportZgetPeer)�protoZexpected)�peernamer�
serverFactoryrr�
cbConnMade6s
z1UnixSocketTests.test_peerBind.<locals>.cbConnMade)�mktemprr	�Deferred�protocolConnectionMader�
listenUNIX�
addCleanup�
stopListening�socket�AF_UNIX�SOCK_STREAM�close�bind�connect�addCallback)r�filenameZconnMade�unixPortZ
unixSocketr%r)r#rr$r�
test_peerBind&s


zUnixSocketTests.test_peerBindcs�����t�}t��}||_t��|�}��|j�t	��t��}|�_t�
���t�||g�}���fdd�}|�|�|S)z�
        L{IReactorUNIX.connectUNIX} can be used to connect a client to a server
        started with L{IReactorUNIX.listenUNIX}.
        cs6|\}}���jt���g�|j��|j��dS)N)rr rrr!�loseConnection)�args�serverProtocolZclientProtocol)�
clientFactoryr3rrr�allConnectedNs

z1UnixSocketTests.test_dumber.<locals>.allConnected)
r&rr	r'r(rr)r*r+r�connectUNIX�
gatherResultsr2)rr$�serverConnMader4�clientConnMade�dr:r)r9r3rr�test_dumber>s	
zUnixSocketTests.test_dumbercs�����t�}t��}||_tj�|dd����t�	�d��t
��t��}|�_tj��dd�t�||g�}����fdd�}|�
|���fdd	�}|�
|�|S)
z�
        A lockfile is created and locked when L{IReactorUNIX.listenUNIX} is
        called and released when the Deferred returned by the L{IListeningPort}
        provider's C{stopListening} method is called back.
        T)�wantPIDz.lock�)�checkPIDcs:|\}}���jt���g�|j��|j�����S)N)rr rrr!r6r+)r7r8ZclientProto)r9r3rr4rr�
_portStuffqs

z0UnixSocketTests.test_pidFile.<locals>._portStuffcs��t��d�d�dS)Nz.lock�locked)ZassertFalser�isLocked)�ignored)r3rrr�_check~sz,UnixSocketTests.test_pidFile.<locals>._check)r&rr	r'r(rr)Z
assertTruerrFrr;r<r2)rr$r=r>r?rDrHr)r9r3rr4r�test_pidFile[s 

zUnixSocketTests.test_pidFilecsR|���t��tj��dd�}|jtjtj��dd���fdd�}|���|�S)z�
        L{IReactorUNIX.listenUNIX} raises L{error.CannotListenError} if passed
        the name of a file on which a server is already listening.
        T)rAcstj��dd�}|��S)NT)rA)rr)r+)�ignr4)r3r$rr�stoppedListening�sz<UnixSocketTests.test_socketLocking.<locals>.stoppedListening)	r&rrr)�assertRaisesr�CannotListenErrorr+r2)rr4rKr)r3r$r�test_socketLocking�sz"UnixSocketTests.test_socketLockingcCsj|��|_td|jf�}dttj�tj���	�ji}ttj
��	�j}tj|dd|f|d�}|�
|�|S)Nzmfrom twisted.internet import protocol, reactor
reactor.listenUNIX(%r, protocol.ServerFactory(),wantPID=True)
s
PYTHONPATHs-us-c)�env)r&r3r
r�os�pathsep�join�sys�pathZasBytesMode�
executabler
ZgetProcessValuer2)r�callback�sourcerOZpyExer?rrr�_uncleanSocketTest�s

z"UnixSocketTests._uncleanSocketTestcs�fdd�}��|�S)a"
        If passed C{True} for the C{wantPID} parameter, a server can be started
        listening with L{IReactorUNIX.listenUNIX} when passed the name of a
        file on which a previous server which has not exited cleanly has been
        listening using the C{wantPID} option.
        cstj�jt�dd�}|��S)NT)rA)rr)r3rr+)rJ�p)rrr�ranStupidChild�szGUnixSocketTests.test_uncleanServerSocketLocking.<locals>.ranStupidChild)rX)rrZr)rr�test_uncleanServerSocketLocking�sz/UnixSocketTests.test_uncleanServerSocketLockingcs�fdd�}��|�S)z�
        If passed C{True} for the C{checkPID} parameter, a client connection
        attempt made with L{IReactorUNIX.connectUNIX} fails with
        L{error.BadFileError}.
        cs0t��}t|�}tj�j|dd���|tj�S)NT)rC)	r	r'rrr;r3Z
assertFailurerZBadFileError)rJr?�f)rrrrZ�szCUnixSocketTests.test_connectToUncleanServer.<locals>.ranStupidChild)rX)rrZr)rr�test_connectToUncleanServer�sz+UnixSocketTests.test_connectToUncleanServercsj���}t�||��d�|f}��t��|���t��|�t��j�}���fdd�}|�	|�|S)z~
        Test the C{__str__} and C{__repr__} implementations of a UNIX port when
        used with the given factory.
        z
<%s on %r>cs.d�f}��t��|���t��|�dS)Nz<%s (not listening)>)r�repr�str)rJ�unconnectedString)�factoryNamerr4rrrK�s
z3UnixSocketTests._reprTest.<locals>.stoppedListening)
r&rr)rr^r_r	�
maybeDeferredr+r2)rr$rar3�connectedStringr?rKr)rarr4r�	_reprTest�s
zUnixSocketTests._reprTestcCs*Gdd�d�}|�|tj�|�|�d�S)a
        The two string representations of the L{IListeningPort} returned by
        L{IReactorUNIX.listenUNIX} contains the name of the classic factory
        class being used and the filename on which the port is listening or
        indicates that the port is not listening.
        c@seZdZdd�Zdd�ZdS)zCUnixSocketTests.test_reprWithClassicFactory.<locals>.ClassicFactorycSsdS)Nr)rrrr�doStart�szKUnixSocketTests.test_reprWithClassicFactory.<locals>.ClassicFactory.doStartcSsdS)Nr)rrrr�doStop�szJUnixSocketTests.test_reprWithClassicFactory.<locals>.ClassicFactory.doStopN)rrrrerfrrrr�ClassicFactory�srgz%twisted.test.test_unix.ClassicFactory)�assertIsInstance�types�	ClassTyperd)rrgrrr�test_reprWithClassicFactory�sz+UnixSocketTests.test_reprWithClassicFactoryz)Classic classes do not exist on Python 3.cCs*Gdd�dt�}|�|t�|�|�d�S)a!
        The two string representations of the L{IListeningPort} returned by
        L{IReactorUNIX.listenUNIX} contains the name of the new-style factory
        class being used and the filename on which the port is listening or
        indicates that the port is not listening.
        c@seZdZdd�Zdd�ZdS)zEUnixSocketTests.test_reprWithNewStyleFactory.<locals>.NewStyleFactorycSsdS)Nr)rrrrre�szMUnixSocketTests.test_reprWithNewStyleFactory.<locals>.NewStyleFactory.doStartcSsdS)Nr)rrrrrf�szLUnixSocketTests.test_reprWithNewStyleFactory.<locals>.NewStyleFactory.doStopN)rrrrerfrrrr�NewStyleFactory�srlz&twisted.test.test_unix.NewStyleFactory)�objectrh�typerd)rrlrrr�test_reprWithNewStyleFactory�sz,UnixSocketTests.test_reprWithNewStyleFactoryN)rrr�__doc__r5r@rIrNrXr[r]rdrkr�skiprorrrrr"s)rc@s8eZdZdZZdZdd�Zdd�Zdd�Zd	d
�Z	dS)�ClientProtoFNcCst��|_t��|_dS)N)r	r'�deferredStarted�deferredGotBack)rrrrrs
zClientProto.__init__cCs
d|_dS)NT)�stopped)rrrr�stopProtocolszClientProto.stopProtocolcCsd|_|j�d�dS)NT)�startedrsrV)rrrr�
startProtocolszClientProto.startProtocolcCs||_|j�d�dS)N)�gotbackrtrV)r�datarrr�datagramReceivedszClientProto.datagramReceived)
rrrrwruryrrvrxr{rrrrrrsrrc@s<eZdZdZZdZZdd�Zdd�Zdd�Z	d	d
�Z
dS)�ServerProtoFNcCst��|_t��|_dS)N)r	r'rs�deferredGotWhat)rrrrr s
zServerProto.__init__cCs
d|_dS)NT)ru)rrrrrv$szServerProto.stopProtocolcCsd|_|j�d�dS)NT)rwrsrV)rrrrrx'szServerProto.startProtocolcCs*||_|j�d|�||_|j�d�dS)Nshi back)�gotfromr!�write�gotwhatr}rV)rrz�addrrrrr{+szServerProto.datagramReceived)rrrrwrur�r~rrvrxr{rrrrr|sr|c@sBeZdZdZdd�Zdd�Zdd�Zdd	�Zer6d
e_	dd�Z
d
S)�DatagramUnixSocketTestsz%
    Test datagram UNIX sockets.
    cs��������}t��t��t�|��}��|j�tj|��d�}��|j�t�	�j
�j
g�}��fdd�}����fdd�}|�|�|�|�|S)zf
        Test that a datagram can be sent to and received by a server and vice
        versa.
        )ZbindAddresscs�j�d�t��j�jg�S)Nshi)r!rr	r<r}rt)rG)�cp�sprrrFsz4DatagramUnixSocketTests.test_exchange.<locals>.writecs.��d�j�����j���d�j�dS)Nshishi back)rr�r~ry)rG)�
clientaddrr�rr�rr�_cbTestExchangeKsz>DatagramUnixSocketTests.test_exchange.<locals>._cbTestExchange)r&r|rrr�listenUNIXDatagramr*r+ZconnectUNIXDatagramr	r<rsr2)rZ
serveraddr�s�cr?rr�r)r�r�rr�r�
test_exchange7s

z%DatagramUnixSocketTests.test_exchangecCsD|��}t�}t�||�}|�tjtj||�|��t�	|�dS)z�
        L{IReactorUNIXDatagram.listenUNIXDatagram} raises
        L{error.CannotListenError} if the unix socket specified is already in
        use.
        N)
r&r|rr�rLrrMr+rP�unlink)rr�rYr�rrr�test_cannotListenUsz)DatagramUnixSocketTests.test_cannotListencsj���}t�||��d�|f}��t��|���t��|�t��j�}���fdd�}|�	|�|S)z�
        Test the C{__str__} and C{__repr__} implementations of a UNIX datagram
        port when used with the given protocol.
        z
<%s on %r>cs.d�f}��t��|���t��|�dS)Nz<%s (not listening)>)rr^r_)rJr`)�protocolNamerr4rrrKrs
z;DatagramUnixSocketTests._reprTest.<locals>.stoppedListening)
r&rr�rr^r_r	rbr+r2)rZserverProtor�r3rcZstopDeferredrKr)r�rr4rrdes
z!DatagramUnixSocketTests._reprTestcCs*Gdd�d�}|�|tj�|�|�d�S)a0
        The two string representations of the L{IListeningPort} returned by
        L{IReactorUNIXDatagram.listenUNIXDatagram} contains the name of the
        classic protocol class being used and the filename on which the port is
        listening or indicates that the port is not listening.
        c@seZdZdd�Zdd�ZdS)zMDatagramUnixSocketTests.test_reprWithClassicProtocol.<locals>.ClassicProtocolcSsdS)Nr)rr!rrr�makeConnection�sz\DatagramUnixSocketTests.test_reprWithClassicProtocol.<locals>.ClassicProtocol.makeConnectioncSsdS)Nr)rrrrrf�szTDatagramUnixSocketTests.test_reprWithClassicProtocol.<locals>.ClassicProtocol.doStopN)rrrr�rfrrrr�ClassicProtocol�sr�z&twisted.test.test_unix.ClassicProtocol)rhrirjrd)rr�rrr�test_reprWithClassicProtocolzsz4DatagramUnixSocketTests.test_reprWithClassicProtocolz)Classic classes do not exist on Python 3.cCs*Gdd�dt�}|�|t�|�|�d�S)a2
        The two string representations of the L{IListeningPort} returned by
        L{IReactorUNIXDatagram.listenUNIXDatagram} contains the name of the
        new-style protocol class being used and the filename on which the port
        is listening or indicates that the port is not listening.
        c@seZdZdd�Zdd�ZdS)zODatagramUnixSocketTests.test_reprWithNewStyleProtocol.<locals>.NewStyleProtocolcSsdS)Nr)rr!rrrr��sz^DatagramUnixSocketTests.test_reprWithNewStyleProtocol.<locals>.NewStyleProtocol.makeConnectioncSsdS)Nr)rrrrrf�szVDatagramUnixSocketTests.test_reprWithNewStyleProtocol.<locals>.NewStyleProtocol.doStopN)rrrr�rfrrrr�NewStyleProtocol�sr�z'twisted.test.test_unix.NewStyleProtocol)rmrhrnrd)rr�rrr�test_reprWithNewStyleProtocol�sz5DatagramUnixSocketTests.test_reprWithNewStyleProtocolN)rrrrpr�r�rdr�rrqr�rrrrr�3sr�z1This reactor does not support UNIX domain socketsz3This reactor does not support UNIX datagram sockets)(rp�
__future__rrrPrSrir,Ztwisted.internetrrrrrr	r
Ztwisted.pythonrZtwisted.python.compatrr
Ztwisted.python.filepathrZ
twisted.trialrZtwisted.test.test_tcprrZ
ClientFactoryrZTestCaserZConnectedDatagramProtocolrrZDatagramProtocolr|r�ZIReactorUNIXrqZIReactorUNIXDatagramrrrr�<module>s,	fv