�
Ϫ�f\2 � � � d Z ddlZddlZddlZddlZddlmZmZmZ ddl m
Z
ddlmZm
Z
mZ ddlmZmZ ddlmZ ddlmZmZmZmZmZ dd lmZmZ dd
lmZmZm Z m!Z! ddl"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z* ddl+m,Z,m-Z-m.Z.m/Z/ dd
l0m1Z1m2Z2 ddl4m5Z5 ddl6m7Z7 ddl8m9Z9 ddl:m;Z; ddl<m=Z=m>Z> ddl?m@Z@mAZA ddlBmCZCmDZDmEZE ddlFmGZG ddlHmIZI ddlJmKZK ddlLmMZM ddlNmOZOmPZP ddlQmRZS ddlTmUZUmVZVmWZWmXZXmYZYmZZZ ddl[m\Z] e]Z\g d�Z^ G d� d e/� Z_ G d!� d"e,� Z` e
ej� � G d#� d$� � Zb G d%� d&ej� ej� ej� � Zf G d'� d( eGefd)� � Zg G d*� d+e.� Zh G d,� d-e� Zi e
ej� � G d.� d/� � Zk e
ej� � G d0� d1� � Zl G d2� d3el� Zm G d4� d5el� Zn e
ej� � G d6� d7� � Zo e
ej� � G d8� d9� � Zp e
e$� G d:� d;� � Zq e
ej� � G d<� d=� � Zr e
ej� � G d>� d?� � Zs e
ej� � G d@� dA� � Zt e
ej� � G dB� dC� � Zu e
ej� � G dD� dE� � Zv e
ej� � G dF� dG� � ZwdkdH�ZxdldI�Zy dmdJ�Zz e
e=e*� G dK� dL� � Z{ e
e=e*� G dM� dN� � Z| e
e=e*� G dO� dP� � Z}exeyezdQ�Z~ edR� \ Z�Z�dS� Z�dT� Z�emeseudU�Z�eoetevdU�Z�dV� Z�dW� Z�dX� Z�dY� Z�dZ� Z�d[� Z�d\� Z�d]� Z�d^� Z�d_� Z�d`� Z�e�e�e�dU�Z�da� Z�db� Z� e
ej� � G dc� dd� � Z� e
ej� � G de� df� � Z�dg� Z� dndh�Z� e
e=e)� G di� dj� � Z�y# e3$ r dZ2dZ1Y ��qw xY w# e3$ r dZ\Y ��w xY w)oa7
Implementations of L{IStreamServerEndpoint} and L{IStreamClientEndpoint} that
wrap the L{IReactorTCP}, L{IReactorSSL}, and L{IReactorUNIX} interfaces.
This also implements an extensible mini-language for describing endpoints,
parsed by the L{clientFromString} and L{serverFromString} functions.
@since: 10.1
� N)�Optional�Sequence�Type)� normalize)�directlyProvides�implementer�provider)�
NamedConstant�Names)�Version)�defer�error�fdesc�
interfaces�threads)�isIPAddress�
isIPv6Address)�HostnameAddress�IPv4Address�IPv6Address�_ProcessAddress)�IAddress�IHostnameResolver�IHostResolution�IReactorPluggableNameResolver�IReactorSocket�IResolutionReceiver�,IStreamClientEndpointStringParserWithReactor�!IStreamServerEndpointStringParser)�
ClientFactory�Factory�ProcessProtocol�Protocol)�PipeAddress�
StandardIO)�HostResolution)�Deferred)�LoopingCall)�Logger)�IPlugin�
getPlugins)� deprecate�log)�_matchingString� iterbytes�nativeString)�proxyForInterface)�Failure)�FilePath)� ListenFDs� )�
_idnaBytes� _idnaText)�Error)�Certificate�CertificateOptions�KeyPair�PrivateCertificate�optionsForClientTLS�trustRootFromCertificates��TLSMemoryBIOFactory)�clientFromString�serverFromString�TCP4ServerEndpoint�TCP6ServerEndpoint�TCP4ClientEndpoint�TCP6ClientEndpoint�UNIXServerEndpoint�UNIXClientEndpoint�SSL4ServerEndpoint�SSL4ClientEndpoint�AdoptedStreamServerEndpoint�StandardIOEndpoint�ProcessEndpoint�HostnameEndpoint�StandardErrorBehavior�connectProtocol�
wrapClientTLSc �F � e Zd ZdZd� Zd� Zd� Zd� Zd� Zd� Z d� Z
d � Zd
� Zy)�_WrappingProtocolz_
Wrap another protocol in order to notify my user when a connection has
been made.
c �� � || _ || _ t j t j t j
fD ]* }|j
| j � s�t | |� �, y)z�
@param connectedDeferred: The L{Deferred} that will callback
with the C{wrappedProtocol} when it is connected.
@param wrappedProtocol: An L{IProtocol} provider that will be
connected.
N)�_connectedDeferred�_wrappedProtocolr �IHalfCloseableProtocol�IFileDescriptorReceiver�IHandshakeListener�
providedByr )�self�connectedDeferred�wrappedProtocol�ifaces �</usr/lib/python3/dist-packages/twisted/internet/endpoints.py�__init__z_WrappingProtocol.__init__p sb � � #4��� /���
�-�-��.�.��)�)�
� .�E�
���� 5� 5�6� ��u�-�
.� c �� � t j j | j � r| j j � S | j j
j S )zO
Transparently pass through the wrapped protocol's log prefix.
)r �ILoggingContextrZ rV � logPrefix� __class__�__name__�r[ s r_ rd z_WrappingProtocol.logPrefix� sK � � �%�%�0�0��1F�1F�G��(�(�2�2�4�4��$�$�.�.�7�7�7ra c � � | j j | j � | j j | j � y)z�
Connect the C{self._wrappedProtocol} to our C{self.transport} and
callback C{self._connectedDeferred} with the C{self._wrappedProtocol}
N)rV �makeConnection� transportrU �callbackrg s r_ �connectionMadez _WrappingProtocol.connectionMade� s6 � �
���,�,�T�^�^�<����(�(��)>�)>�?ra c �8 � | j j |� S )zM
Proxy C{dataReceived} calls to our C{self._wrappedProtocol}
)rV �dataReceived)r[ �datas r_ rn z_WrappingProtocol.dataReceived� s � � �$�$�1�1�$�7�7ra c �8 � | j j |� S )zW
Proxy C{fileDescriptorReceived} calls to our C{self._wrappedProtocol}
)rV �fileDescriptorReceived)r[ �
descriptors r_ rq z(_WrappingProtocol.fileDescriptorReceived� s � � �$�$�;�;�J�G�Gra c �8 � | j j |� S )zO
Proxy C{connectionLost} calls to our C{self._wrappedProtocol}
)rV �connectionLost�r[ �reasons r_ rt z _WrappingProtocol.connectionLost� s � � �$�$�3�3�F�;�;ra c �8 � | j j � y)zl
Proxy L{IHalfCloseableProtocol.readConnectionLost} to our
C{self._wrappedProtocol}
N)rV �readConnectionLostrg s r_ rx z$_WrappingProtocol.readConnectionLost� � � �
���0�0�2ra c �8 � | j j � y)zm
Proxy L{IHalfCloseableProtocol.writeConnectionLost} to our
C{self._wrappedProtocol}
N)rV �writeConnectionLostrg s r_ r{ z%_WrappingProtocol.writeConnectionLost� s � �
���1�1�3ra c �8 � | j j � y)za
Proxy L{interfaces.IHandshakeListener} to our
C{self._wrappedProtocol}.
N)rV �handshakeCompletedrg s r_ r} z$_WrappingProtocol.handshakeCompleted� ry ra N)
rf �
__module__�__qualname__�__doc__r` rd rl rn rq rt rx r{ r} � ra r_ rS rS j s6 � ��
.�&8�@�8�H�<�3�4�3ra rS c �> |