%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__/unix.cpython-312.pyc

�

Ϫ�f�W��<�dZddlZddlZddlZddlZddlmZmZmZm	Z	m
Z
mZddlm
Z
mZddlmZmZmZddlmZmZmZmZmZmZmZmZddlmZddlmZm Z m!Z!m"Z"dd	l#m$Z$dd
l%m&Z&ddl'm(Z(	ddlm)Z*e*Z)e,ed
�se+d��d�Z-Gd�d�Z.Gd�d�Z/e)re.Z.ne/Z.eej`�Gd�de.ejb��Z1d�Z2Gd�d�Z3Gd�de3ejh�Z4eej`�Gd�de.ejj��Z6Gd�dejn�Z8eejr�Gd�d e3ejh��Z:eejvgeejx����Gd!�d"e:��Z=y#e+$rdZ)Y��$wxYw)#z�
UNIX socket support for Twisted.

End users shouldn't use this module directly - use the reactor APIs instead.

Maintainer: Itamar Shtull-Trauring
�N)�EAGAIN�ECONNREFUSED�EINTR�EMSGSIZE�ENOBUFS�EWOULDBLOCK)�Optional�Type)�
implementedBy�implementer�implementer_only)�address�base�error�
interfaces�main�protocol�tcp�udp)�FileDescriptor)�failure�lockfile�log�reflect)�
lazyByteSlice)�_coerceToFilesystemEncoding)�untilConcludes)�sendmsg�AF_UNIXz+UNIX sockets not supported on this platformc�r�tjd|�}tjtj
|fgS)zh
    Pack an integer into an ancillary data structure suitable for use with
    L{sendmsg.sendmsg}.
    �i)�struct�pack�socket�
SOL_SOCKETr�
SCM_RIGHTS)�fd�packeds  �7/usr/lib/python3/dist-packages/twisted/internet/unix.py�_ancillaryDescriptorr*)s0��
�[�[��b�
!�F�
�
�
�� 2� 2�F�;�<�<�c�T�eZdZUdZdZeeeed<dZ	d�Z
d�Zd�Zd�Z
d	�Zd
�Zy)�
_SendmsgMixina

    Mixin for stream-oriented UNIX transports which uses sendmsg and recvmsg to
    offer additional functionality, such as copying file descriptors into other
    processes.

    @ivar _writeSomeDataBase: The class which provides the basic implementation
        of C{writeSomeData}.  Ultimately this should be a subclass of
        L{twisted.internet.abstract.FileDescriptor}.  Subclasses which mix in
        L{_SendmsgMixin} must define this.

    @ivar _sendmsgQueue: A C{list} of C{int} holding file descriptors which are
        currently buffered before being sent.

    @ivar _fileDescriptorBufferSize: An C{int} giving the maximum number of file
        descriptors to accept and queue for sending before pausing the
        registered producer, if there is one.
    N�_writeSomeDataBase�@c��g|_y�N)�
_sendmsgQueue��selfs r)�__init__z_SendmsgMixin.__init__Hs
����r+c��t|j�|jkDxs|jj	|�S)a�
        Determine whether the user-space send buffer for this transport is full
        or not.

        This extends the base determination by adding consideration of how many
        file descriptors need to be sent using L{sendmsg.sendmsg}.  When there
        are more than C{self._fileDescriptorBufferSize}, the buffer is
        considered full.

        @return: C{True} if it is full, C{False} otherwise.
        )�lenr2�_fileDescriptorBufferSizer.�_isSendBufferFullr3s r)r9z_SendmsgMixin._isSendBufferFullKsD��&����
��*�*�+�
�.2�.E�.E�.W�.W��/
�	
r+c�z�|jj|�|j�|j�y)zY
        Queue the given file descriptor to be sent and start trying to send it.
        N)r2�append�_maybePauseProducer�startWriting)r4�filenos  r)�sendFileDescriptorz _SendmsgMixin.sendFileDescriptords0��	
