%PDF- %PDF-
Mini Shell

Mini Shell

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

�

Ϫ�f�H����dZddlZddlZddlZddlmZddlmZddlm	Z	e	dk(r3ddl
mZddl
mZdd	l
m
Z
mZmZmZmZmZmZeeeegZe
eeegZeZe
ZeZeZndd
l
mZmZmZmZmZmZeeegZegZddlmZmZmZm Z m!Z!m"Z"ddl#m$Z$m%Z%ee"jLe"jNe"jP�Gd
�dejR��Z*Gd�d�Z+ee"jX�Gd�de+e*��Z-y)a�
Various asynchronous UDP classes.

Please do not use this module directly.

@var _sockErrReadIgnore: list of symbolic error constants (from the C{errno}
    module) representing socket errors where the error is temporary and can be
    ignored.

@var _sockErrReadRefuse: list of symbolic error constants (from the C{errno}
    module) representing socket errors that indicate connection refused.
�N)�Optional)�implementer)�platformType�win32)�WSAEINPROGRESS)�WSAEWOULDBLOCK)�WSAECONNREFUSED�
WSAECONNRESET�WSAEINTR�WSAEMSGSIZE�WSAENETRESET�WSAENOPROTOOPT�WSAETIMEDOUT)�EAGAIN�ECONNREFUSED�EINTR�EMSGSIZE�ENOPROTOOPT�EWOULDBLOCK)�abstract�address�base�defer�error�
interfaces)�failure�logc���eZdZUdZej
ZejZdZ	dZ
eee
d<dZdd�Zed��Zdefd�Zd	�Zd
�Zd�Zd�Zd
�Zdd�Zd�Zd�Zd�Zd�Zd�Zdd�Zd�Z d�Z!d�Z"d�Z#d�Z$d�Z%y)�Porta�
    UDP port, listening for packets.

    @ivar maxThroughput: Maximum number of bytes read in one event
        loop iteration.

    @ivar addressFamily: L{socket.AF_INET} or L{socket.AF_INET6}, depending on
        whether this port is listening on an IPv4 address or an IPv6 address.

    @ivar _realPortNumber: Actual port number being listened on. The
        value will be L{None} until this L{Port} is listening.

    @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}).
    iN�_realPortNumberc���tjj||�||_||_||_||_|j�d|_|j�y)a
        @param port: A port number on which to listen.
        @type port: L{int}

        @param proto: A C{DatagramProtocol} instance which will be
            connected to the given C{port}.
        @type proto: L{twisted.internet.protocol.DatagramProtocol}

        @param interface: The local IPv4 or IPv6 address to which to bind;
            defaults to '', ie all IPv4 addresses.
        @type interface: L{str}

        @param maxPacketSize: The maximum packet size to accept.
        @type maxPacketSize: L{int}

        @param reactor: A reactor which will notify this C{Port} when
            its socket is ready for reading or writing. Defaults to
            L{None}, ie the default global reactor.
        @type reactor: L{interfaces.IReactorFDSet}
        N)
r�BasePort�__init__�port�protocol�
maxPacketSize�	interface�	setLogStr�_connectedAddr�_setAddressFamily)�selfr$�protor'r&�reactors      �6/usr/lib/python3/dist-packages/twisted/internet/udp.pyr#z
Port.__init__[sS��*	
�
�
���t�W�-���	���
�*���"�������"������ �c��tj|||j�}|j�d}|d||||��}||_|S)a�
        Create a new L{Port} based on an existing listening
        I{SOCK_DGRAM} socket.

        @param reactor: A reactor which will notify this L{Port} when
            its socket is ready for reading or writing. Defaults to
            L{None}, ie the default global reactor.
        @type reactor: L{interfaces.IReactorFDSet}

        @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.
        @type fd: L{int}

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

        @param protocol: A C{DatagramProtocol} instance which will be
            connected to the C{port}.
        @type protocol: L{twisted.internet.protocol.DatagramProtocol}

        @param maxPacketSize: The maximum packet size to accept.
        @type maxPacketSize: L{int}

        @return: A new instance of C{cls} wrapping the socket given by C{fd}.
        @rtype: L{Port}
        rN)r'r-r&)�socket�fromfd�
