%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/twisted/internet/iocpreactor/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/twisted/internet/iocpreactor/__pycache__/tcp.cpython-312.pyc

�

Ϫ�fkO���dZddlmZddlZddlZddlZddlmZmZm	Z	ddl
mZmZddl
mZmZmZmZmZddlmZmZddlmZmZdd	lmZdd
lmZmZddlm Z m!Z!m"Z"m#Z#m$Z$ddl%m&Z&dd
l'm(Z(ddl)m*Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1ddl2m3Z3m4Z4m5Z5	ddl6m7Z8e8Z9erddl;m<Z<e ejze"ej|iZ?ee&ej�ej��Gd�dej�e1e,��ZCe9�eeCej��Gd�de-e.eC�ZEGd�deC�ZFGd�de+�Z*eej��Gd�de1e��ZHy#e:$rdZ9Y��wxYw)z
TCP support for IOCP reactor
�)�annotationsN)�
TYPE_CHECKING�Optional�Union)�classImplements�implementer)�address�defer�error�
interfaces�main)�	_LogOwner�
isIPv6Address)�IPv4Address�IPv6Address)�	IProtocol)�abstract�iocpsupport)�ERROR_CONNECTION_REFUSED�ERROR_IO_PENDING�ERROR_NETWORK_UNREACHABLE�SO_UPDATE_ACCEPT_CONTEXT�SO_UPDATE_CONNECT_CONTEXT)�IReadWriteHandle)�Protocol)�	Connector�_AbortingMixin�_BaseBaseClient�_BaseTCPClient�_getsockname�_resolveIPv6�
_SocketCloser)�failure�log�reflect)�startTLS)�IOCPReactorc��eZdZdZdZdd�Zd�Zd�Zd�Zd�Z	d	�Z
d
�Zd�Zd�Z
d
�Zd�Zd�Zd�Ze�dd�Zd�Zd�Zdd�Zd�Zd�Zd�Zd�Zy)�
Connectionz�
    @ivar TLS: C{False} to indicate the connection is in normal TCP mode,
        C{True} to indicate that TLS has been started and that operations must
        be routed through the L{TLSMemoryBIOProtocol} instance.
    FNc��tjj||�||_|j|_||_y�N)r�
FileHandle�__init__�socket�fileno�
getFileHandle�protocol)�self�sock�proto�reactors    �B/usr/lib/python3/dist-packages/twisted/internet/iocpreactor/tcp.pyr-zConnection.__init__Fs2�����$�$�T�7�3����!�[�[�����
�c��|jSr+)r.�r2s r6�	getHandlezConnection.getHandleLs���{�{�r7c���t|t�rn3t|t�rt|�}ntdt	|�z��|j
j
|�y)z`
        @param rbuffer: Data received.
        @type rbuffer: L{bytes} or L{bytearray}
        z%data must be bytes or bytearray, not N)�
isinstance�bytes�	bytearray�	TypeError�typer1�dataReceived)r2�rbuffers  r6rAzConnection.dataReceivedOsK��
�g�u�%��
���
+��G�n�G��C�d�7�m�S�T�T��
�
�"�"�7�+r7c�L�tj|j�||�Sr+)�_iocp�recvr0)r2�bufflist�evts   r6�readFromHandlezConnection.readFromHandle^s���z�z�$�,�,�.��#�>�>r7c��t|�}tj|j�|d|jj�|�S)z�
        Send C{buff} to current file handle using C{_iocp.send}. The buffer
        sent is limited to a size of C{self.SEND_LIMIT}.
        r)�
memoryviewrD�sendr0�
SEND_LIMIT�tobytes)r2�buffrG�	writeViews    r6�
writeToHandlezConnection.writeToHandleasC��
�t�$�	��z�z���� �)�A����"@�"H�"H�"J�C�
�	
r7c�R�	|jjd�tj|j
d�}|r	|j
�yy#t$rY�@wxYw#t$r<tj�}tj�|j|�YywxYw)N�)
r.�shutdown�OSErrorr�IHalfCloseableProtocolr1�writeConnectionLost�
BaseExceptionr#�Failurer$�err�connectionLost)r2�p�fs   r6�_closeWriteConnectionz Connection._closeWriteConnectionks���	��K�K� � ��#�
�-�-�d�m�m�T�B���
'��%�%�'�
���	��	��!�
'��O�O�%�����	��#�#�A�&�
'�s$�A�A!�	A�A�!AB&�%B&c��tj|jd�}|r	|j�y|j|�y#t$r:tj�|jtj��YywxYwr+)
rrUr1�readConnectionLostrWr$rYrZr#rX)r2�reasonr[s   r6r_zConnection.readConnectionLostysk���-�-�d�m�m�T�B���
7��$�$�&�

����'��	!�
7����	��#�#�G�O�O�$5�6�
7�s�A�AB
�	B
c��|jrytjj||�|duxs |j	t
j�}|j|�|j}|`|`	|`
|j|�yr+)�disconnectedrr,rZ�checkr�ConnectionAborted�_closeSocketr1r.r0)r2r`�isCleanr1s    r6rZzConnection.connectionLost�sy���������*�*�4��8��D�.�M����U�5L�5L�(M�$M�����'�"��=�=���M��K�������'r7c��|jS)zN
        Return the prefix to log with when I own the logging thread.
        )�logstrr9s r6�	logPrefixzConnection.logPrefix�����{�{�r7c��t|jjtjtj��Sr+)�boolr.�
getsockopt�IPPROTO_TCP�TCP_NODELAYr9s r6�
getTcpNoDelayzConnection.getTcpNoDelay�s*���D�K�K�*�*�6�+=�+=�v�?Q�?Q�R�S�Sr7c�v�|jjtjtj|�yr+)r.�
setsockoptrnro�r2�enableds  r6�
setTcpNoDelayzConnection.setTcpNoDelay�s$�������v�1�1�6�3E�3E�w�Or7c��t|jjtjtj��Sr+)rlr.rm�
SOL_SOCKET�SO_KEEPALIVEr9s r6�getTcpKeepAlivezConnection.getTcpKeepAlive�s*���D�K�K�*�*�6�+<�+<�f�>Q�>Q�R�S�Sr7c�v�|jjtjtj|�yr+)r.rrrwrxrss  r6�setTcpKeepAlivezConnection.setTcpKeepAlive�s$�������v�0�0�&�2E�2E�w�Or7c�<�t|||tj�y)z9
            @see: L{ITLSTransport.startTLS}
            N)�	_startTLSrr,)r2�contextFactory�normals   r6r&zConnection.startTLS�s��
�d�N�F�H�4G�4G�Hr7c��|jry|jr|jj|�ytj
j||�y)z�
        Write some data, either directly to the underlying handle or, if TLS
        has been started, to the L{TLSMemoryBIOProtocol} for it to encrypt and
        send.

        @see: L{twisted.internet.interfaces.ITransport.write}
        N)rb�TLSr1�writerr,)r2�datas  r6r�zConnection.write�s?�������8�8��M�M����%����%�%�d�D�1r7c��|jry|jr|jj|�ytj
j||�y)z�
        Write some data, either directly to the underlying handle or, if TLS
        has been started, to the L{TLSMemoryBIOProtocol} for it to encrypt and
        send.

        @see: L{twisted.internet.interfaces.ITransport.writeSequence}
        N)rbr�r1�
writeSequencerr,)r2�iovecs  r6r�zConnection.writeSequence�s?�������8�8��M�M�'�'��.����-�-�d�E�:r7c���|jr5|jr(|js|jj	�yyyt
jj	||�y)z�
        Close the underlying handle or, if TLS has been started, first shut it
        down.

        @see: L{twisted.internet.interfaces.ITransport.loseConnection}
        N)r��	connected�
disconnectingr1�loseConnectionrr,)r2r`s  r6r�zConnection.loseConnection�sI���8�8��~�~�d�&8�&8��
�
�,�,�.�'9�~�
���.�.�t�V�<r7c��|jr|jj||�ytjj|||�y)zc
        Register a producer.

        If TLS is enabled, the TLS connection handles this.
        N)r�r1�registerProducerrr,)r2�producer�	streamings   r6r�zConnection.registerProducer�s9���8�8�

�M�M�*�*�8�Y�?����0�0��x��Kr7c��|jr|jj�ytjj|�y)ze
        Unregister a producer.

        If TLS is enabled, the TLS connection handles this.
        N)r�r1�unregisterProducerrr,r9s r6r�zConnection.unregisterProducer�s/���8�8��M�M�,�,�.����2�2�4�8r7c��yr+�r9s r6�getHostzConnection.getHost����r7c��yr+r�r9s r6�getPeerzConnection.getPeer�r�r7r+)T)�__name__�
__module__�__qualname__�__doc__r�r-r:rArHrPr]r_rZrirpruryr{r}r&r�r�r�r�r�r�r�r�r7r6r)r)<s�����C���
,�?�
�'�	(�
(��T�P�T�P���	I�
2�
;�=�
L�	9�
�
r7r)c�l�eZdZdZej
ZejZdZ	e
Zd�Zd�Z
d�Zd�Zd�Zd�Zy	)
�Clientz�
    @ivar _tlsClientDefault: Always C{True}, indicating that this is a client
        connection, and by default when TLS is negotiated this class will act as
        a TLS client.
    Tc�N�|�d}||_tj||||||�y)N)�r)r5rr-)r2�host�port�bindAddress�	connectorr5s      r6r-zClient.__init__	s,����!�K��������d�D�+�y�'�Rr7c�b�|jj|j|j�S)zd
        Create a socket registered with the IOCP reactor.

        @see: L{_BaseTCPClient}
        )r5�createSocket�
addressFamily�
socketTyper9s r6�createInternetSocketzClient.createInternetSockets%���|�|�(�(��);�);�T�_�_�M�Mr7c��|`|`y)z�
        Clean up potentially circular references to the socket and to its
        C{getFileHandle} method.

        @see: L{_BaseBaseClient}
        N)r.r0r9s r6�_collectSocketDetailszClient._collectSocketDetailss��
�K��+r7c�:�|jj|�y)z^
        Remove the active handle from the reactor.

        @see: L{_BaseBaseClient}
        N)r5�removeActiveHandler9s r6�_stopReadingAndWritingzClient._stopReadingAndWriting!s��	
���'�'��-r7c	���|r[tj||�}|jtj|t
jj|d�f��y|jjtjttjd|jj���|jj|j!��|_d|_|j'|j"�}|dz|_|j"� t+�|_|j-�y|j"j/|�|j1�y)Nz
Unknown error�PTz,client)�connectExErrors�get�failIfNotConnectedr�getConnectError�errno�	errorcoder.rrrwr�struct�packr/r��
buildProtocolr�r1r��
_getLogPrefixrhrr��makeConnection�startReading)r2�rcr�rGris     r6�	cbConnectzClient.cbConnect)s��
� �$�$�R��,�B��#�#��%�%�r�5�?�?�+>�+>�r�?�+S�&T�U�
�
�K�K�"�"��!�!�)����C����!3�!3�!5�6�
�
!�N�N�8�8�����H�D�M�!�D�N��*�*�4�=�=�9�I�#�i�/�D�K��}�}�$�!)�
��
��#�#�%��
�
�,�,�T�2��!�!�#r7c�j�t|d�sytjsJ�|jj	|�tj
|j|�}tj|jj�|j|�}|r|tk7r|j
|d|�yyy)Nr�r)�hasattrrD�have_connectexr5�addActiveHandle�Eventr��connectr.r/�realAddressr)r2rGr�s   r6�	doConnectzClient.doConnectGs����t�[�)�
��#�#�#�#����$�$�T�*��k�k�$�.�.�$�/��
�]�]�4�;�;�-�-�/��1A�1A�3�
G��
�"�(�(��N�N�2�q�#�&�)�2r7N)r�r�r�r�r.�AF_INETr��SOCK_STREAMr��_tlsClientDefaultr)�_commonConnectionr-r�r�r�r�r�r�r7r6r�r��sI����N�N�M��#�#�J���"��S�N�,�.�$�<'r7r�c�H�eZdZdZdZ												dd�Zd	d�Zd�Zd�Zy)
�ServeraV
    Serverside socket-stream connection class.

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

    @ivar _tlsClientDefault: Always C{False}, indicating that this is a server
        connection, and by default when TLS is negotiated this class will act as
        a TLS server.
    Fc��tj||||�||_||_||_|j|j�}|�d|�d|jj��|_dj|jjj|j|jj�|_
d|_|j�y)a

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

        Initialize me 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.
        �,z<{} #{} on {}>TN)r)r-�
serverAddr�
clientAddr�	sessionnor�r1r�rh�format�	__class__r�r��repstrr�r�)r2r3r1r�r�r�r5ris        r6r-zServer.__init__cs��� 	���D�$��'�:�$���$���"����&�&�t�}�}�5�	�"��1�Y�K�q����1E�1E�0F�G���+�2�2��M�M�#�#�,�,��N�N��O�O� � �
���
������r7c��|jS)z=
        A string representation of this connection.
        )r�r9s r6�__repr__zServer.__repr__�rjr7c��|jS)zW
        Returns an IPv4Address.

        This indicates the server's address.
        )r�r9s r6r�zServer.getHost�������r7c��|jS)zW
        Returns an IPv4Address.

        This indicates the client's address.
        )r�r9s r6r�zServer.getPeer�r�r7N)r3z