���!�!�&�)�� � �"����r+c��t|j�t|�kDrtj�Sd}	|t|j�krc|j|}	t	t
j
|j|||dzt|��|dz
}|t|j�kr�c|jd|�=t||�}|jj!||�}	||zS#t$rZ}|jdttfvr|cYd}~|jd|�=StjcYd}~|jd|�=Sd}~wwxYw#|jd|�=wxYw#t"$r|cYSwxYw)zg
        Send as much of C{data} as possible.  Also send any pending file
        descriptors.
        r�N)r7r2r�FileDescriptorOverrunrrr$r*�OSError�argsrrr�CONNECTION_LOSTrr.�
writeSomeData�	TypeError)r4�data�indexr'�se�limitedData�results       r)rFz_SendmsgMixin.writeSomeDatals���t�!�!�"�S��Y�.��.�.�0�0���	+��#�d�0�0�1�1��'�'��.��
�"��������U�U�Q�Y�/�,�R�0�	��Q�J�E��#�d�0�0�1�1�"�"�"�6�E�6�*�$�D�%�0���(�(�6�6�t�[�I��	��6�>�!���4��w�w�q�z�k�7�%;�;�$���"�"�6�E�6�*�	 $�3�3�3��"�"�6�E�6�*��4���"�"�6�E�6�*���	��M�	�s_�'E�!5C1�E�,E+�1	E�:E�E�E�+E�:E�;E�E�E�E(�+E9�8E9c	�4�	ttj|j|j�\}}}|D]�\}}}|tjk(r%|tjk(r|j|��?tjd|j�|j!�|j#|j$�||����|j'|�S#t
$r5}|jdtk(rYd}~ytjcYd}~Sd}~wwxYw)a�
        Calls {IProtocol.dataReceived} with all available data and
        L{IFileDescriptorReceiver.fileDescriptorReceived} once for each
        received file descriptor in ancillary data.

        This reads up to C{self.bufferSize} bytes of data from its socket, then
        dispatches the data to protocol callbacks to be handled.  If the
        connection is not lost through an error in the underlying recvmsg(),
        this function will return the result of the dataReceived call.
        rNz�%(protocolName)s (on %(hostAddress)r) received unsupported ancillary data (level=%(cmsgLevel)r, type=%(cmsgType)r) from %(peerAddress)r.)�format�hostAddress�peerAddress�protocolName�	cmsgLevel�cmsgType)rr�recvmsgr$�
bufferSizerCrDrrrEr%r&�%_ancillaryLevelSOLSOCKETTypeSCMRIGHTSr�msg�getHost�getPeer�
_getLogPrefixr�
_dataReceived)r4rH�	ancillary�flagsrJrRrS�cmsgDatas        r)�doReadz_SendmsgMixin.doRead�s���	,�%3�������d�o�o�&�"�D�)�U�.7�	�)�I�x���F�-�-�-�(�g�>P�>P�2P��:�:�8�D����0�
!%���� $����!%�!3�!3�D�M�M�!B�'�%��		�$�!�!�$�'�'��1�	,��w�w�q�z�[�(���+�+�+��		,�s#�3C�	D�"D�=D�D�Dc��t|�dz}tjd|z|�}tjj|j�r#|D]}|jj|��ytjd|j�|j�|j|j���|D]}tj|��y)a�
        Processes ancillary data with level SOL_SOCKET and type SCM_RIGHTS,
        indicating that the ancillary data payload holds file descriptors.

        Calls L{IFileDescriptorReceiver.fileDescriptorReceived} once for each
        received file descriptor or logs a message if the protocol does not
        implement L{IFileDescriptorReceiver}.

        @param cmsgData: Ancillary data payload.
        @type cmsgData: L{bytes}
        �r!z�%(protocolName)s (on %(hostAddress)r) does not provide IFileDescriptorReceiver; closing file descriptor received (from %(peerAddress)r).)rNrOrPrQN)r7r"�unpackr�IFileDescriptorReceiver�
providedByr�fileDescriptorReceivedrrWrXrYrZ�os�close)r4r^�fdCount�fdsr's     r)rVz3_SendmsgMixin._ancillaryLevelSOLSOCKETTypeSCMRIGHTS�s����h�-�1�$���m�m�C�'�M�8�4���-�-�8�8����G��
9���
�
�4�4�R�8�
9�
�G�G�B�!�L�L�N� �L�L�N�!�/�/��
�
�>�	
��
�������
r+)�__name__�
__module__�__qualname__�__doc__r.r	r
r�__annotations__r8r5r9r?rFr_rV�r+r)r-r-2sD���$:>����n�!5�6�=� "�� �
�2�,�\'(�Rr+r-c��eZdZdZy)�_UnsupportedSendmsgMixinz�
    Behaviorless placeholder used when C{twisted.python.sendmsg} is not
    available, preventing L{IUNIXTransport} from being supported.
    N)rjrkrlrmror+r)rqrq�s��r+rqc�F�eZdZejZd�Zed��Zd�Z	d�Z
y)�Serverc	�|�tj|�tjj||||df|||�yr1)r-r5rrs)r4�sockr�client�server�	sessionno�reactors       r)r5zServer.__init__�s5�����t�$��
�
����$��6�4�.�&�)�W�	
r+c��tj|tjtj�}t	j
|j
��}|j|�}|�|j�yd}||||j�d||�}dj|jjj|j|j
��|_dj|jjj|j|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.

        @return: A new instance of C{cls} wrapping the socket given by
            C{fileDescriptor}.
        Nrz<{} #{} on {}>z{},{},{})r$�fromfdr�SOCK_STREAMr�UNIXAddress�getsockname�
buildProtocolrg�getpeernamerNr�	__class__rjrx�repstr�logstr�makeConnection)	�cls�fileDescriptor�factoryry�skt�protocolAddr�protorxr4s	         r)�_fromConnectedSocketzServer._fromConnectedSocket�s��� �m�m�N�F�N�N�F�<N�<N�O���*�*�3�?�?�+<�=���%�%�l�3���=��I�I�K���	��3��s���0�$�	�7�K��&�-�-��M�M�#�#�,�,��N�N��O�O��
���
!�'�'��M�M�#�#�,�,��N�N��O�O��
���
	���T�"��r+c�\�tj|jj��Sr1�rr}r$r~r3s r)rXzServer.getHost#s ���"�"�4�;�;�#:�#:�#<�=�=r+c�H�tj|jxsd�Sr1)rr}�hostnamer3s r)rYzServer.getPeer&s���"�"�4�=�=�#8�D�9�9r+N)rjrkrlrrsr.r5�classmethodr�rXrYror+r)rsrs�s0������
��%��%�N>�:r+rsc��|dddvS)a�
    Determine whether the given unix socket path is in a filesystem namespace.

    While most PF_UNIX sockets are entries in the filesystem, Linux 2.2 and
    above support PF_UNIX sockets in an "abstract namespace" that does not
    correspond to any path. This function returns C{True} if the given socket
    path is stored in the filesystem and C{False} if the path is in this
    abstract namespace.
    NrA)��ro)�paths r)�_inFilesystemNamespacer�*s�����8�=�(�(r+c��eZdZd�Zy)�	_UNIXPortc�\�tj|jj��S)zV
        Returns a UNIXAddress.

        This indicates the server's address.
        r�r3s r)rXz_UNIXPort.getHost8s"���"�"�4�;�;�#:�#:�#<�=�=r+N)rjrkrlrXror+r)r�r�7s��>r+r�c��eZdZejZejZeZ	dZ
	d