socketType�getsockname�_preexistingSocket)	�clsr-�fd�
addressFamilyr%r&r$r'r+s	         r.�_fromListeningDescriptorzPort._fromListeningDescriptorysV��@�}�}�R�����?���$�$�&�q�)�	������'�
��#'����r/�returnc��|j�'d|jj�d|j�d�Sd|jj�d�S)N�<z on �>z not connected>)r r%�	__class__�r+s r.�__repr__z
Port.__repr__�sO�����+��t�}�}�.�.�/�t�D�4H�4H�3I��K�K��t�}�}�.�.�/��?�?r/c��|jS)z)
        Return a socket object.
        )r1r?s r.�	getHandlezPort.getHandle�����{�{�r/c�D�|j�|j�y)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.
        N)�_bindSocket�_connectToProtocolr?s r.�startListeningzPort.startListening�s��	
�������!r/c�(�|j�9	|j�}|j|j|jf�n|j}d|_|j�d|_	tj|j|j��d|j���d|_||_|jj |_y#t
$r0}t
j|j|j|��d}~wwxYw)aJ
        Prepare and assign a L{socket.socket} instance to
        C{self.socket}.

        Either creates a new SOCK_DGRAM L{socket.socket} bound to
        C{self.interface} and C{self.port} or takes an existing
        L{socket.socket} provided via the
        L{interfaces.IReactorSocket.adoptDatagramPort} interface.
        N�z
 starting on )r5�createInternetSocket�bindr'r$�OSErrorr�CannotListenErrorr4r r�msg�
_getLogPrefixr%�	connectedr1�fileno�r+�skt�les   r.rEzPort._bindSocket�s����"�"�*�
M��/�/�1�����$�.�.�$�)�)�4�5�
�)�)�C�&*�D�#� #���0��3�������!�!�$�-�-�0�$�2F�2F�
H�	
�
�������k�k�(�(����%�
M��-�-�d�n�n�d�i�i��L�L��
M�s�7C�	D�!+D�Dc�Z�|jj|�|j�y�N)r%�makeConnection�startReadingr?s r.rFzPort._connectToProtocol�s ���
�
�$�$�T�*����r/c�<�d}||jkr�	|jj|j�\}}|t	|�z
}|j
tjk(r|dd}	|jj||�||jkr��yy#t$rtj�Y�1wxYw#t$rU}|jd}|tvrYd}~y|tvr+|j r|jj#�Yd}~y�d}~wwxYw)z=
        Called when my socket is ready for reading.
        rN�)�
maxThroughputr1�recvfromr&�lenr8�AF_INET6r%�datagramReceived�
BaseExceptionr�errrL�args�_sockErrReadIgnore�_sockErrReadRefuser)�connectionRefused)r+�read�data�addr�se�nos      r.�doReadzPort.doRead�s������T�'�'�'�
�!�[�[�1�1�$�2D�2D�E�
��d���D�	�!���%�%����8� ���8�D���M�M�2�2�4��>�/�T�'�'�'��0%���G�G�I���+�
��W�W�Q�Z���+�+���+�+��*�*��
�
�7�7�9����
�s5�(B=�,B�B:�9B:�=	D�D�".D�D�Dc��|jr.|d|jfvsJ�	|jj|�S|dk7sJ�tj|d�s9tj|d�s!|ddk7rtj |dd��tj|d�s|ddk(r6|j"tj$k(rtj |dd��tj|d�r6|j"tj&k(rtj |dd��	|jj)||�S#t$r{}|jd}|t
k(r|j
|�cYd}~S|tk(rtjd��|tk(r|jj�n�Yd}~yd}~wwxYw#t$ra}|jd}|t
k(r|j
||�cYd}~S|tk(rtjd��|tk(rYd}~y�d}~wwxYw)az
        Write a datagram.

        @type datagram: L{bytes}
        @param datagram: The datagram to be sent.

        @type addr: L{tuple} containing L{str} as first element and L{int} as
            second element, or L{None}
        @param addr: A tuple of (I{stringified IPv4 or IPv6 address},
            I{integer port number}); can be L{None} in connected mode.
        Nrzmessage too longz<broadcast>z0write() only accepts IP addresses, not hostnamesz7IPv6 port write() called with IPv4 or broadcast addressz*IPv4 port write() called with IPv6 address)r)r1�sendrLrbr�writerr�MessageLengthErrorrr%rer�isIPAddress�
isIPv6Address�InvalidAddressErrorr8r^�AF_INET�sendto)r+�datagramrhrirjs     r.rnz
Port.writes������D�$�"5�"5�6�6�6�6�
��{�{�'�'��1�1��4�<��<��(�(��a��1� �.�.�t�A�w�7���G�}�,��/�/���G�O����$�$�T�!�W�-��a��M�1I��$�$����7��/�/���G�V����%�%�d�1�g�.�4�3E�3E����3W��/�/���G�I���
��{�{�)�)�(�D�9�9��?�	
��W�W�Q�Z����;��:�:�h�/�/��8�^��2�2�3E�F�F��<�'��M�M�3�3�5��6��	
��@�
��W�W�Q�Z����;��:�:�h��5�5��8�^��2�2�3E�F�F��<�'����
�sN�E�8G�	G�(G�G�AG�G�	I�$)I�
I�'I�?I�Ic�F�|jdj|�|�y)a�
        Write a datagram constructed from an iterable of L{bytes}.

        @param seq: The data that will make up the complete datagram to be
            written.
        @type seq: an iterable of L{bytes}

        @type addr: L{tuple} containing L{str} as first element and L{int} as
            second element, or L{None}
        @param addr: A tuple of (I{stringified IPv4 or IPv6 address},
            I{integer port number}); can be L{None} in connected mode.
        r/N)rn�join)r+�seqrhs   r.�
writeSequencezPort.writeSequence@s��	
�
�
�3�8�8�C�=�$�'r/c��|jrtd��tj|�s+tj|�stj|d��||f|_|jj||f�y)z-
        'Connect' to remote server.
        z:already connected, reconnecting is not currently supported�not an IPv4 or IPv6 address.N)	r)�RuntimeErrorrrprqrrrr1�connect)r+�hostr$s   r.r}zPort.connectOsp������L��
��#�#�D�)�(�2H�2H��2N��+�+�D�2P�Q�Q�#�T�l��������T�4�L�)r/c��|j�|jr'|jjd|j�yy)Nr)�stopReadingrPr-�	callLater�connectionLostr?s r.�_loseConnectionzPort._loseConnection\s4�������>�>��L�L�"�"�1�d�&9�&9�:�r/c�z�|jrtj�x}|_nd}|j	�|SrV)rPr�Deferred�dr�)r+�results  r.�
stopListeningzPort.stopListeningas2���>�>�#�n�n�.�.�F�T�V��F������
r/c�\�tjdtd��|j�y)Nz-Please use stopListening() to disconnect portrZ)�
stacklevel)�warnings�warn�DeprecationWarningr�r?s r.�loseConnectionzPort.loseConnectionis%���
�
�;���	
�
	