socket.socketr1rr��Union[IPv4Address, IPv6Address]r�r�r��intr5r'��return�str)	r�r�r�r�r�r-r�r�r�r�r7r6r�r�Us]��	��������4�	�
4���
���<��r7r�c��eZdZd�Zy)rc�p�t|j|j|j||j�Sr+)r�r�r�r�r5r9s r6�_makeTransportzConnector._makeTransport�s'���d�i�i����D�,<�,<�d�D�L�L�Q�Qr7N)r�r�r�r�r�r7r6rr�s��Rr7rc��eZdZUdZdZdZejZejZ
ejZ
dZdZded<dZdd�Zdd�Zd	�Zej,ej0�fd
�ZeZd�Zd�Zd
�Zd�Zd�Zd�Z d�Z!y)�PortFrNz
Optional[int]�_realPortNumber�TCPc��||_||_||_||_||_t|�r+tj|_tj|_yyr+)r��factory�backlog�	interfacer5rr.�AF_INET6r�r	r�_addressType)r2r�r�r�r�r5s      r6r-z
Port.__init__�sL����	�������"��������#�!'���D�� '� 3� 3�D��$r7c���|j�;dj|j|jj|j�Sdj|j|jj�S)Nz<{} of {} on {}>z<{} of {} (not listening)>)r�r�r�r�r9s r6r�z
Port.__repr__�sg�����+�%�,�,�������&�&��$�$��
�0�6�6�������&�&��
r7c���	|jj|j|j�}|jtj
k(r!t
|j|j�}n|j|jf}|j|�tj|j��|_|j#�d|_t'j(|j+|j,��d|j$���|j,j/�|j1|j2�d|_d|_|jj9|�||_|jj|_|j=�y#t$r0}tj|j|j|��d}~wwxYw)NrRz
 starting on TF)r5r�r�r�r.r�r!r�r��bindrTr�CannotListenErrorrD�
maxAddrLenr/�addrLen�getsocknamer�r$�msgr�r��doStart�listenr�r�rbr�r0�doAccept)r2�skt�addr�les    r6�startListeningzPort.startListening�s]��		I��,�,�+�+�D�,>�,>����P�C��!�!�V�_�_�4�#�D�N�N�D�I�I�>������	�	�2���H�H�T�N��'�'��
�
��5��� #���0��3�������!�!�$�,�,�/��1E�1E�
G�	
�
	
�������
�
�4�<�<� ����!������$�$�T�*����!�[�[�/�/����
�
���+�	I��)�)�$�.�.�$�)�)�R�H�H��	I�s�BF'�'	G �0+G�G c���d|_|jrLtj�|_|j
j
d|j|�|jSy)z�
        Stop accepting connections on this port.

        This will shut down my socket and call self.connectionLost().
        It returns a deferred which will fire successfully when the
        port is actually closed.
        TrN)r�r�r
�Deferred�deferredr5�	callLaterrZ)r2�connDones  r6r�zPort.loseConnection�sL��"����>�>�!�N�N�,�D�M��L�L�"�"�1�d�&9�&9�8�D��=�=� �r7c�d�tjd|j�d|j�d��y)z.
        Log message for closing port
        �(z Port z Closed)N)r$r��_typer�r9s r6�_logConnectionLostMsgzPort._logConnectionLostMsg�s*��	���!�D�J�J�<�v�d�&:�&:�%;�8�D�Er7c���|j�d|_d}t|d�r|j}|`d|_|j
j
|�d|_|jd�|`	|`
	|jj�d|_
|�|jd�yy#t$r0d|_
|�%|j!t#j$��Yy�wxYw)z'
        Cleans up the socket.
        Nr�TF)rr�r�r�rbr5r�r�rer.r0r��doStopr��callbackrW�errbackr#rX)r2r`�ds   r6rZzPort.connectionLost�s���	