d�Zed��Z
defd�Zd�Zd�Zd�Zd	�Zy)�PortNc��tjj||j|�j|||��||_||_d|_y)N�ry)rr�r5�
_buildAddr�name�mode�wantPID�_preexistingSocket)r4�fileNamer��backlogr�ryr�s       r)r5z
Port.__init__HsM��	������$�/�/�(�+�0�0�'�7�G�	�	
���	����"&��r+c��tj||j|j�}||j	�||��}||_|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.

        @return: A new instance of C{cls} wrapping the socket given by C{fd}.
        r�)r$r{�
addressFamily�
socketTyper~r�)r�ryr'r��portr4s      r)�_fromListeningDescriptorzPort._fromListeningDescriptorRsD���}�}�R��!2�!2�C�N�N�C���4�#�#�%�w��@��"&����r+�returnc���tj|jj�}t	|d�r&dj|t
d|j��Sd|�d�S)Nr$z<{} on {!r}>��<� (not listening)>)r�qualr�r��hasattrrNrr�)r4�factoryNames  r)�__repr__z
Port.__repr__esZ���l�l�4�<�<�#9�#9�:���4��"�!�(�(��+�B��	�	�:��
�
�{�m�#4�5�5r+c�,�tj|�Sr1�rr})r4r�s  r)r�zPort._buildAddro����"�"�4�(�(r+c��tjj�tj|j|j��dtd|j����|jr�tj|jdz�|_|jj�s!tjd|jd��|jj s\	t#j$t'j"|j�j(�rt'j*|j�|jj/�	|j0�|j0}d|_n+|j3�}|j5|j�t7|j�r*t'j8|j|j:�|j=|j>�d|_ ||_!|jBjD|_"d|_#|jI�y#t,$rY��
wxYw#tJ$r&}tjd|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.
        �
 starting on r��.lockNzCannot acquire lockT�d)&r�_reservedFD�reserverrWrZr�rr�r�r�FilesystemLock�lockFile�lockr�CannotListenError�clean�stat�S_ISSOCKrf�st_mode�remove�
BaseException�doStartr��createInternetSocket�bindr��chmodr��listenr��	connectedr$r>�
numberAccepts�startReadingrC�r4r��les   r)�startListeningzPort.startListeningrs���	�����!�����"�"�4�<�<�0�+�B��	�	�:�
�	
��<�<�$�3�3�D�I�I��4H�I�D�M��=�=�%�%�'��-�-�d�D�I�I�?T�U�U��}�}�*�*�	� �=�=�������);�)C�)C�D��I�I�d�i�i�0�	
������	 ��&�&�2��-�-��*.��'��/�/�1��������#�&�d�i�i�0�������D�I�I�.��J�J�t�|�|�$�!�D�N��D�K��+�+�,�,�D�K�!$�D�������/)������	?��)�)�$��	�	�2�>�>��	?�s,�+AI�!AI�	I�I�	J� !J�Jc�\�tjdtd|j�z�y)z0
        Log message for closing socket
        z(UNIX Port %s Closed)r�N)rrWrr�r3s r)�_logConnectionLostMsgzPort._logConnectionLostMsg�s*��	���#�+���I�I��
�	
r+c��t|j�rtj|j�|j�|jj�tjj||�yr1)	r�r�rf�unlinkr��unlockrr��connectionLost�r4�reasons  r)r�zPort.connectionLost�sL��!�$�)�)�,��I�I�d�i�i� ��=�=�$��M�M� � �"�������f�-r+)�2�Nr)rjrkrlr$rr�r|r�rs�	transportr�r5r�r��strr�r�r�r�r�ror+r)r�r�Asa���N�N�M��#�#�J��I��H�PQ�'�����$6�#�6�)�4 �l
�.r+r�c�l�eZdZdZej
ZejZe	jZdd�Zd�Z
d�Zy)�ClientzA client for Unix sockets.Nc�p�tj|�tj|�j}||_|x|_|_|r?tj|dz�s'|jddtj|�|�|j|j|j�d|�y)Nr�)r-r5rr}r��	connector�realAddress�addrr�isLocked�_finishInitr�BadFileError�	doConnectr�)r4�filenamer�ry�checkPIDs     r)r5zClient.__init__�s������t�$��&�&�x�0�5�5��"���'/�/���4�9��H�-�-�h��.A�B����T�4��);�);�H�)E�w�O��������)B�)B�)D�d�G�Tr+c�@�tj|j�Sr1)rr}r�r3s r)rYzClient.getPeer�s���"�"�4�9�9�-�-r+c�,�tjd�Sr1r�r3s r)rXzClient.getHost�r�r+)Nr)rjrkrlrmr$rr�r|r�r�
BaseClientr.r5rYrXror+r)r�r��s3��$��N�N�M��#�#�J�����U�.�)r+r�c��eZdZd�Zd�Zd�Zy)�	Connectorc�d�tjj||||�||_||_yr1)r�
BaseConnectorr5rr�)r4rr��timeoutryr�s      r)r5zConnector.__init__�s*�����#�#�D�'�7�G�D���� ��
r+c�Z�t|j||j|j�Sr1)r�rryr�r3s r)�_makeTransportzConnector._makeTransport�s���d�l�l�D�$�,�,��
�
�F�Fr+c�@�tj|j�Sr1r�r3s r)�getDestinationzConnector.getDestination�s���"�"�4�<�<�0�0r+N)rjrkrlr5r�r�ror+r)r�r��s��!�
G�1r+r�c�V�eZdZdZej
Zd
d�Zdefd�Z	d�Z
d�Zdd�Zd	�Z
y)�DatagramPortz4
    Datagram UNIX port, listening for packets.
    Nc�Z�tjj|||||��||_y)z%Initialize with address to listen on.)�
