File: //usr/lib/python3/dist-packages/twisted/internet/test/__pycache__/connectionmixins.cpython-310.pyc
o
�b�N � @ s� d Z ddlZddlmZ ddlmZ ddlmZ ddlm Z ddl
mZmZ ddl
mZmZ dd lmZmZmZ dd
lmZ ddlmZmZ ddlmZ dd
lmZmZmZ ddlm Z ddl!m"Z" ddl#m$Z$ dej%ej&fdd�Z'G dd� de�Z(G dd� d�Z)G dd� de�Z*dd� Z+dd� Z,G dd� de�Z-G d d!� d!�Z.G d"d#� d#e�Z/G d$d%� d%e(�Z0G d&d'� d'�Z1G d(d)� d)�Z2G d*d+� d+�Z3G d,d-� d-�Z4dS ).z?
Various helpers for tests for connection-oriented transports.
� N)�collect)�Optional)�ref)�verifyObject)�Deferred�
gatherResults)�
IConnector�
IReactorFDSet)�
ClientFactory�Protocol�
ServerFactory)�needsRunningReactor)�context�log)�Failure)�ILogContext�err�msg)�platform)�ClosingProtocol)�SkipTestz 127.0.0.1c C s� t �| d�d d }t � ||�}z.|�|� |t jkr6|�� }t �|t jt jB �d }||d fW |�� S |�� W |�� S |�� w )a�
Ask the platform to allocate a free port on the specified interface, then
release the socket and return the address which was allocated.
@param interface: The local address to try to bind the port on.
@type interface: C{str}
@param type: The socket type which will use the resulting port.
@return: A two-tuple of address and port, like that returned by
L{socket.getsockname}.
r � � ) �socket�getaddrinfo�bind�AF_INET6�getsockname�getnameinfo�NI_NUMERICHOST�NI_NUMERICSERV�close)� interface�family�type�addr�probe�sockname�hostname� r) �H/usr/lib/python3/dist-packages/twisted/internet/test/connectionmixins.py�findFreePort s
��
�r+ c @ �$ e Zd ZdZdZdd� Zdd� ZdS )�ConnectableProtocolab
A protocol to be used with L{runProtocolsWithReactor}.
The protocol and its pair should eventually disconnect from each other.
@ivar reactor: The reactor used in this test.
@ivar disconnectReason: The L{Failure} passed to C{connectionLost}.
@ivar _done: A L{Deferred} which will be fired when the connection is
lost.
Nc C s || _ || _dS )aN
Set attributes on the protocol that are known only externally; this
will be called by L{runProtocolsWithReactor} when this protocol is
instantiated.
@param reactor: The reactor used in this test.
@param done: A L{Deferred} which will be fired when the connection is
lost.
N)�reactor�_done)�selfr. �doner) r) r* �_setAttributesJ s
z"ConnectableProtocol._setAttributesc C s || _ | j�d � | `d S �N)�disconnectReasonr/ �callback�r0 �reasonr) r) r* �connectionLostX s z"ConnectableProtocol.connectionLost)�__name__�
__module__�__qualname__�__doc__r4 r2 r8 r) r) r) r* r- : s
r- c @ � e Zd ZdZdd� Zdd� ZdS )�EndpointCreatorzT
Create client and server endpoints that know how to connect to each other.
c C � t � �)z�
Return an object providing C{IStreamServerEndpoint} for use in creating
a server to use to establish the connection type to be tested.
��NotImplementedError�r0 r. r) r) r* �serverc � zEndpointCreator.serverc C r? )z�
Return an object providing C{IStreamClientEndpoint} for use in creating
a client to use to establish the connection type to be tested.
r@ )r0 r. �
serverAddressr) r) r* �clientj rD zEndpointCreator.clientN)r9 r: r; r<