�
Ϫ�f�N � � � 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$ dejJ ejL fd�Z' G d� de� Z( G d� d� Z) G d� de� Z*d� Z+d� Z, G d� de� Z- G d� d� Z. G d� d e� Z/ G d!� d"e(� Z0 G d#� d$� Z1 G d%� d&� Z2 G d'� d(� Z3 G d)� d*� Z4y)+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 �� � t j | d� d d }t j ||� } |j |� |t j k( r_|j � }t j
|t j t j z � d }||d f|j � S |j � |j � S # |j � w xY 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�hostnames �H/usr/lib/python3/dist-packages/twisted/internet/test/connectionmixins.py�findFreePortr, s� � � ���i��+�A�.�q�1�D��M�M�&�$�'�E��
�
�
�4���V�_�_�$��(�(�*�H��)�)��&�/�/�&�2G�2G�G����H� �h�q�k�*� ���
� �$�$�&�
���
�����
�s �A2C �7C �C)c � � e Zd ZdZdZd� Zd� Zy)�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 � � || _ || _ y)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)�selfr0 �dones r+ �_setAttributesz"ConnectableProtocol._setAttributesJ s � � �����
� c �L � || _ | j j d � | `y �N)�disconnectReasonr1 �callback�r2 �reasons r+ �connectionLostz"ConnectableProtocol.connectionLostX s! � � &����
�
���D�!��Jr5 )�__name__�
__module__�__qualname__�__doc__r8 r4 r< |