maxPacketSizeryN)rr�r5r�)r4r�r�r�r�rys      r)r5zDatagramPort.__init__�s-��������$��]�G�	�	
���	r+r�c��tj|jj�}t	|d�rd|�d|j
�d�Sd|�d�S)Nr$r�z on �>r�)rr�rr�r�r�)r4rQs  r)r�zDatagramPort.__repr__�sR���|�|��M�M�#�#�
���4��"��|�n�D����
�Q�7�7��|�n�$5�6�6r+c�B�tj|jj�dt	|j
����	|j
�}|j
r|j|j
�|j
r?t|j
�r*tj|j
|j�d|_||_|j j"|_y#t$r&}tjd|j
|��d}~wwxYw)Nr�rA)rrWrr��reprr�r�r�rCrr�r�rfr�r�r�r$r>r�s   r)�_bindSocketzDatagramPort._bindSocket�s������4�=�=�*�*�+�=��d�i�i��8I�J�K�	?��+�+�-�C��y�y�������#��9�9�/��	�	�:��H�H�T�Y�Y��	�	�*��������k�k�(�(�����	?��)�)�$��	�	�2�>�>��	?�s�7C/�/	D�8!D�Dc��	|jj||�S#t$rb}|jd}|tk(r|j||�cYd}~S|tk(rtjd��|tk(rn�Yd}~yd}~wwxYw)zWrite a datagram.rN�message too long)
r$�sendtorCrDr�writerr�MessageLengthErrorr)r4�datagramrrJ�nos     r)rzDatagramPort.writes���	��;�;�%�%�h��8�8���	������B��U�{��z�z�(�G�4�4��x���.�.�/A�B�B��v������	�s ��	B	�)B�B	�)B�B	c��tjdt|j�z�tj
j
||�t|d�r|jj�d|_
|jj�|`|`
t|d�r|jjd�|`yy)zCleans up my socket.z(Port %s Closed)rr�dN)rrWr�r�r�BasePortr�r�r�doStopr�r$rgr>r�callbackr�s  r)r�zDatagramPort.connectionLosts������"�T�$�)�)�_�4�5��
�
�$�$�T�6�2��4��$�
�M�M� � �"�����������K��K��4����F�F�O�O�D�!���r+c�f�tj|jj�dz|_y)Nz (UDP))rr�rr�r�r3s r)�	setLogStrzDatagramPort.setLogStr-s!���l�l�4�=�=�#:�#:�;�h�F��r+)� r�Nr1)rjrkrlrmr$rr�r5r�r�r�rr�r
ror+r)r�r��s8����N�N�M��7�#�7�
)��$� Gr+r�c�>�eZdZdZ				d	d�Zd�Zd�Zd�Zd�Zd�Z	y)
�ConnectedDatagramPortz+
    A connected datagram UNIX socket.
    Nc�~�t|tj�sJ�tj	||||||�||_yr1)�
isinstancer�ConnectedDatagramProtocolr�r5�
remoteaddr)r4r�r�r�r��bindAddressrys       r)r5zConnectedDatagramPort.__init__9s9���%��!C�!C�D�D�D����d�K��
�t�W�U���r+c���	|j�|jj|j�|j	�y#t
$r&|j
tj��YywxYwr1)	r�r$�connectr�_connectToProtocolr��connectionFailedr�Failurer3s r)r�z$ConnectedDatagramPort.startListeningFsY��	5������K�K������0��#�#�%���	5��!�!�'�/�/�"3�4�	5�s�AA�,A7�6A7c�^�|j�|jj|�|`y)z�
        Called when a connection fails. Stop listening on the socket.

        @type reason: L{Failure}
        @param reason: Why the connection failed.
        N)�
