Current File : //proc/self/root/lib/python3/dist-packages/twisted/internet/__pycache__/tcp.cpython-312.pyc
�

Ϫ�f���	��dZddlmZddlZddlZddlZddlZddlmZm	Z	m
Z
mZmZddl
mZmZddlZddlZddlmZmZmZmZmZmZddlmZmZmZddlmZmZdd	lm Z dd
l!m"Z"	ddl#m$Z%m&Z'm(Z)ddlm*Z*e"dk(r6e,�Z-ddl.m/Z0m1Z2m3Z4m5Z6m7Z8m9Z:m;Z<e,�Z=e,�Z>e<Z?ddl.m@ZAddlBmCZDnNddl.m-Z-ddl.m4Z4ddl.m<Z<ddl.m2Z2ddl.m0Z0ddl.m6Z6ddl.m:Z:ddl.m8Z8ddl.m=Z=dd l.m>Z>dd!l.m?Z?dd"l.mAZAdd#lmDZDdd$l.mEZEdd%lFmGZGmHZHmIZImJZJmKZKmLZLdd&lMmNZNdd'lOmPZPdd(lQmRZRdd)lmSZSmTZTmUZUdd*lVmWZWeXed+d�ZYd,�ZZd-�Z[d.�Z\Gd/�d0�Z]Gd1�d2�Z^ee*ee�Gd3�d4e'eGj�e]e^��Z`Gd5�d6�ZaGd7�d8eae%e`�Zbej�eYzZdd9�ZeGd:�d;�ZfGd<�d=efeb�ZgGd>�d?e)e`�ZhGd@�dAe�ZiGdB�dCej��Zjeei�ej�dD�E�GdF�dG���Zleei�GdH�dI��Zme"dk(rem�Znn	eldJ��Zne8e:e=e>eAfZoej�dD�E�GdK�dL��ZpdM�Zqee�GdN�dOeIj�e]��ZsGdP�dQeIj��Zuy#e+$r$eZ*Gd
�d�Z'Gd�d�Z%Gd�d�Z)Y��WwxYw)Rzt
Various asynchronous TCP/IP classes.