�"�"�$�#������4��$��
�
�A��
� ������'�'��-�������$���K���	!��L�L���!�"'�D���}��
�
�4� ����	�!&�D���}��	�	�'�/�/�+�,��	�s�3B)�)5C"� C"c�T�tj|jj�S)zK
        Returns the name of my class, to prefix log entries with.
        )r%�qualr�r�r9s r6rizPort.logPrefixs���|�|�D�L�L�2�2�3�3r7c�N�|jdgt|j����S)zf
        Returns an IPv4Address or IPv6Address.

        This indicates the server's address.
        r�)r�r r.r9s r6r�zPort.getHost#s%��!�t� � ��C��d�k�k�)B�C�Cr7c�|�|j||�|js|js|j�yyyr+)�handleAcceptr�rbr�)r2r�r�rGs    r6�cbAcceptz
Port.cbAccept+s4�����"�c�"��"�"�d�&7�&7��M�M�O�'8�"r7c	�8�|js|jry|r;tjdtj
j
|d��d|�d��y|jjtjttjd|jj���tj |jj�|j"�\}}}||j$k(sJ�d|dvr,t'|dj)d�d	�}|d|d	d|f}d|dvr,t'|dj)d�d	�}|d|d	d|f}|j*j-|j.d
g|����}|�|jj1�y|j2}|d	z|_t5|j||j.d
g|���|j.d
g|���||j6�}	|j9|	�y)NFz#Could not accept new connection -- z
unknown errorz (�)r��%rrRr�T)r�rbr$r�r�r�r��newsktrrr.rwrr�r�r/rD�get_accept_addrsrNr�r��splitr�r�r��closer�r�r5r�)
r2r�rG�family�lAddr�rAddr�scoper1�s�	transports
          r6rzPort.handleAccept0s�������!2�!2����G�G��?�?�&�&�r�?�;�R�A�
��
�J�J�!�!��!�!�(����C����!3�!3�!5�6�
�
$)�#9�#9�#�*�*�:K�:K�:M�s�x�x�#X� �F�E�5��T�/�/�/�/�/��e�A�h���E�!�H�N�N�3�/��2�3���q��5��8�Q��6���e�A�h���E�!�H�N�N�3�/��2�3���q��5��8�Q��6���|�|�1�1�2C�$�2C�2C�E�2R�E�2R�S�H����
�
� � �"���N�N��!"�Q����"��J�J��%�D�%�%�e�4�e�4�%�D�%�%�e�4�e�4���L�L�
�	��'�'�	�2�r7c��tj|j|�}td|jdzz�x|_}|jj|j|j�x|_
}tj|jj�|j�||�}|r|tk7r|j||�yyy)N��)rDr�rr>r�rNr5r�r�r�r�acceptr.r/rr)r2rGrNrr�s     r6r�z
Port.doAcceptcs����k�k�$�-�-��.��$�A�����):�$;�<�<���4�"�l�l�7�7�������
�	
��
�V��\�\�$�+�+�,�,�.��
�
���s�
K��
�"�(�(����b�#�&�)�2r7)�2r�Nr�)"r�r�r�r�rbr�r.r�r�r�r�r	rr�r�r��__annotations__rr-r�r�r#rXr
�CONNECTION_DONEr��
stopListeningrrZrir�rrr�r�r7r6r�r��s����I��L��M��N�N�M��#�#�J��&�&�L��I�&*�O�]�)�
�E�4���@'6�g�o�o�d�6J�6J�&K�!�#�M�F�!�>4�D��
1�f'r7r�)Ir��
__future__rr�r.r��typingrrr�zope.interfacerr�twisted.internetr	r
rrr
�twisted.internet.abstractrr�twisted.internet.addressrr�twisted.internet.interfacesr�twisted.internet.iocpreactorrrrD�"twisted.internet.iocpreactor.constrrrrr�'twisted.internet.iocpreactor.interfacesr�twisted.internet.protocolr�twisted.internet.tcpr�TCPConnectorrrrr r!r"�twisted.pythonr#r$r%�twisted.internet._newtlsr&�
__startTLSr}�ImportError�$twisted.internet.iocpreactor.reactorr'�WSAECONNREFUSED�WSAENETUNREACHr��
ITCPTransport�
ISystemHandler,r)�
ITLSTransportr�r��IListeningPortr�r�r7r6�<module>r:s[���#��
�
�1�1�7�D�D�>�=�1�G���E�.����1�0��?��I��@��e�3�3��u�3�3���
�
�z�7�7��9Q�9Q�R�x
��$�$�m�^�x
�S�x
�v
���J�
� 8� 8�9�V'�_�n�j�V'�r@�Z�@�FR��R�

�Z�
&�
&�'�Q'�=�)�Q'�(�Q'��e���I��s�
E�E�E

Zerion Mini Shell 1.0