stopListeningrrr�s  r)rz&ConnectedDatagramPort.connectionFailedNs'��	
�����
�
�&�&�v�.��Mr+c���d}||jkrc	|jj|j�\}}|t	|�z
}|j
j
|�||jkr�byy#t$rV}|jd}|tttfvrYd}~y|tk(r|j
j�n�Yd}~�ld}~wt$rtj �Y��wxYw)z=
        Called when my socket is ready for reading.
        rN)�
maxThroughputr$�recvfromr�r7r�datagramReceivedrCrDrrrr�connectionRefusedr�r�deferr)r4�readrHr�rJrs      r)r_zConnectedDatagramPort.doReadYs������T�'�'�'�

�!�[�[�1�1�$�2D�2D�E�
��d���D�	�!���
�
�.�.�t�4�	�T�'�'�'��
�
��W�W�Q�Z���&�%��5�5����%��M�M�3�3�5��6��!�
��
�
��
�s$�AA6�6	C3�?"C�&%C� C3�2C3c�f�	|jj|�S#t$r�}|jd}|tk(r|j|�cYd}~S|tk(rtjd��|tk(r|jj�n|tk(rn�Yd}~yYd}~yd}~wwxYw)z#
        Write a datagram.
        rNr�)
r$�sendrCrDrrrrrrrrr)r4rHrJrs    r)rzConnectedDatagramPort.writens���	��;�;�#�#�D�)�)���	������B��U�{��z�z�$�'�'��x���.�.�/A�B�B��|�#��
�
�/�/�1��v�����2��	�s!��	B0�(B+�B0�A
B+�+B0c�@�tj|j�Sr1)rr}rr3s r)rYzConnectedDatagramPort.getPeer�s���"�"�4�?�?�3�3r+)rr�NN)
rjrkrlrmr5r�rr_rrYror+r)r
r
1s3����
����5�	��*�,4r+r
)>rmrfr$r�r"�errnorrrrrr�typingr	r
�zope.interfacerrr
�twisted.internetrrrrrrrr�twisted.internet.abstractr�twisted.pythonrrrr�twisted.python.compatr�twisted.python.filepathr�twisted.python.utilrr�_sendmsg�ImportErrorr�r*r-rq�IUNIXTransportrsr�r�r�r�r�r�r��IUNIXDatagramTransportr��IUNIXDatagramConnectedTransportrr
ror+r)�<module>r2s���
�
�
��
�M�M�!�G�G�W�W�W�4�:�:�/�?�.��2��G��v�y�!�
�C�
D�D�=�o�o�d���!�M�,�M�
�Z�
&�
&�'�5:�]�C�J�J�5:�(�5:�p
)�>�>�z.�9�c�h�h�z.�z
�Z�
&�
&�'�)�]�C�N�N�)�(�)�0
1��"�"�
1�
�Z�
.�
.�/�IG�9�c�h�h�IG�0�IG�X��.�.��2?��
�
�2N��Q4�L�Q4��Q4��i���G��s�.F�F�F

Zerion Mini Shell 1.0