Your IP : 216.73.216.213
B
:��]|� � @ s0 d Z ddlmZmZ ddlZddlZddlZddlZddlZddl Z ddl
mZmZ ddl
mZ ddlmZmZ ddlmZ ddlmZmZ ydd lmZmZmZ W nD ek
r� G d
d� de�ZG dd
� d
e�ZG dd� de�ZY nX edk�rxe� Z ddl!m"Z# ddl!m$Z% ddl!m&Z' ddl!m(Z) ddl!m*Z+ ddl!m,Z- ddl!m.Z/ e� Z0e� Z1e%Z2ddl!m3Z4 ddl5m6Z7 n�ddl!m Z ddl!m#Z# ddl!m%Z% ddl!m'Z' ddl!m)Z) ddl!m+Z+ dd l!m-Z- dd!l!m/Z/ dd"l!m0Z0 dd#l!m1Z1 dd$l!m2Z2 dd%l!m4Z4 dd&lm7Z7 dd'l!m8Z8 dd(l9m:Z:m;Z;m<Z< dd)l=m>Z> dd*lm?Z?m@Z@mAZA dd+lBmCZC dd,lDmEZE dd-l9mFZFmGZGmHZHmIZI dd.lJmKZK eLed/d�ZMeNefZOd0d1� ZPd2d3� ZQd4d5� ZRG d6d7� d7e�ZSG d8d9� d9e�ZTeeHjUeHjV�G d:d;� d;eeFjWeSeT��ZXG d<d=� d=e�ZYG d>d?� d?eYeeX�ZZej[eMB Z\d@dA� Z]G dBdC� dCe�Z^G dDdE� dEe^eZ�Z_G dFdG� dGeeX�Z`G dHdI� dIe�Zaeea�e jbG dJdK� dKe���Zceea�G dLdM� dMe��Zdedk�r�ed� ZenecdNdO� �Zee/e-e0e1e4fZfe jbG dPdQ� dQe��ZgdRdS� ZheeHji�G dTdU� dUe:jjeS��ZkG dVdW� dWe:jl�ZmdS )Xzt
Various asynchronous TCP/IP classes.
End users shouldn't use this module directly - use the reactor APIs instead.
� )�division�absolute_importN)� Interface�implementer)�Logger)�
lazyByteSlice�unicode)�platformType)�versions� deprecate)�ConnectionMixin�ClientMixin�ServerMixinc @ s e Zd ZdZdS )�_TLSConnectionMixinFN)�__name__�
__module__�__qualname__ZTLS� r r �G/opt/alt/python37/lib64/python3.7/site-packages/twisted/internet/tcp.pyr % s r c @ s e Zd ZdS )�_TLSClientMixinN)r r r r r r r r ) s r c @ s e Zd ZdS )�_TLSServerMixinN)r r r r r r r r - s r �win32)� WSAEINVAL)�WSAEWOULDBLOCK)�WSAEINPROGRESS)�WSAEALREADY)�
WSAEISCONN)�
WSAENOBUFS)� WSAEMFILE)�
WSAECONNRESET)�formatError)�EPERM)�EINVAL)�EWOULDBLOCK)�EINPROGRESS)�EALREADY)�EISCONN)�ENOBUFS)�EMFILE)�ENFILE)�ENOMEM)�EAGAIN)�ECONNABORTED)�strerror)� errorcode)�base�address�fdesc)�
deferLater)�log�failure�reflect)�untilConcludes)�CannotListenError)�abstract�main�
interfaces�error)�Protocol�AI_NUMERICSERVc C sN t | �dkr>t�| tjtjB �d }t|gt| dd� � �S | dd� S dS )ai
Return a 2-tuple of socket IP and port for IPv4 and a 4-tuple of
socket IP, port, flowInfo, and scopeID for IPv6. For IPv6, it
returns the interface portion (the part after the %) as a part of
the IPv6 address, which Python 3.7+ does not include.
@param addr: A 2-tuple for IPv4 information or a 4-tuple for IPv6
information.
� r � N� )�len�socket�getnameinfo�NI_NUMERICHOST�NI_NUMERICSERV�tuple�list)�addr�hostr r r �_getrealnameg s
rJ c C s t | �� �S )z
See L{_getrealname}.
)rJ �getpeername)�sktr r r �_getpeername{ s rM c C s t | �� �S )z
See L{_getrealname}.
)rJ �getsockname)rL r r r �_getsockname� s rO c @ s e Zd ZdZdZdd� ZdS )�
_SocketCloserz�
@ivar _shouldShutdown: Set to C{True} if C{shutdown} should be called
before calling C{close} on the underlying socket.
@type _shouldShutdown: C{bool}
Tc C s~ | j }y8|r| jr<|�d� n| j �t jt jt�ddd�� W n t jk
rT Y nX y|� � W n t jk
rx Y nX d S )Nr@ �iir? r )
rB �_shouldShutdown�shutdown�
setsockopt�
SOL_SOCKET� SO_LINGER�struct�packr; �close)�selfZorderlyrL r r r �_closeSocket� s z_SocketCloser._closeSocketN)r r r �__doc__rR r[ r r r r rP � s rP c @ s e Zd ZdZdZdd� ZdS )�_AbortingMixinz�
Common implementation of C{abortConnection}.
@ivar _aborting: Set to C{True} when C{abortConnection} is called.
@type _aborting: C{bool}
Fc C sZ | j s| jrdS d| _| �� | �� dd� | _dd� | _| j�d| jt �
t�� �� dS )zf
Aborts the connection immediately, dropping any buffered data.
@since: 11.1
NTc _ s d S )Nr )�args�kwargsr r r �<lambda>� � z0_AbortingMixin.abortConnection.<locals>.<lambda>c _ s d S )Nr )r^ r_ r r r r` � ra r )
�disconnected� _aborting�stopReading�stopWriting�doRead�doWrite�reactor� callLater�connectionLostr4 �Failurer; �ConnectionAborted)rZ r r r �abortConnection� s
z_AbortingMixin.abortConnectionN)r r r r\ rc rm r r r r r] � s r] c @ s~ e Zd ZdZddd�Zdd� Zdd� Zd d
� Zdd� Zd
d� Z dd� Z
dd� ZdZdd� Z
dd� Zdd� Zdd� Zdd� ZdS )�
Connectiona
Superclass of all socket-based FileDescriptors.
This is an abstract superclass of all objects which represent a TCP/IP
connection based socket.
@ivar logstr: prefix used when logging events related to this connection.
@type logstr: C{str}
Nc C s4 t jj| |d� || _| j�d� |j| _|| _d S )N)rh r )r8 �FileDescriptor�__init__rB �setblocking�fileno�protocol)rZ rL rs rh r r r rp � s
zConnection.__init__c C s | j S )z&Return the socket for this connection.)rB )rZ r r r � getHandle� s zConnection.getHandlec
C sZ y| j �| j�}W n< t jk
rN } z|jd tkr8dS tjS W dd}~X Y nX | �|�S )a\ Calls self.protocol.dataReceived with all available data.
This reads up to self.bufferSize bytes of data from its socket, then
calls self.dataReceived(data) to process it. If the connection is not
lost through an error in the physical recv(), this function will return
the result of the dataReceived call.
r N) rB �recvZ
bufferSizer; r^ r# r9 �CONNECTION_LOST�
_dataReceived)rZ �data�ser r r rf � s zConnection.doReadc C sV |s
t jS | j�|�}|d k rR| jj}d}tj|t�dddd�|d�}t�||� |S )NzPReturning a value other than None from %(fqpn)s is deprecated since %(version)s.�Twisted� r )�format) r9 �CONNECTION_DONErs ZdataReceivedr ZgetDeprecationWarningStringr
�VersionZwarnAboutFunction)rZ rx ZrvalZoffenderZ
warningFormatZ
warningStringr r r rw � s zConnection._dataReceivedc
C sb t |d| j�}yt| jj|�S tjk
r\ } z |jd ttfkrFdS t j
S W dd}~X Y nX dS )a
Write as much as possible of the given data to this TCP connection.
This sends up to C{self.SEND_LIMIT} bytes from C{data}. If the
connection is lost, an exception is returned. Otherwise, the number
of bytes successfully written is returned.
r N)r Z
SEND_LIMITr6 rB �sendr; r^ r# r'