End users shouldn't use this module directly - use the reactor APIs instead.
�)�annotationsN)�Callable�ClassVar�List�Optional�Union)�	Interface�implementer)�IHalfCloseableProtocol�IListeningPort�	IProtocol�IReactorTCP�
ISystemHandle�
ITCPTransport)�ILogObserver�LogEvent�Logger)�	deprecate�versions)�
lazyByteSlice)�platformType)�ClientMixin�ConnectionMixin�ServerMixin)�
ITLSTransportc��eZdZdZy)�_TLSConnectionMixinFN)�__name__�
__module__�__qualname__�TLS���6/usr/lib/python3/dist-packages/twisted/internet/tcp.pyrr2s���r#rc��eZdZy)�_TLSClientMixinN�rrr r"r#r$r&r&5���r#r&c��eZdZy)�_TLSServerMixinNr'r"r#r$r*r*8r(r#r*�win32)�WSAEALREADY�WSAEINPROGRESS�	WSAEINVAL�
WSAEISCONN�	WSAEMFILE�
WSAENOBUFS�WSAEWOULDBLOCK)�
WSAECONNRESET)�formatError)�EPERM)�EINVAL)�EWOULDBLOCK)�EINPROGRESS)�EALREADY)�EISCONN)�ENOBUFS)�EMFILE)�ENFILE)�ENOMEM)�EAGAIN)�ECONNABORTED)�strerror)�	errorcode)�abstract�address�base�error�fdesc�main)�CannotListenError)�Protocol)�
deferLater)�failure�log�reflect)�untilConcludes�AI_NUMERICSERVc���t|�dk(rStj|tjtjz�d}t|gt
|dd�z�S|ddS)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�hosts  r$�_getrealnamer^psc���4�y�A�~��!�!�$��(=�(=��@U�@U�(U�V�
�
���d�V�d�4���8�n�,�-�-��B�Q�x�r#c�4�t|j��S�z
    See L{_getrealname}.
    )r^�getpeername��skts r$�_getpeernamerd��������)�*�*r#c�4�t|j��Sr`)r^�getsocknamerbs r$�_getsocknamerh�rer#c��eZdZdZdZd�Zy)�
_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	�X�|j}	|r|jr`|jd�nN|jjtjtj
t
jddd��	|j�y#t$rY�wxYw#t$rYywxYw)NrT�iirSr)
rV�_shouldShutdown�shutdown�
setsockopt�
SOL_SOCKET�	SO_LINGER�struct�pack�OSError�close)�self�orderlyrcs   r$�_closeSocketz_SocketCloser._closeSocket�s���
�k�k��
	���'�'��L�L��O�
���&�&��%�%�v�'7�'7����T�1�a�9P��	��I�I�K���	��	���	��	�s$�A.B�=B�	B�B�	B)�(B)N)rrr �__doc__rmrxr"r#r$rjrj�s����O�r#rjc��eZdZdZdZd�Zy)�_AbortingMixinz�
    Common implementation of C{abortConnection}.

    @ivar _aborting: Set to C{True} when C{abortConnection} is called.
    @type _aborting: C{bool}
    Fc�<�|js|jryd|_|j�|j�d�|_d�|_|jjd|jtjtj���y)zf
        Aborts the connection immediately, dropping any buffered data.

        @since: 11.1
        NTc��y�Nr"��args�kwargss  r$�<lambda>z0_AbortingMixin.abortConnection.<locals>.<lambda>���r#c��yr~r"rs  r$r�z0_AbortingMixin.abortConnection.<locals>.<lambda>�r�r#r)
�disconnected�	_aborting�stopReading�stopWriting�doRead�doWrite�reactor�	callLater�connectionLostrL�FailurerF�ConnectionAborted�rvs r$�abortConnectionz_AbortingMixin.abortConnection�st��������������������2���3��������
�t�"�"�G�O�O�E�4K�4K�4M�$N�	
r#N)rrr ryr�r�r"r#r$r{r{�s����I�
r#r{c�d�eZdZdZdd�Zd�Zd�Zd�Zd�Zd�Z	d	�Z
d
�ZdZd�Z
d
�Zd�Zd�Zd�Zy)�
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��tjj||��||_|jj	d�|j
|_||_y)N�r�r)rC�FileDescriptor�__init__rV�setblocking�fileno�protocol)rvrcr�r�s    r$r�zConnection.__init__�sF�����(�(��w�(�?����������"��j�j��� ��
r#c��|jS)z&Return the socket for this connection.)rVr�s r$�	getHandlezConnection.getHandle�����{�{�r#c���	|jj|j�}|j|�S#t$r5}|jdt
k(rYd}~ytjcYd}~Sd}~wwxYw)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.
        rN)	rV�recv�
bufferSizertr�r7rH�CONNECTION_LOST�
_dataReceived)rv�data�ses   r$r�zConnection.doRead�sc��	,��;�;�#�#�D�O�O�4�D��!�!�$�'�'��
�	,��w�w�q�z�[�(���+�+�+��		,�s!�%8�	A6�A1�A1�+A6�1A6c	��|stjS|jj|�}|�\|jj}d}t	j
|t
jdddd�|��}t	j||�|S)NzPReturning a value other than None from %(fqpn)s is deprecated since %(version)s.�Twisted�r)�format)	rH�CONNECTION_DONEr��dataReceivedr�getDeprecationWarningStringr�Version�warnAboutFunction)rvr��rval�offender�
warningFormat�
warningStrings      r$r�zConnection._dataReceived�s�����'�'�'��}�}�)�)�$�/�����}�}�1�1�H�0�
�&�A�A��(�*�*�9�b�!�Q�?�
��M�
�'�'��-�@��r#c��t|d|j�}	t|jj|�S#t
$r:}|jdttfvrYd}~ytjcYd}~Sd}~wwxYw)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.
        rN)r�
SEND_LIMITrOrV�sendrtr�r7r;rHr�)rvr��limitedDatar�s    r$�
writeSomeDatazConnection.writeSomeDatasf��$�D�!�T�_�_�=��	,�!�$�+�+�"2�"2�K�@�@���	,��w�w�q�z�k�7�3�3���+�+�+��		,�s!�9�	A<�A7�"A7�1A<�7A<c�>�	|jjd�t|jd�}|r	|j�yy#t$rY�6wxYw#t$r<tj�}tj�|j|�YywxYw�NrS)rVrnrtrr��writeConnectionLost�
BaseExceptionrLr�rM�errr�)rv�p�fs   r$�_closeWriteConnectionz Connection._closeWriteConnection s���	��K�K� � ��#�
#�4�=�=�$�7���
'��%�%�'�
���	��	��!�
'��O�O�%�����	��#�#�A�&�
'�s#�A�A�	A�A�AB�Bc��t|jd�}|r	|j�y|j
|�y#t$r:t	j
�|j
tj��YywxYwr~)	rr��readConnectionLostr�rMr�r�rLr�)rv�reasonr�s   r$r�zConnection.readConnectionLost.se��"�4�=�=�$�7���
7��$�$�&�

����'��	!�
7����	��#�#�G�O�O�$5�6�
7�s�=�AB�?Bc��t|d�sytjj||�|j	|jtj��|j}|`|`	|`
|j|�y)z-See abstract.FileDescriptor.connectionLost().rVN)�hasattrrCr�r�rx�checkrFr�r�rVr�)rvr�r�s   r$r�zConnection.connectionLost9sm���t�X�&�����.�.�t�V�<����f�l�l�5�+B�+B�C�C�D��=�=���M��K��K�����'r#�
Uninitializedc��|jS)z<Return the prefix to log with when I own the logging thread.)�logstrr�s r$�	logPrefixzConnection.logPrefixLr�r#c��t|jjtjtj��Sr~)�boolrV�
getsockopt�IPPROTO_TCP�TCP_NODELAYr�s r$�
getTcpNoDelayzConnection.getTcpNoDelayPs*���D�K�K�*�*�6�+=�+=�v�?Q�?Q�R�S�Sr#c�v�|jjtjtj|�yr~)rVror�r��rv�enableds  r$�
setTcpNoDelayzConnection.setTcpNoDelaySs$�������v�1�1�6�3E�3E�w�Or#c��t|jjtjtj��Sr~)r�rVr�rp�SO_KEEPALIVEr�s r$�getTcpKeepAlivezConnection.getTcpKeepAliveVs*���D�K�K�*�*�6�+<�+<�f�>Q�>Q�R�S�Sr#c�v�|jjtjtj|�yr~)rVrorpr�r�s  r$�setTcpKeepAlivezConnection.setTcpKeepAliveYs$�������v�0�0�&�2E�2E�w�Or#r~)rrr ryr�r�r�r�r�r�r�r�r�r�r�r�r�r�r"r#r$r�r��sS���!��(�$� ,�('�	(�(�"�F��T�P�T�Pr#r�c�d�eZdZdZej
ZejZd�Z	d�Z
d�Zd�Zd�Z
d�Zy)	�_BaseBaseClienta�	
    Code shared with other (non-POSIX) reactors for management of general
    outgoing connections.

    Requirements upon subclasses are documented as instance variables rather
    than abstract methods, in order to avoid MRO confusion, since this base is
    mixed in to unfortunately weird and distinctive multiple-inheritance
    hierarchies and many of these attributes are provided by peer classes
    rather than descendant classes in those hierarchies.

    @ivar addressFamily: The address family constant (C{socket.AF_INET},
        C{socket.AF_INET6}, C{socket.AF_UNIX}) of the underlying socket of this
        client connection.
    @type addressFamily: C{int}

    @ivar socketType: The socket type constant (C{socket.SOCK_STREAM} or
        C{socket.SOCK_DGRAM}) of the underlying socket.
    @type socketType: C{int}

    @ivar _requiresResolution: A flag indicating whether the address of this
        client will require name resolution.  C{True} if the hostname of said
        address indicates a name that must be resolved by hostname lookup,
        C{False} if it indicates an IP address literal.
    @type _requiresResolution: C{bool}

    @cvar _commonConnection: Subclasses must provide this attribute, which
        indicates the L{Connection}-alike class to invoke C{__init__} and
        C{connectionLost} on.
    @type _commonConnection: C{type}

    @ivar _stopReadingAndWriting: Subclasses must implement in order to remove
        this transport from its reactor's notifications in response to a
        terminated connection attempt.
    @type _stopReadingAndWriting: 0-argument callable returning L{None}

    @ivar _closeSocket: Subclasses must implement in order to close the socket
        in response to a terminated connection attempt.
    @type _closeSocket: 1-argument callable; see L{_SocketCloser._closeSocket}

    @ivar _collectSocketDetails: Clean up references to the attached socket in
        its underlying OS resource (such as a file descriptor or file handle),
        as part of post connection-failure cleanup.
    @type _collectSocketDetails: 0-argument callable returning L{None}.

    @ivar reactor: The class pointed to by C{_commonConnection} should set this
        attribute in its constructor.
    @type reactor: L{twisted.internet.interfaces.IReactorTime},
        L{twisted.internet.interfaces.IReactorCore},
        L{twisted.internet.interfaces.IReactorFDSet}
    c��|r1|jj||d|�|jd|�y|jd|j|�y)ax
        Called by subclasses to continue to the stage of initialization where
        the socket connect attempt is made.

        @param whenDone: A 0-argument callable to invoke once the connection is
            set up.  This is L{None} if the connection could not be prepared
            due to a previous error.

        @param skt: The socket object to use to perform the connection.
        @type skt: C{socket._socketobject}

        @param error: The error to fail the connection with.

        @param reactor: The reactor to use for this client.
        @type reactor: L{twisted.internet.interfaces.IReactorTime}
        Nr)�_commonConnectionr�r��failIfNotConnected)rv�whenDonercrFr�s     r$�_finishInitz_BaseBaseClient._finishInit�sI��"��"�"�+�+�D�#�t�W�E����a��*����a��!8�!8�%�@r#c����jrc�jj�jd�}|j	�fd��|j�j�j�y�j
�j�y)a�
        Resolve the name that was passed to this L{_BaseBaseClient}, if
        necessary, and then move on to attempting the connection once an
        address has been determined.  (The connection will be attempted
        immediately within this function if either name resolution can be
        synchronous or the address was an IP address literal.)

        @note: You don't want to call this method from outside, as it won't do
            anything useful; it's just part of the connection bootstrapping
            process.  Also, although this method is on L{_BaseBaseClient} for
            historical reasons, it's not used anywhere except for L{Client}
            itself.

        @return: L{None}
        rc�*��|f�jddzSr�)r\)�nrvs �r$r�z0_BaseBaseClient.resolveAddress.<locals>.<lambda>�s���Q�D�4�9�9�Q�R�=�$8�r#N)�_requiresResolutionr��resolver\�addCallback�addCallbacks�_setRealAddressr�)rv�ds` r$�resolveAddressz_BaseBaseClient.resolveAddress�sc��� �#�#����$�$�T�Y�Y�q�\�2�A�
�M�M�8�9�
�N�N�4�/�/��1H�1H�I�� � ����+r#c��t|�dk(rYtj|tjtjz�d}t|gt
|dd�z�|_n||_|j�y)a�
        Set the resolved address of this L{_BaseBaseClient} and initiate the
        connection attempt.

        @param address: Depending on whether this is an IPv4 or IPv6 connection
            attempt, a 2-tuple of C{(host, port)} or a 4-tuple of C{(host,
            port, flow, scope)}.  At this point it is a fully resolved address,
            and the 'host' portion will always be an IP address, not a DNS
            name.
        rRrrSN)	rUrVrWrXrYrZr[�realAddress�	doConnect)rvrD�hostnames   r$r�z_BaseBaseClient._setRealAddress�sq���w�<�1���)�)���.�.��1F�1F�F����H� %�h�Z�$�w�q�r�{�2C�%C�D�D��&�D�����r#c�0�|js|jst|d�sy|j�	|j	d�|j�|jjtj|��|`y#t$rY�<wxYw)z�
        Generic method called when the attempts to connect failed. It basically
        cleans everything it can: call connectionFailed, stop read and write,
        delete socket related members.
        �	connectorNT)�	connectedr�r��_stopReadingAndWritingrx�_collectSocketDetails�AttributeErrorr��connectionFailedrLr�)rvr�s  r$r�z"_BaseBaseClient.failIfNotConnected�s����>�>�T�.�.�g�d�K�6P���#�#�%�	)����d�#�
�&�&�(����'�'�����(<�=��N���	��	�s�B	�		B�Bc�J�|jtj��y)z�
        If a connection attempt is still outstanding (i.e.  no connection is
        yet established), immediately stop attempting to connect.
        N)r�rF�	UserErrorr�s r$�stopConnectingz_BaseBaseClient.stopConnecting�s��
	
������ 1�2r#c���|js&|jtj|���y|jj||�|jj|�y)a�
        Invoked by lower-level logic when it's time to clean the socket up.
        Depending on the state of the connection, either inform the attached
        L{Connector} that the connection attempt has failed, or inform the
        connected L{IProtocol} that the established connection has been lost.

        @param reason: the reason that the connection was terminated
        @type reason: L{Failure}
        ��stringN)r�r�rF�ConnectErrorr�r�r��rvr�s  r$r�z_BaseBaseClient.connectionLost�sL���~�~��#�#�E�$6�$6�f�$E�F��"�"�1�1�$��?��N�N�)�)�&�1r#N)rrr ryrV�AF_INET�
addressFamily�SOCK_STREAM�
socketTyper�r�r�r�r�r�r"r#r$r�r�]s=��1�f�N�N�M��#�#�J�A�.,�.�*�&3�2r#r�c�6�eZdZdZeZeZd�Zd�Zd�Z	d�Z
d�Zy)�
BaseClienta�
    A base class for client TCP (and similar) sockets.

    @ivar realAddress: The address object that will be used for socket.connect;
        this address is an address tuple (the number of elements dependent upon
        the address family) which does not contain any names which need to be
        resolved.
    @type realAddress: C{tuple}

    @ivar _base: L{Connection}, which is the base class of this class which has
        all of the useful file descriptor methods.  This is used by
        L{_TLSServerMixin} to call the right methods to directly manipulate the
        transport, as is necessary for writing TLS-encrypted bytes (whereas
        those methods on L{Server} will go through another layer of TLS if it
        has been enabled).
    c�^�t|d�r!|j�|j�yy)z�
        Implement the POSIX-ish (i.e.
        L{twisted.internet.interfaces.IReactorFDSet}) method of detaching this
        socket from the reactor for L{_BaseBaseClient}.
        r�N)r�r�r�r�s r$r�z!BaseClient._stopReadingAndWritings+���4��#���������$r#c��|`|`y)zn
        Clean up references to the socket and its file descriptor.

        @see: L{_BaseBaseClient}
        N)rVr�r�s r$r�z BaseClient._collectSocketDetails"s
��
�K��r#c���tj|j|j�}|jd�t	j
|j
��|S)zc(internal) Create a non-blocking socket using
        self.addressFamily, self.socketType.
        r)rVr�r�r�rG�_setCloseOnExecr��rv�ss  r$�createInternetSocketzBaseClient.createInternetSocket*sC��
�M�M�$�,�,�d�o�o�>��	�
�
�a��
���a�h�h�j�)��r#c�8�|j|_|j|_t|d�sy|jjtjtj�}|r0|jtj|t|�f��y	|jj|j�}|r�|t k(rnv|t"t$t&fvs|t(k(r*t*dk(r!|j-�|j/�y|jtj|t|�f��y|`|`|j1�|j3�|j5�y#t$r}|jd}Yd}~��d}~wwxYw)z�
        Initiate the outgoing connection attempt.

        @note: Applications do not need to call this method; it will be invoked
            internally as part of L{IReactorTCP.connectTCP}.
        r�Nrr+)r�r�r�r�rVr�rp�SO_ERRORr�rF�getConnectErrorrA�
connect_exr�rtr�r:r7r8r9r6r�startReading�startWritingr�r��_connectDone)rvr��
connectResultr�s    r$r�zBaseClient.doConnect3sU���~�~����n�n����t�[�)�
��k�k�$�$�V�%6�%6����H����#�#�E�$9�$9�3���
�:N�$O�P��	'� �K�K�2�2�4�3C�3C�D�M����'�� �K��h�#G�G���'�L�G�,C��!�!�#��!�!�#���'�'��)�)�=�(�=�:Q�*R�S���
�L��K��������������5�	'��G�G�A�J�M��	'�s�%E7�7	F�F�Fc�f�|jj|j��|_d|_|j|j�}d|z|_|j� t�|_|j�y|j�|jj|�y)a�
        This is a hook for when a connection attempt has succeeded.

        Here, we build the protocol from the
        L{twisted.internet.protocol.ClientFactory} that was passed in, compute
        a log string, begin reading so as to send traffic to the newly built
        protocol, and finally hook up the protocol itself.

        This hook is overridden by L{ssl.Client} to initiate the TLS protocol.
        rSz	%s,clientN)r��
buildProtocol�getPeerr�r��
_getLogPrefixr�rJ�loseConnectionr
�makeConnection)rvr�s  r$rzBaseClient._connectDoneks������4�4�T�\�\�^�D��
�����&�&�t�}�}�5�	�!�I�-����=�=� �%�J�D�M����!������M�M�(�(��.r#N)rrr ryr��_baser�r�r�rr�rr"r#r$rrs.���"
�E�"��	�%��6�p/r#rc�J�tj||dddt�ddS)av
    Resolve an IPv6 literal into an IPv6 address.

    This is necessary to resolve any embedded scope identifiers to the relevant
    C{sin6_scope_id} for use with C{socket.connect()}, C{socket.listen()}, or
    C{socket.bind()}; see U{RFC 3493 <https://tools.ietf.org/html/rfc3493>} for
    more information.

    @param ip: An IPv6 address literal.
    @type ip: C{str}

    @param port: A port number.
    @type port: C{int}

    @return: a 4-tuple of C{(host, port, flow, scope)}, suitable for use as an
        IPv6 address.

    @raise socket.gaierror: if either the IP or port is not numeric as it
        should be.
    rrR)rV�getaddrinfo�
_NUMERIC_ONLY)�ip�ports  r$�_resolveIPv6r�s)��*���b�$��1�a��?��B�1�E�Er#c�D�eZdZdZej
Zdd�Zd�Zd�Z	dd�Z
y)	�_BaseTCPClienta�
    Code shared with other (non-POSIX) reactors for management of outgoing TCP
    connections (both TCPv4 and TCPv6).

    @note: In order to be functional, this class must be mixed into the same
        hierarchy as L{_BaseBaseClient}.  It would subclass L{_BaseBaseClient}
        directly, but the class hierarchy here is divided in strange ways out
        of the need to share code along multiple axes; specifically, with the
        IOCP reactor and also with UNIX clients in other reactors.

    @ivar _addressType: The Twisted _IPAddress implementation for this client
    @type _addressType: L{IPv4Address} or L{IPv6Address}

    @ivar connector: The L{Connector} which is driving this L{_BaseTCPClient}'s
        connection attempt.

    @ivar addr: The address that this socket will be connecting to.
    @type addr: If IPv4, a 2-C{tuple} of C{(str host, int port)}.  If IPv6, a
        4-C{tuple} of (C{str host, int port, int ignored, int scope}).

    @ivar createInternetSocket: Subclasses must implement this as a method to
        create a python socket object of the appropriate address family and
        socket type.
    @type createInternetSocket: 0-argument callable returning
        C{socket._socketobject}.
    Nc��||_||f|_|j}d}d}tj|�rd|_n_tj|�rCd|_t||�|_tj|_
tj|_
nd|_	|j�}|r7|�5	tj|d�r	t|�}
n|}
|j'|
�|j)||||�y#t$r<}	t!j"|	j$d|	j$d�}d}Yd}	~	��d}	~	wwxYw#t$r<}	t!j"|	j$d|	j$d�}d}Yd}	~	��d}	~	wwxYw)NFTrrS)r�r\r�rC�isIPAddressr��
isIPv6AddressrrV�AF_INET6r�rD�IPv6Address�_addressTyperrtrF�ConnectBindErrorr��bindr�)rvr]r�bindAddressr�r�r�r�rcr��bindinfos           r$r�z_BaseTCPClient.__init__�s[��"����4�L��	��&�&����������%�',�D�$�
�
#�
#�D�
)�',�D�$�$�T�4�0�D�I�!'���D�� '� 3� 3�D��'+�D�$�	��+�+�-�C���/�
 ��)�)�+�a�.�9�+�[�9�H�*�H�����"�	
����3��W�5���	��(�(������R�W�W�Q�Z�@�C��H��	���
 ��,�,�R�W�W�Q�Z������D�����
 �s0�C<�34E�<	E�2D<�<E�	F	�
2F�F	c�N�|jdgt|j����S)z~
        Returns an L{IPv4Address} or L{IPv6Address}.

        This indicates the address from which I am connecting.
        �TCP)r%rhrVr�s r$�getHostz_BaseTCPClient.getHost�s%��!�t� � ��C��d�k�k�)B�C�Cr#c�<�|jdg|j���S)zz
        Returns an L{IPv4Address} or L{IPv6Address}.

        This indicates the address that I am connected to.
        r+)r%r�r�s r$rz_BaseTCPClient.getPeer�s"��!�t� � ��:��)9�)9�:�:r#c�Z�d|j�d|j�dt|�d�d�}|S)N�<z to z at �x�>)�	__class__r\�idrs  r$�__repr__z_BaseTCPClient.__repr__�s0�������t�D�I�I�;�d�2�d�8�A�,�a�@���r#r~��return�str)rrr ryrD�IPv4Addressr%r�r,rr4r"r#r$rr�s*���6�&�&�L�!6�FD�;�r#rc��eZdZdZy)�Clientz�
    A transport for a TCP protocol; either TCPv4 or TCPv6.

    Do not create these directly; use L{IReactorTCP.connectTCP}.
    N)rrr ryr"r#r$r:r:�s��r#r:c��eZdZUdZeZejZde	d<														d
d�Z
dd�Zed��Z
d�Zd�Zy	)�Servera<
    Serverside socket-stream connection class.

    This is a serverside network connection transport; a socket which came from
    an accept() on a server.

    @ivar _base: L{Connection}, which is the base class of this class which has
        all of the useful file descriptor methods.  This is used by
        L{_TLSServerMixin} to call the right methods to directly manipulate the
        transport, as is necessary for writing TLS-encrypted bytes (whereas
        those methods on L{Server} will go through another layer of TLS if it
        has been enabled).
    z;Union[type[address.IPv4Address], type[address.IPv6Address]]r%c��tj||||�t|�dk7rtj|_||_||_||_|d|_	|j|j�}|�d|�d|j��|_|j�Tdj|jjj|j|jj �|_|j%�d|_y)a

        Server(sock, protocol, client, server, sessionno)

        Initialize it with a socket, a protocol, a descriptor for my peer (a
        tuple of host, port describing the other end of the connection), an
        instance of Port, and a session number.
        rTr�,N�<{} #{} on {}>rS)r�r�rUrDr$r%�server�client�	sessionnor�rr�r�r�r2r�_realPortNumber�repstrr
r�)rv�sockr�rAr@rBr�r�s        r$r�zServer.__init__s��� 	���D�$��'�:��v�;�!�� '� 3� 3�D��������"����q�	��
��&�&�t�}�}�5�	�"��1�Y�K�q�����@����;�;�"�/�6�6��
�
�'�'�0�0�������+�+� �D�K�
	
������r#c��|jS)z=
        A string representation of this connection.
        )rDr�s r$r4zServer.__repr__9s���{�{�r#c��tj}|tjk(rtj}tj
||tj�}t|�}|dg|���}|j�d}	|j|�}
|
�|j�y|||
|d|d|�}dj|jjj|j|	�|_|
j#|�|S)a�
        Create a new L{Server} based on an existing connected I{SOCK_STREAM}
        socket.

        Arguments are the same as to L{Server.__init__}, except where noted.

        @param fileDescriptor: An integer file descriptor associated with a
            connected socket.  The socket must be in non-blocking mode.  Any
            additional attributes desired, such as I{FD_CLOEXEC}, must also be
            set already.

        @param addressFamily: The address family (sometimes called I{domain})
            of the existing socket.  For example, L{socket.AF_INET}.

        @return: A new instance of C{cls} wrapping the socket given by
            C{fileDescriptor}.
        r+rSNr?)rDr8rVr#r$�fromfdr�rdrgrrur�r�r2rrBrDr)�cls�fileDescriptorr��factoryr��addressTypercr\�protocolAddr�	localPortr�rvs            r$�_fromConnectedSocketzServer._fromConnectedSocket?s���&�)�)���F�O�O�+�!�-�-�K��m�m�N�M�6�;M�;M�N���C� ��"�5�0�4�0���O�O�%�a�(�	��(�(��6�����I�I�K���3��$��d�1�g�w�?��&�-�-��M�M�#�#�,�,��N�N��
���
	����%��r#c�R�t|j�}|jdg|���S)zl
        Returns an L{IPv4Address} or L{IPv6Address}.

        This indicates the server's address.
        r+�rhrVr%�rvr\s  r$r,zServer.getHosths*���D�K�K�(�� �t� � ��.��.�.r#c�<�|jdg|j���S)zl
        Returns an L{IPv4Address} or L{IPv6Address}.

        This indicates the client's address.
        r+)r%rAr�s r$rzServer.getPeerqs ��!�t� � ��5����5�5r#N)rEz
socket.socketr�r
rAztuple[object, ...]r@�PortrB�intr�rr6�Noner5)rrr ryr�rrDr8r%�__annotations__r�r4�classmethodrOr,rr"r#r$r<r<s����
�E�	������!��!��!�#�	!�
�!��
!��!�
�!�F��&��&�P/�6r#r<c�(�eZdZdZd�Zd�Zd�Zd�Zy)�_IFileDescriptorReservationaT
    An open file that represents an emergency reservation in the
    process' file descriptor table.  If L{Port} encounters C{EMFILE}
    on C{accept(2)}, it can close this file descriptor, retry the
    C{accept} so that the incoming connection occupies this file
    descriptor's space, and then close that connection and reopen this
    one.

    Calling L{_IFileDescriptorReservation.reserve} attempts to open
    the reserve file descriptor if it is not already open.
    L{_IFileDescriptorReservation.available} returns L{True} if the
    underlying file is open and its descriptor claimed.

    L{_IFileDescriptorReservation} instances are context managers;
    entering them releases the underlying file descriptor, while
    exiting them attempts to reacquire it.  The block can take
    advantage of the free slot in the process' file descriptor table
    accept and close a client connection.

    Because another thread might open a file descriptor between the
    time the context manager is entered and the time C{accept} is
    called, opening the reserve descriptor is best-effort only.
    c��y)z�
        Is the reservation available?

        @return: L{True} if the reserved file descriptor is open and
            can thus be closed to allow a new file to be opened in its
            place; L{False} if it is not open.
        Nr"r"r#r$�	availablez%_IFileDescriptorReservation.available�r�r#c��y)a!
        Attempt to open the reserved file descriptor; if this fails
        because of C{EMFILE}, internal state is reset so that another
        reservation attempt can be made.

        @raises Exception: Any exception except an L{OSError} whose
            errno is L{EMFILE}.
        Nr"r"r#r$�reservez#_IFileDescriptorReservation.reserve�r�r#c��y)z}
        Release the underlying file descriptor so that code within the
        context manager can open a new file.
        Nr"r"r#r$�	__enter__z%_IFileDescriptorReservation.__enter__�r�r#c��y)z�
        Attempt to re-open the reserved file descriptor.  See
        L{reserve} for caveats.

        @param excType: See L{object.__exit__}
        @param excValue: See L{object.__exit__}
        @param traceback: See L{object.__exit__}
        Nr")�excType�excValue�	tracebacks   r$�__exit__z$_IFileDescriptorReservation.__exit__�r�r#N�rrr ryr\r^r`rer"r#r$rZrZzs���0���r#rZc��eZdZdd�Zy)�	_HasClosec��yr~r"r�s r$ruz_HasClose.close�s��r#N)r6�object)rrr rur"r#r$rhrh�s��r#rhT)�auto_attribsc�~�eZdZUdZe�Zded<ded<ejdd��Z	d	ed
<d�Z
d�Zd
�Zd�Z
y)�_FileDescriptorReservationa	
    L{_IFileDescriptorReservation} implementation.

    @ivar fileFactory: A factory that will be called to reserve a
        file descriptor.
    @type fileFactory: A L{callable} that accepts no arguments and
        returns an object with a C{close} method.
    zClassVar[Logger]�_logzCallable[[], _HasClose]�_fileFactoryFN)�init�defaultzOptional[_HasClose]�_fileDescriptorc��|jduS)z�
        See L{_IFileDescriptorReservation.available}.

        @return: L{True} if the reserved file descriptor is open and
            can thus be closed to allow a new file to be opened in its
            place; L{False} if it is not open.
        N)rrr�s r$r\z$_FileDescriptorReservation.available�s���#�#�4�/�/r#c���|j�	|j�}||_yy#t$r:}|jtk(r|j
j
d�n�Yd}~yd}~wwxYw)z=
        See L{_IFileDescriptorReservation.reserve}.
        Nz2Could not reserve EMFILE recovery file descriptor.)rrrort�errnor<rnrL)rvrJ�es   r$r^z"_FileDescriptorReservation.reserve�so�����'�

6�!%�!2�!2�!4��(6��$�(���
��7�7�f�$��I�I�%�%�L���	��
�s�'�	A*�0A%�%A*c�t�|j�td��|jj�d|_y)z?
        See L{_IFileDescriptorReservation.__enter__}.
        Nz5No file reserved.  Have you called my reserve method?)rr�RuntimeErrorrur�s r$r`z$_FileDescriptorReservation.__enter__�s6�����'��V�W�W����"�"�$�#��r#c�z�	|j�y#t$r|jjd�YywxYw)z>
        See L{_IFileDescriptorReservation.__exit__}.
        z5Could not re-reserve EMFILE recovery file descriptor.N)r^�	ExceptionrnrL�rvrbrcrds    r$rez#_FileDescriptorReservation.__exit__�s5��	W��L�L�N���	W��I�I���U�V�	W�s��$:�:)rrr ryrrnrW�attr�ibrrr\r^r`rer"r#r$rmrm�sI���$�X�D�
�%�)�)�+2�4�7�7��t�+L�O�(�L�0�6�"$�Wr#rmc�(�eZdZdZd�Zd�Zd�Zd�Zy)�_NullFileDescriptorReservationzB
    A null implementation of L{_IFileDescriptorReservation}.
    c��y)z�
        The reserved file is never available.  See
        L{_IFileDescriptorReservation.available}.

        @return: L{False}
        Fr"r�s r$r\z(_NullFileDescriptorReservation.availables��r#c��y)zJ
        Do nothing.  See L{_IFileDescriptorReservation.reserve}.
        Nr"r�s r$r^z&_NullFileDescriptorReservation.reserve
r�r#c��y)ze
        Do nothing. See L{_IFileDescriptorReservation.__enter__}

        @return: L{False}
        Nr"r�s r$r`z(_NullFileDescriptorReservation.__enter__r�r#c��y)z�
        Do nothing.  See L{_IFileDescriptorReservation.__exit__}.

        @param excType: See L{object.__exit__}
        @param excValue: See L{object.__exit__}
        @param traceback: See L{object.__exit__}
        Nr"r{s    r$rez'_NullFileDescriptorReservation.__exit__r�r#Nrfr"r#r$rr�s�����
�r#rc�4�ttj�Sr~)�open�os�devnullr"r#r$r�r�>s��T�"�*�*�5E�r#c��eZdZUdZded<ded<ejeje���Z	ded<d	�Z
d
�Zy)�_BuffersLogsa@
    A context manager that buffers any log events until after its
    block exits.

    @ivar _namespace: The namespace of the buffered events.
    @type _namespace: L{str}.

    @ivar _observer: The observer to which buffered log events will be
        written
    @type _observer: L{twisted.logger.ILogObserver}.
    r7�
_namespacer�	_observer)rqzList[LogEvent]�_logsc�X�t|j|jj��S)z
        Enter a log buffering context.

        @return: A logger that buffers log events.
        @rtype: L{Logger}.
        )�	namespace�observer)rr�r��appendr�s r$r`z_BuffersLogs.__enter__es������$�*�*�:K�:K�L�Lr#c�H�|jD]}|j|��y)z�
        Exit a log buffering context and log all buffered events to
        the provided observer.

        @param excType: See L{object.__exit__}
        @param excValue: See L{object.__exit__}
        @param traceback: See L{object.__exit__}
        N)r�r�)rvrcrbrd�events     r$rez_BuffersLogs.__exit__ns#���Z�Z�	"�E��N�N�5�!�	"r#N)rrr ryrWr|r}�Factoryr[r�r`rer"r#r$r�r�Ss?��
��O���#�D�G�G�L�D�L�L��,>�?�E�>�?�M�
"r#r�c	#�K�|D]}	|j�\}}||f���y#t$�r%}|jdttfvrYd}~y|jdt
k(rYd}~�f|jdtk(r�|j�r{|jd�|5t||||�}|D](\}	}
|	j�|jd|
���*|jd�ddd�n#1swYnxYwYd}~y|jdtvr-|jdt|jd��Yd}~y�d}~wwxYw�w)	a�
    Return a generator that yields client sockets from the provided
    listening socket until there are none left or an unrecoverable
    error occurs.

    @param logger: A logger to which C{accept}-related events will be
        logged.  This should not log to arbitrary observers that might
        open a file descriptor to avoid claiming the C{EMFILE} file
        descriptor on UNIX-like systems.
    @type logger: L{Logger}

    @param accepts: An iterable iterated over to limit the number
        consecutive C{accept}s.
    @type accepts: An iterable.

    @param listener: The listening socket.
    @type listener: L{socket.socket}

    @param reservedFD: A reserved file descriptor that can be used to
        recover from C{EMFILE} on UNIX-like systems.
    @type reservedFD: L{_IFileDescriptorReservation}

    @return: A generator that yields C{(socket, addr)} tuples from
        L{socket.socket.accept}
    rNz7EMFILE encountered; releasing reserved file descriptor.z-EMFILE recovery: Closed socket from {address})rDz-Re-reserving EMFILE recovery file descriptor.z/Could not accept new connection ({acceptError}))�acceptError)
�acceptrtr�r7r?r5r<r\�info�_acceptru�_ACCEPT_ERRORSrB)�logger�accepts�listener�
reservedFD�_rArDrv�clientsToClose�
clientToClose�
closedAddresss           r$r�r�{sZ����4�,"��+	"�&�o�o�/�O�F�G�T�'�/�!�Y,"���'	��v�v�a�y�[�&�1�1�������e�#�������f�$��)=�)=�)?����P��
 �Q�%,�V�W�h�
�%S�N�8F��4�
�}�%�+�+�-����N�$1�$����K�K� O�P�Q�Q�Q��������n�,����E� )�!�&�&��)� 4������O'	�sm�E�%�	E�
E�E�
E�E�&E�+9E�$A
C:�1	E�:D�?E�E�<E�E�E�E�Ec� �eZdZUdZej
ZeZdZ	dZ
dZdZdZ
ded<dZej Zej&Ze�Zdd	�Zed
��Zdd�Zd�Zd
�Zd�Zd�Zej@e!jD�fd�Z#e#Z$d�Z%d�Z&d�Z'd�Z(y)rTa.
    A TCP server port, listening for connections.

    When a connection is accepted, this will call a factory's buildProtocol
    with the incoming address as an argument, according to the specification
    described in L{twisted.internet.interfaces.IProtocolFactory}.

    If you wish to change the sort of transport that will be used, the
    C{transport} attribute will be called with the signature expected for
    C{Server.__init__}, so it can be replaced.

    @ivar deferred: a deferred created when L{stopListening} is called, and
        that will fire when connection is lost. This is not to be used it
        directly: prefer the deferred returned by L{stopListening} instead.
    @type deferred: L{defer.Deferred}

    @ivar disconnecting: flag indicating that the L{stopListening} method has
        been called and that no connections should be accepted anymore.
    @type disconnecting: C{bool}

    @ivar connected: flag set once the listen has successfully been called on
        the socket.
    @type connected: C{bool}

    @ivar _type: A string describing the connections which will be created by
        this port.  Normally this is C{"TCP"}, since this is a TCP port, but
        when the TLS implementation re-uses this class it overrides the value
        with C{"TLS"}.  Only used for logging.

    @ivar _preexistingSocket: If not L{None}, a L{socket.socket} instance which
        was created and initialized outside of the reactor and will be used to
        listen for connections (instead of a new socket being created by this
        L{Port}).
    r��2r+Nz
Optional[int]rCc��tjj||��||_||_||_t
j|�r*tj|_
tj|_
||_y)z,Initialize with a numeric port to listen on.r�N)rE�BasePortr�rrK�backlogrCr"rVr#r�rDr$r%�	interface)rvrrKr�r�r�s      r$r�z
Port.__init__�s]���
�
���t�W��5���	��������!�!�)�,�!'���D�� '� 3� 3�D��"��r#c��tj|||j�}t|�d}|d|d||�}||_|S)a}
        Create a new L{Port} based on an existing listening I{SOCK_STREAM}
        socket.

        Arguments are the same as to L{Port.__init__}, except where noted.

        @param fd: An integer file descriptor associated with a listening
            socket.  The socket must be in non-blocking mode.  Any additional
            attributes desired, such as I{FD_CLOEXEC}, must also be set already.

        @param addressFamily: The address family (sometimes called I{domain}) of
            the existing socket.  For example, L{socket.AF_INET}.

        @return: A new instance of C{cls} wrapping the socket given by C{fd}.
        rN)rVrHr�rh�_preexistingSocket)rIr��fdr�rKrr�rvs        r$�_fromListeningDescriptorzPort._fromListeningDescriptor	sH��"�}�}�R�����?�� ��&�q�)�	��4��$�	�7�;��"&����r#c���|j�;dj|j|jj|j�Sdj|j|jj�S)Nz<{} of {} on {}>z<{} of {} (not listening)>)rCr�r2rKr�s r$r4z
Port.__repr__ sg�����+�%�,�,�������&�&��$�$��
�0�6�6�������&�&��
r#c���tjj|�}tdk(rBtj
dk7r/|j
tjtjd�|S)N�posix�cygwinrS)
rEr�rr�sys�platformrorVrp�SO_REUSEADDRrs  r$rzPort.createInternetSocket-sJ���M�M�.�.�t�4���7�"�s�|�|�x�'?�
�L�L��*�*�F�,?�,?��C��r#c�b�tj�|j��	|j�}|jt
jk(r!t|j|j�}n|j|jf}|j|�|j|j�n|j}d|_d|_|j!�d|_t%j&|j)|j*��d|j"���|j*j-�d|_||_|j
j0|_d|_|j5�y#t$r&}t|j|j|��d}~wwxYw)z�Create and bind my socket, and begin listening on it.

        This is called on unserialization, and must be called after creating a
        server to begin listening on the specified port.
        NFrSz
 starting on T�d)�_reservedFDr^r�rr�rVr#rr�rr'rtrI�listenr�rmrgrCrM�msgrrK�doStartr�r��
numberAcceptsr
)rvrcr\�les    r$�startListeningzPort.startListening3sT��	�����"�"�*�
G��/�/�1���%�%����8�'�����	�	�B�D� �N�N�D�I�I�6�D������
�J�J�t�|�|�$��)�)�C�&*�D�#�#(�D� � #���0��3�������!�!�$�,�,�/��1E�1E�
G�	
�	
�������������k�k�(�(��� ��������7�
G�'�����	�	�2�F�F��
G�s�A7E?�?	F.�!F)�)F.c�(�|jdg|���S)Nr+)r%)rvrDs  r$�
_buildAddrzPort._buildAddr`s�� �t� � ��1��1�1r#c
��	tdk(r
|j}nd}t|jj|jj
�5}d}t
|t|�|jt�}t|d�D�]\}\}}tj|j��t|�dk(rStj|tj tj"z�}t%|dgt'|dd�z�}|j(j+|j-|��}|�|j/���|j0}	|	dz|_|j3|||||	|j4�}
|j7|
���	ddd�|jk(r|xjdz
c_yt9d|�|_y#1swY�@xYw#t:$rt=j>�YywxYw)z�
        Called when my socket is ready for reading.

        This accepts a connection and calls self.protocol() to handle the
        wire-level protocol.
        r�rSrrRN�) rr�r��_loggerr�r�r��rangerVr��	enumeraterGrr�rUrWrXrYrZr[rKrr�rurB�	transportr�r�maxr�rM�deferr)rv�
numAccepts�bufferingLogger�accepted�clientsrcr\r]r�rr�s           r$r�zPort.doReadcs���8	��w�&�!�/�/�
��
�����&�&����(=�(=��
7� ���!�#�U�:�%6����[���.7�w��-B�7�)�H�k�s�D��)�)�#�*�*�,�7��4�y�A�~� &�1�1� �&�"7�"7�&�:O�:O�"O� �� %�d�1�g�Y��d�1�2�h��%?�@��#�|�|�9�9�$�/�/�$�:O�P�H��'��	�	�� ����A�%&��U�D�N� $����X�t�T�1�d�l�l�!�I��+�+�I�6�)7�
7�D�4�-�-�-��"�"�b�(�"�&)��H�%5��"�O
7�
7��P�	�
�J�J�L�	�s1�AG#�E	G�,G#�G#�G �G#�#H�Hc��d|_|j�|jr3t|jd|j
|�|_|jSy)a
        Stop accepting connections on this port.

        This will shut down the socket and call self.connectionLost().  It
        returns a deferred which will fire successfully when the port is
        actually closed, or with a failure if an error occurs shutting down.
        TrN)�
disconnectingr�r�rKr�r��deferred)rv�connDones  r$rzPort.loseConnection�sJ��"��������>�>�&�t�|�|�Q��8K�8K�X�V�D�M��=�=� �r#c�d�tjd|j�d|j�d��y)z.
        Log message for closing port
        �(z Port z Closed)N)rMr��_typerCr�s r$�_logConnectionLostMsgzPort._logConnectionLostMsg�s*��	���!�D�J�J�<�v�d�&:�&:�%;�8�D�Er#c��|j�d|_tjj	||�d|_|j
d�|`|`	|jj�d|_y#d|_wxYw)z'
        Cleans up the socket.
        NFT)r�rCrEr�r�r�rxrVr�rK�doStopr�r�s  r$r�zPort.connectionLost�sq��	
�"�"�$�#����
�
�$�$�T�6�2�������$���K��K�	'��L�L���!�!&�D����D��s�A7�7	Bc�T�tj|jj�S)z9Returns the name of my class, to prefix log entries with.)rN�qualrKr2r�s r$r�zPort.logPrefix�s���|�|�D�L�L�2�2�3�3r#c�R�t|j�}|jdg|���S)zs
        Return an L{IPv4Address} or L{IPv6Address} indicating the listening
        address of this port.
        r+rQrRs  r$r,zPort.getHost�s*��
�D�K�K�(�� �t� � ��.��.�.r#)r�r�Nr5))rrr ryrVr�r�r<r�rBr�r�r�rCrWr�r�r�rDr8r%rr�r�rXr�r4rr�r�r�rLr�rHr�r�
stopListeningr�r�r�r,r"r#r$rTrT�s���!�F�#�#�J��I��I��I��G��E�&*�O�]�)����N�N�M��&�&�L��h�G�	#�����,��+�Z2�?�B'6�g�o�o�d�6J�6J�&K�!�#�M�F�'�$4�/r#rTc�<�eZdZdZej
Zdd�Zd�Zd�Z	y)�	Connectora6
    A L{Connector} provides of L{twisted.internet.interfaces.IConnector} for
    all POSIX-style reactors.

    @ivar _addressType: the type returned by L{Connector.getDestination}.
        Either L{IPv4Address} or L{IPv6Address}, depending on the type of
        address.
    @type _addressType: C{type}
    Nc�p�t|t�r	tj|d�}||c|_|_tj|�rtj|_
||_tj j#||||�y#t$r!}tj|�d|�d����d}~wwxYw)N�tcpz (�)r�)�
isinstancer7rV�
getservbynamertrF�ServiceNameUnknownErrorr]rrCr"rDr$r%r(rE�
BaseConnectorr�)rvr]rrK�timeoutr(r�rvs        r$r�zConnector.__init__�s����d�C� �
N��+�+�D�%�8�� $�T���	�4�9��!�!�$�'� '� 3� 3�D��&������#�#�D�'�7�G�D��
�
N��3�3�a�S��4�(�!�;L�M�M��
N�s�B�	B5�B0�0B5c�p�t|j|j|j||j�S)z|
        Create a L{Client} bound to this L{Connector}.

        @return: a new L{Client}
        @rtype: L{Client}
        )r:r]rr(r�r�s r$�_makeTransportzConnector._makeTransport�s)���d�i�i����D�,<�,<�d�D�L�L�Q�Qr#c�P�|jd|j|j�S)zQ
        @see: L{twisted.internet.interfaces.IConnector.getDestination}.
        r+)r%r]rr�s r$�getDestinationzConnector.getDestination�s!��� � ���	�	�4�9�9�=�=r#r~)
rrr ryrDr8r%r�r�r�r"r#r$r�r��s%����&�&�L�
E�R�>r#r�)vry�
__future__rr�rVrrr��typingrrrrr�zope.interfacer	r
r|�twisted.internet.interfacesrrr
rrr�twisted.loggerrrr�twisted.pythonrr�twisted.python.compatr�twisted.python.runtimer�twisted.internet._newtlsrr&rrrr*r�ImportErrorrjr5rur,r9r-r8r.r6r/r:r0r<r1r;r2r7r=r>r?r3r@�twisted.python.win32r4rArB�twisted.internetrCrDrErFrGrH�twisted.internet.errorrI�twisted.internet.protocolrJ�twisted.internet.taskrKrLrMrN�twisted.python.utilrO�getattr�_AI_NUMERICSERVr^rdrhrjr{r�r�r�r�AI_NUMERICHOSTrrrr:r<rZrhrrmrr�r�r�r�r�rTr�r�r"r#r$�<module>r�s���
�#�	�
�
�
�<�<�1��
���:�9�.�/�/�
���
:��7��
�H�E�����X�F�
�X�F�
�F�3�<���!�!��������"���I�H�4�.�,�0�0�.��&�"2�A�6���(+�+� � �F
�
�8
�]�M�=�9�HP���0�0�-��HP�:�HP�Vb2�b2�JC/��/�:�C/�L�%�%��7�
�F�0S�S�l�^�Z��v6�_�j�v6�r:�)�:�z�����

�
(�)�����T��:W�:W��*�:W�z
�
(�)�!�!�*�!�~�7��0�2�K�,�-E�F�K�$�'�6�6�<�@������T��$"�$"��$"�NF"�R
�^��Q/�4�=�=�-�Q/��Q/�h&>��"�"�&>��W-�
��M���
�
�
�
�
�s�&J%�%%K�
K
¿Qué es la limpieza dental de perros? - Clínica veterinaria


Es la eliminación del sarro y la placa adherida a la superficie de los dientes mediante un equipo de ultrasonidos que garantiza la integridad de las piezas dentales a la vez que elimina en profundidad cualquier resto de suciedad.

A continuación se procede al pulido de los dientes mediante una fresa especial que elimina la placa bacteriana y devuelve a los dientes el aspecto sano que deben tener.

Una vez terminado todo el proceso, se mantiene al perro en observación hasta que se despierta de la anestesia, bajo la atenta supervisión de un veterinario.

¿Cada cuánto tiempo tengo que hacerle una limpieza dental a mi perro?

A partir de cierta edad, los perros pueden necesitar una limpieza dental anual o bianual. Depende de cada caso. En líneas generales, puede decirse que los perros de razas pequeñas suelen acumular más sarro y suelen necesitar una atención mayor en cuanto a higiene dental.


Riesgos de una mala higiene


Los riesgos más evidentes de una mala higiene dental en los perros son los siguientes:

  • Cuando la acumulación de sarro no se trata, se puede producir una inflamación y retracción de las encías que puede descalzar el diente y provocar caídas.
  • Mal aliento (halitosis).
  • Sarro perros
  • Puede ir a más
  • Las bacterias de la placa pueden trasladarse a través del torrente circulatorio a órganos vitales como el corazón ocasionando problemas de endocarditis en las válvulas. Las bacterias pueden incluso acantonarse en huesos (La osteomielitis es la infección ósea, tanto cortical como medular) provocando mucho dolor y una artritis séptica).

¿Cómo se forma el sarro?

El sarro es la calcificación de la placa dental. Los restos de alimentos, junto con las bacterias presentes en la boca, van a formar la placa bacteriana o placa dental. Si la placa no se retira, al mezclarse con la saliva y los minerales presentes en ella, reaccionará formando una costra. La placa se calcifica y se forma el sarro.

El sarro, cuando se forma, es de color blanquecino pero a medida que pasa el tiempo se va poniendo amarillo y luego marrón.

Síntomas de una pobre higiene dental
La señal más obvia de una mala salud dental canina es el mal aliento.

Sin embargo, a veces no es tan fácil de detectar
Y hay perros que no se dejan abrir la boca por su dueño. Por ejemplo…

Recientemente nos trajeron a la clínica a un perro que parpadeaba de un ojo y decía su dueño que le picaba un lado de la cara. Tenía molestias y dificultad para comer, lo que había llevado a sus dueños a comprarle comida blanda (que suele ser un poco más cara y llevar más contenido en grasa) durante medio año. Después de una exploración oftalmológica, nos dimos cuenta de que el ojo tenía una úlcera en la córnea probablemente de rascarse . Además, el canto lateral del ojo estaba inflamado. Tenía lo que en humanos llamamos flemón pero como era un perro de pelo largo, no se le notaba a simple vista. Al abrirle la boca nos llamó la atención el ver una muela llena de sarro. Le realizamos una radiografía y encontramos una fístula que llegaba hasta la parte inferior del ojo.

Le tuvimos que extraer la muela. Tras esto, el ojo se curó completamente con unos colirios y una lentilla protectora de úlcera. Afortunadamente, la úlcera no profundizó y no perforó el ojo. Ahora el perro come perfectamente a pesar de haber perdido una muela.

¿Cómo mantener la higiene dental de tu perro?
Hay varias maneras de prevenir problemas derivados de la salud dental de tu perro.

Limpiezas de dientes en casa
Es recomendable limpiar los dientes de tu perro semanal o diariamente si se puede. Existe una gran variedad de productos que se pueden utilizar:

Pastas de dientes.
Cepillos de dientes o dedales para el dedo índice, que hacen más fácil la limpieza.
Colutorios para echar en agua de bebida o directamente sobre el diente en líquido o en spray.

En la Clínica Tus Veterinarios enseñamos a nuestros clientes a tomar el hábito de limpiar los dientes de sus perros desde que son cachorros. Esto responde a nuestro compromiso con la prevención de enfermedades caninas.

Hoy en día tenemos muchos clientes que limpian los dientes todos los días a su mascota, y como resultado, se ahorran el dinero de hacer limpiezas dentales profesionales y consiguen una mejor salud de su perro.


Limpiezas dentales profesionales de perros y gatos

Recomendamos hacer una limpieza dental especializada anualmente. La realizamos con un aparato de ultrasonidos que utiliza agua para quitar el sarro. Después, procedemos a pulir los dientes con un cepillo de alta velocidad y una pasta especial. Hacemos esto para proteger el esmalte.

La frecuencia de limpiezas dentales necesaria varía mucho entre razas. En general, las razas grandes tienen buena calidad de esmalte, por lo que no necesitan hacerlo tan a menudo e incluso pueden pasarse la vida sin requerir una limpieza. Sin embargo, razas pequeñas como el Yorkshire o el Maltés, deben hacérselas todos los años desde cachorros si se quiere conservar sus piezas dentales.

Otro factor fundamental es la calidad del pienso. Algunas marcas han diseñado croquetas que limpian la superficie del diente y de la muela al masticarse.

Ultrasonido para perros

¿Se necesita anestesia para las limpiezas dentales de perros y gatos?

La limpieza dental en perros no es una técnica que pueda practicarse sin anestesia general , aunque hay veces que los propietarios no quieren anestesiar y si tiene poco sarro y el perro es muy bueno se puede intentar…… , pero no se va a poder pulir ni acceder a todas la zona de la boca …. Además los limpiadores dentales van a irrigar agua y hay riesgo de aspiración a vías respiratorias si no se realiza una anestesia correcta con intubación traqueal . En resumen , sin anestesia no se va hacer una correcta limpieza dental.

Tampoco sirve la sedación ya que necesitamos que el animal esté totalmente quieto, y el veterinario tenga un acceso completo a todas sus piezas dentales y encías.

Alimentos para la limpieza dental

Hay que tener cierto cuidado a la hora de comprar determinados alimentos porque no todos son saludables. Algunos tienen demasiado contenido graso, que en exceso puede causar problemas cardiovasculares y obesidad.

Los mejores alimentos para los dientes son aquellos que están elaborados por empresas farmacéuticas y llevan componentes químicos con tratamientos específicos para el diente del perro. Esto implica no solo limpieza a través de la acción mecánica de morder sino también un tratamiento antibacteriano para prevenir el sarro.

Conclusión

Si eres como la mayoría de dueños, por falta de tiempo , es probable que no estés prestando la suficiente atención a la limpieza dental de tu perro. Por eso te animamos a que comiences a limpiar los dientes de tu perro y consideres atender a su higiene bucal con frecuencia.

Estas simples medidas pueden conllevar a que tu perro tenga una vida más larga y mucho más saludable.

Si te resulta imposible introducir un cepillo de dientes a tu perro en la boca, pásate con él por clínica Tus Veterinarios y te explicamos cómo hacerlo.

Necesitas hacer una limpieza dental profesional a tu mascota?
Llámanos al 622575274 o contacta con nosotros

Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *

¡Hola!