File: //usr/lib/python3/dist-packages/twisted/internet/test/__pycache__/connectionmixins.cpython-38.pyc
U
W[�O � @ s� d Z ddlmZmZ ddlZddlmZ ddlmZ ddl m
Z
ddlmZm
Z
ddlmZ dd lmZ dd
lmZmZmZ ddlmZmZ ddlmZmZ dd
lmZmZmZ ddl m!Z! ddl"m#Z# ddl$m%Z% dej&ej'fdd�Z(G dd� de�Z)G dd� de*�Z+G dd� de�Z,dd� Z-dd� Z.G dd� de�Z/G d d!� d!e*�Z0G d"d#� d#e�Z1G d$d%� d%e)�Z2G d&d'� d'e*�Z3G d(d)� d)e*�Z4G d*d+� d+e*�Z5G d,d-� d-e*�Z6dS ).z?
Various helpers for tests for connection-oriented transports.
� )�division�absolute_importN)�collect)�ref)�verifyObject)�context�log)�Failure)�platform)�ILogContext�msg�err)�Deferred�
gatherResults)�
IConnector�
IReactorFDSet)�
ClientFactory�Protocol�
ServerFactory)�SkipTest)�needsRunningReactor)�ClosingProtocolz 127.0.0.1c C s� t �| d�d d }t � ||�}zT|�|� |t jkrf|�� }t �|t jt jB �d }||d fW �S |�� W �S W 5 |�� X dS )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 � � N) �socketZgetaddrinfo�closeZbindZAF_INET6ZgetsocknameZgetnameinfoZNI_NUMERICHOSTZNI_NUMERICSERV)Z interfaceZfamily�type�addrZprobeZsocknameZhostname� r �H/usr/lib/python3/dist-packages/twisted/internet/test/connectionmixins.py�findFreePort s
��r c @ s$ 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"