���r/c�h�tjd|jz�d|_d|_tj
j
||�|jj�|jj�|`	|`t|d�r|jjd�|`
yy)z&
        Cleans up my socket.
        z(UDP Port %s Closed)N���r�)rrNr r[rr"r�r%�doStopr1�closerQ�hasattrr��callback)r+�reasons  r.r�zPort.connectionLostqs���	���&��)=�)=�=�>�#�������
�
�$�$�T�6�2��
�
�����������K��K��4����F�F�O�O�D�!���r/c�N�|j|j�}d|z|_y)zP
        Initialize the C{logstr} attribute to be used by C{logPrefix}.
        z%s (UDP)N)rOr%�logstr)r+�	logPrefixs  r.r(zPort.setLogStr�s$���&�&�t�}�}�5�	� �9�,��r/c�0�tj|j�rtj|_ytj|j�rtj|_y|jr tj|jd��y)z8
        Resolve address family for the socket.
        r{N)
rrqr'r1r^r8rprsrrrr?s r.r*zPort._setAddressFamily�si���!�!�$�.�.�1�!'���D��
�
!�
!�$�.�.�
1�!'���D��
�^�^��+�+���� >��
�r/c��|jS)z0
        Return the prefix to log with.
        )r�r?s r.r�zPort.logPrefix�rCr/c�
�|jj�}|jtjk(rt	j
dg|���S|jtjk(rt	jdg|dd���Sy)z�
        Return the local address of the UDP connection

        @returns: the local address of the UDP connection
        @rtype: L{IPv4Address} or L{IPv6Address}
        �UDPNrZ)r1r4r8rsr�IPv4Addressr^�IPv6Address�r+rhs  r.�getHostzPort.getHost�sq���{�{�&�&�(��������/��&�&�u�4�t�4�4�
�
�
�6�?�?�
2��&�&�u�:��R�a��:�:�3r/c�v�|jjtjtj|�y)z�
        Set whether this port may broadcast. This is disabled by default.

        @param enabled: Whether the port may broadcast.
        @type enabled: L{bool}
        N)r1�
setsockopt�
SOL_SOCKET�SO_BROADCAST)r+�enableds  r.�setBroadcastAllowedzPort.setBroadcastAllowed�s&��	
�����v�0�0�&�2E�2E�w�Or/c��t|jjtjtj��S)z�
        Checks if broadcast is currently allowed on this port.

        @return: Whether this port may broadcast.
        @rtype: L{bool}
        )�boolr1�
getsockoptr�r�r?s r.�getBroadcastAllowedzPort.getBroadcastAllowed�s,���D�K�K�*�*�6�+<�+<�f�>Q�>Q�R�S�Sr/)�� NrV)&�__name__�
__module__�__qualname__�__doc__r1rsr8�
SOCK_DGRAMr3r[r r�int�__annotations__r5r#�classmethodr9�strr@rBrGrErFrkrnryr}r�r�r�r�r(r*r�r�r�r��r/r.rr>s����$�N�N�M��"�"�J��M�%)�O�X�c�]�)���!�<�)��)�V@�#�@��"�!)�F��@<�|
(�*�;�
��� -���;�P�Tr/rc�V�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
dd	�Zd
�Zd�Z
dd�Zy
)�MulticastMixinz,
    Implement multicast functionality.
    c���|jjtjtj�}tjtjd|��S)Nz@i)r1r��
IPPROTO_IP�IP_MULTICAST_IF�	inet_ntoa�struct�pack)r+�is  r.�getOutgoingInterfacez#MulticastMixin.getOutgoingInterface�s@���K�K�"�"�6�#4�#4�f�6L�6L�M��������D�!� 4�5�5r/c�j�|jj|�j|j�S)zReturns Deferred of success.)r-�resolve�addCallback�
_setInterfacer�s  r.�setOutgoingInterfacez#MulticastMixin.setOutgoingInterface�s(���|�|�#�#�D�)�5�5�d�6H�6H�I�Ir/c��tj|�}|jjtjtj|�y)NrI)r1�	inet_atonr�r�r�)r+rhr�s   r.r�zMulticastMixin._setInterface�s7�����T�"�������v�0�0�&�2H�2H�!�L�r/c�r�|jjtjtj�SrV)r1r�r��IP_MULTICAST_LOOPr?s r.�getLoopbackModezMulticastMixin.getLoopbackMode�s%���{�{�%�%�f�&7�&7��9Q�9Q�R�Rr/c��tjdt|��}|jj	tj
tj|�y)N�b)r�r�r�r1r�r�r�)r+�modes  r.�setLoopbackModezMulticastMixin.setLoopbackMode�s8���{�{�3��T�
�+�������v�0�0�&�2J�2J�D�Qr/c�r�|jjtjtj�SrV)r1r�r��IP_MULTICAST_TTLr?s r.�getTTLzMulticastMixin.getTTL�s%���{�{�%�%�f�&7�&7��9P�9P�Q�Qr/c��tjd|�}|jjtjtj
|�y)N�B)r�r�r1r�r�r�)r+�ttls  r.�setTTLzMulticastMixin.setTTL�s4���k�k�#�s�#�������v�0�0�&�2I�2I�3�Or/c�n�|jj|�j|j|d�S)z4Join a multicast group. Returns Deferred of success.rI�r-r�r��
_joinAddr1�r+rhr's   r.�	joinGroupzMulticastMixin.joinGroup��+���|�|�#�#�D�)�5�5�d�o�o�y�RS�T�Tr/c�n�|jj|�j|j||�SrV)r-r�r��
_joinAddr2)r+rhr'rws    r.r�zMulticastMixin._joinAddr1�s+���|�|�#�#�I�.�:�:�4�?�?�D�RV�W�Wr/c��tj|�}tj|�}|rtj}ntj}	|jj	tj
|||z�y#t$r>}tjtj||g|j����cYd}~Sd}~wwxYwrV)r1r��IP_ADD_MEMBERSHIP�IP_DROP_MEMBERSHIPr�r�rLr�Failurer�MulticastJoinErrorrb)r+r'rhrw�cmd�es      r.r�zMulticastMixin._joinAddr2�s�������%���$�$�Y�/�	���*�*�C��+�+�C�	W��K�K�"�"�6�#4�#4�c�4�)�;K�L���	W��?�?�5�#;�#;�D�)�#U�a�f�f�#U�V�V��	W�s�.A>�>	C�3C�:C�Cc�n�|jj|�j|j|d�S)z2Leave multicast group, return Deferred of success.rr�r�s   r.�
leaveGroupzMulticastMixin.leaveGroup�r�r/N)r�)r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r/r.r�r��sG���6�J��
S�R�R�P�U�X�
W�Ur/r�c�&�eZdZdZ				dd�Zd�Zy)�
MulticastPortz.
    UDP Port that supports multicasting.
    Nc�F�tj||||||�||_y)zX
        @see: L{twisted.internet.interfaces.IReactorMulticast.listenMulticast}
        N)rr#�listenMultiple)r+r$r,r'r&r-r�s       r.r#zMulticastPort.__init__�s"��	
�
�
�d�D�%��M�7�K�,��r/c��tj|�}|jrq|jtj
tjd�ttd�r2	|jtj
tjd�|S|S#t$r }|jtk(rn�Yd}~|Sd}~wwxYw)NrI�SO_REUSEPORT)rrJr�r�r1r��SO_REUSEADDRr�r�rL�errnorrRs   r.rJz"MulticastPort.createInternetSockets����'�'��-������N�N�6�,�,�f�.A�.A�1�E��v�~�.���N�N�6�#4�#4�f�6I�6I�1�M��
�s�
��
���x�x�;�.�����
��
�s�"/B�	B>�B9�9B>)r�r�NF)r�r�r�r�r#rJr�r/r.r�r��s�������
-�
r/r�).r�r1r�r��typingr�zope.interfacer�twisted.python.runtimerr�rrr	r
rrr
rrrrcrdrrrrr�twisted.internetrrrrrr�twisted.pythonrr�IListeningPort�
IUDPTransport�
ISystemHandler"rr��IMulticastTransportr�r�r/r.�<module>r�s��
��
���&�/��7��$�$����#�N�K��P��)�=�,��U���H�"�L�
�F��E�U�U� �%��5��&���O�N�'�
����z�7�7��9Q�9Q��wT�4�=�=�wT��wT�t5U�5U�p
�Z�
+�
+�,�!�N�D�!�-�!r/

Zerion Mini Shell 1.0