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

�

Ϫ�fYK���dZddlmZmZmZddlmZmZmZddl	m
Z
ddlmZm
Z
ddlmZmZddlmZd�Zd	�ZGd
�d�Ze
ej,�Gd�d
��Ze
ej0ej2ej4ej6ej8�Gd�dee��Zefdedede fd�Z!dede fd�Z"gd�Z#y)z+
Support for generic select()able objects.
�)�AF_INET�AF_INET6�	inet_pton)�Iterable�List�Optional)�implementer)�
interfaces�main)�failure�reflect)�
lazyByteSlicec�:�t|t�std��y)NzData must be bytes)�
isinstance�bytes�	TypeError)�objs �;/usr/lib/python3/dist-packages/twisted/internet/abstract.py�_dataMustBeBytesrs���c�5�!��,�-�-�"�c�D�djt|�|dg|z�S)Nr)�join�
memoryview)�bObj�offset�bArrays   r�_concatenaters%���8�8�Z��%�f�g�.�/�&�8�9�9rc�.�eZdZdZdZdZdZd�Zd�Zd�Z	y)�_ConsumerMixina�
    L{IConsumer} implementations can mix this in to get C{registerProducer} and
    C{unregisterProducer} methods which take care of keeping track of a
    producer's state.

    Subclasses must provide three attributes which L{_ConsumerMixin} will read
    but not write:

      - connected: A C{bool} which is C{True} as long as the consumer has
        someplace to send bytes (for example, a TCP connection), and then
        C{False} when it no longer does.

      - disconnecting: A C{bool} which is C{False} until something like
        L{ITransport.loseConnection} is called, indicating that the send buffer
        should be flushed and the connection lost afterwards.  Afterwards,
        C{True}.

      - disconnected: A C{bool} which is C{False} until the consumer no longer
        has a place to send bytes, then C{True}.

    Subclasses must also override the C{startWriting} method.

    @ivar producer: L{None} if no producer is registered, otherwise the
        registered producer.

    @ivar producerPaused: A flag indicating whether the producer is currently
        paused.
    @type producerPaused: L{bool}

    @ivar streamingProducer: A flag indicating whether the producer was
        registered as a streaming (ie push) producer or not (ie a pull
        producer).  This will determine whether the consumer may ever need to
        pause and resume it, or if it can merely call C{resumeProducing} on it
        when buffer space is available.
    @ivar streamingProducer: C{bool} or C{int}

    NFc��td��)a
        Override in a subclass to cause the reactor to monitor this selectable
        for write events.  This will be called once in C{unregisterProducer} if
        C{loseConnection} has previously been called, so that the connection can
        actually close.
        z!%r did not implement startWriting��NotImplementedError��selfs r�startWritingz_ConsumerMixin.startWritingLs��"�"E�F�Frc���|j�td|�d|j�d���|jr|j�y||_||_|s|j�yy)a"
        Register to receive data from a producer.

        This sets this selectable to be a consumer for a producer.  When this
        selectable runs out of data on a write() call, it will ask the producer
        to resumeProducing(). When the FileDescriptor's internal data buffer is
        filled, it will ask the producer to pauseProducing(). If the connection
        is lost, FileDescriptor calls producer's stopProducing() method.

        If streaming is true, the producer should provide the IPushProducer
        interface. Otherwise, it is assumed that producer provides the
        IPullProducer interface. In this case, the producer won't be asked to
        pauseProducing(), but it has to be careful to write() data only when its
        resumeProducing() method is called.
        NzCannot register producer z, because producer z was never unregistered.)�producer�RuntimeError�disconnected�
stopProducing�streamingProducer�resumeProducing)r$r'�	streamings   r�registerProducerz_ConsumerMixin.registerProducerUsc�� �=�=�$��#+�T�]�]�<��
�����"�"�$�$�D�M�%.�D�"���(�(�*�rc�f�d|_|jr|jr|j�yyy)zM
        Stop consuming data from a producer, without disconnecting.
        N)r'�	connected�
disconnectingr%r#s r�unregisterProducerz!_ConsumerMixin.unregisterProducerrs-����
��>�>�d�0�0�����1�>r)
�__name__�
__module__�__qualname__�__doc__r'�producerPausedr+r%r.r2�rrrr!s*��$�L�H��N���G�+�: rrc�&�eZdZdZdedefd�Zd�Zy)�	_LogOwnerz�
    Mixin to help implement L{interfaces.ILoggingContext} for transports which
    have a protocol, the log prefix of which should also appear in the
    transport's log prefix.
    �applicationObject�returnc��tjj|�r|j�S|jj
S)z�
        Determine the log prefix to use for messages related to
        C{applicationObject}, which may or may not be an
        L{interfaces.ILoggingContext} provider.

        @return: A C{str} giving the log prefix to use.
        )r
�ILoggingContext�
providedBy�	logPrefix�	__class__r3)r$r;s  r�
_getLogPrefixz_LogOwner._getLogPrefix�s:���%�%�0�0�1B�C�$�.�.�0�0� �*�*�3�3�3rc��y)z�
        Override this method to insert custom logging behavior.  Its
        return value will be inserted in front of every line.  It may
        be called more times than the number of output lines.
        �-r8r#s rr@z_LogOwner.logPrefix�s��rN)r3r4r5r6�object�strrBr@r8rrr:r:{s���
4�v�
4�#�
4�rr:c�8�eZdZdZdZdZdZdZdZdZ	dZ
dZd'dee
jfd�Zd	�Zd
eddfd�Zd
�Zd�Zd�Zd�Zd�Zdej2ddfd�Zd�Zd�Zd�Zd�Zd
eddfd�Zde eddfd�Z!d�Z"d�Z#d�Z$d�Z%d�Z&d �Z'dZ(d!Z)d"�Z*d#�Z+d$�Z,d%�Z-d&�Z.y)(�FileDescriptorz�
    An object which can be operated on by select().

    This is an abstract superclass of all objects which may be notified when
    they are readable or writable; e.g. they have a file-descriptor that is
    valid to be passed to select(2).
    rFriN�reactorc�B�|sddlm}|}||_g|_d|_y)z�
        @param reactor: An L{IReactorFDSet} provider which this descriptor will
            use to get readable and writeable event notifications.  If no value
            is given, the global reactor will be used.
        r)rIN)�twisted.internetrI�_tempDataBuffer�_tempDataLen)r$rI�_reactors   r�__init__zFileDescriptor.__init__�s&���<��G����,.�����rc��d|_d|_|j�!|jj�d|_|j	�|j�y)azThe connection was lost.

        This is called when the connection on a selectable object has been
        lost.  It will be called whether the connection was closed explicitly,
        an exception occurred in an event handler, or the other end of the
        connection closed it first.

        Clean up state here, but make sure to call back up to FileDescriptor.
        �rN)r)r0r'r*�stopReading�stopWriting�r$�reasons  r�connectionLostzFileDescriptor.connectionLost�sL���������=�=�$��M�M�'�'�)� �D�M��������r�datar<c�X�tdtj|j�z��)a�
        Write as much as possible of the given data, immediately.

        This is called to invoke the lower-level writing functionality, such
        as a socket's send() method, or a file's write(); this method
        returns an integer or an exception.  If an integer, it is the number
        of bytes written (possibly zero); if an exception, it indicates the
        connection was lost.
        z#%s does not implement writeSomeData�r"r
�qualrA�r$rWs  r�
writeSomeDatazFileDescriptor.writeSomeData�s&��"�1�G�L�L����4P�P�
�	
rc�X�tdtj|j�z��)z�
        Called when data is available for reading.

        Subclasses must override this method. The result will be interpreted
        in the same way as a result of doWrite().
        z%s does not implement doReadrYr#s r�doReadzFileDescriptor.doRead�s&��"�*�W�\�\�$�.�.�-I�I�
�	
rc��t|j�|jz
|jkrEt	|j|j|j
�|_d|_g|_d|_|jr0|jt|j|j��}n|j|j�}t|t�s|dkr|S|xj|z
c_|jt|j�k(r�|js�d|_d|_|j�|j�:|jr|jr"d|_|jj�y|j r|j#�S|j$rd|_|j)�}|Sy)z�
        Called when data can be written.

        @return: L{None} on success, an exception or a negative integer on
            failure.

        @see: L{twisted.internet.interfaces.IWriteDescriptor.doWrite}.
        rrNFT)�len�
dataBufferr�
SEND_LIMITrrLrMr\rr�	ExceptionrSr'r+r7r,r1�_postLoseConnection�_writeDisconnecting�_writeDisconnected�_closeWriteConnection)r$�l�results   r�doWritezFileDescriptor.doWrite�su���t����$�+�+�-����?�+�������d�.B�.B��D�O��D�K�#%�D� � !�D���;�;��"�"�=����$�+�+�#N�O�A��"�"�4�?�?�3�A��a��#�q�1�u��H����q����;�;�#�d�o�o�.�.�t�7H�7H�!�D�O��D�K������}�}�(��+�+��0C�0C�',��#��
�
�-�-�/���#�#��/�/�1�1��)�)�
+/��'��3�3�5���
�rc�"�tjS)z�Called after a loseConnection(), when all data has been written.

        Whatever this returns is then returned by doWrite.
        )r�CONNECTION_DONEr#s rrdz"FileDescriptor._postLoseConnection's���#�#�#rc��y�Nr8r#s rrgz$FileDescriptor._closeWriteConnection/s��rc�&�|j|�yrn�rVrTs  r�writeConnectionLostz"FileDescriptor.writeConnectionLost3������F�#rrUc�&�|j|�yrnrprTs  r�readConnectionLostz!FileDescriptor.readConnectionLost7rrrc��t��rnr!r#s r�getHostzFileDescriptor.getHost;���!�#�#rc��t��rnr!r#s r�getPeerzFileDescriptor.getPeer?rwrc�`�t|j�|jz|jkDS)ay
        Determine whether the user-space send buffer for this transport is full
        or not.

        When the buffer contains more than C{self.bufferSize} bytes, it is
        considered full.  This might be improved by considering the size of the
        kernel send buffer and how much of it is free.

        @return: C{True} if it is full, C{False} otherwise.
        )r`rarM�
bufferSizer#s r�_isSendBufferFullz FileDescriptor._isSendBufferFullCs'���4�?�?�#�d�&7�&7�7�$�/�/�I�Irc��|j�@|jr3|j�r"d|_|jj	�yyyy)zY
        Possibly pause a producer, if there is one and the send buffer is full.
        NT)r'r+r|r7�pauseProducingr#s r�_maybePauseProducerz"FileDescriptor._maybePauseProducerPsH��
�=�=�$��)?�)?��%�%�'�&*��#��
�
�,�,�.�(�*@�$rc��t|�|jr|jry|rZ|jj	|�|xj
t
|�z
c_|j�|j�yy)a7Reliably write some data.

        The data is buffered until the underlying file descriptor is ready
        for writing. If there is more than C{self.bufferSize} data in the
        buffer and this descriptor has a registered streaming producer, its
        C{pauseProducing()} method will be called.
        N)	rr0rfrL�appendrMr`rr%r[s  r�writezFileDescriptor.write\sg��	����~�~��!8�!8���� � �'�'��-�����T��*���$�$�&�����	r�iovecc��|D]
}t|��|jr|r|jry|jj	|�|D] }|xj
t
|�z
c_�"|j�|j�y)a
        Reliably write a sequence of data.

        Currently, this is a convenience method roughly equivalent to::

            for chunk in iovec:
                fd.write(chunk)

        It may have a more efficient implementation at a later time or in a
        different reactor.

        As with the C{write()} method, if a buffer size limit is reached and a
        streaming producer is registered, it will be paused until the buffered
        data is written to the underlying file descriptor.
        N)	rr0rfrL�extendrMr`rr%)r$r��is   r�
writeSequencezFileDescriptor.writeSequencems�� �	 �A��Q��	 ��~�~�U�d�.E�.E�����#�#�E�*��	(�A�����Q��'��	(�� � �"����rc�D�|jr�|js�|jrS|j�|j	�|jt
jtj��y|j�|j�d|_yyy)a[Close the connection at the next available opportunity.

        Call this to cause this FileDescriptor to lose its connection.  It will
        first write any data that it has buffered.

        If there is data buffered yet to be written, this method will cause the
        transport to lose its connection as soon as it's done flushing its
        write buffer.  If you have a producer registered, the connection won't
        be closed until the producer is finished. Therefore, make sure you
        unregister your producer when it's finished, or the connection will
        never close.
        rQN)r0r1rfrRrSrVr�Failurerrlr%r#s r�loseConnectionzFileDescriptor.loseConnection�sx���>�>�$�"4�"4��&�&�� � �"�� � �"��#�#�G�O�O�D�4H�4H�$I�J�� � �"��!�!�#�%&��"�#5�>rc�2�d|_|j�y)NT)rer%r#s r�loseWriteConnectionz"FileDescriptor.loseWriteConnection�s��#'�� ����rc�:�|jj|�y)z�Stop waiting for read availability.

        Call this to remove this selectable from being notified when it is
        ready for reading.
        N)rI�removeReaderr#s rrRzFileDescriptor.stopReading����	
���!�!�$�'rc�:�|jj|�y)z�Stop waiting for write availability.

        Call this to remove this selectable from being notified when it is ready
        for writing.
        N)rI�removeWriterr#s rrSzFileDescriptor.stopWriting�r�rc�:�|jj|�y)z$Start waiting for read availability.N)rI�	addReaderr#s r�startReadingzFileDescriptor.startReading�s�������t�$rc�:�|jj|�y)z�Start waiting for write availability.

        Call this to have this FileDescriptor be notified whenever it is ready for
        writing.
        N)rI�	addWriterr#s rr%zFileDescriptor.startWriting�s��	
�����t�$ric�D�|j�|j�y)z�Stop consuming data.

        This is called when a producer has lost its connection, to tell the
        consumer to go lose its connection (and break potential circular
        references).
        N)r2r�r#s r�
stopConsumingzFileDescriptor.stopConsuming�s��	
���!����rc�X�|jr|js|j�yyyrn)r0r1r�r#s rr,zFileDescriptor.resumeProducing�s$���>�>�$�"4�"4�����#5�>rc�$�|j�yrn)rRr#s rr~zFileDescriptor.pauseProducing�s�����rc�$�|j�yrn)r�r#s rr*zFileDescriptor.stopProducing�s�����rc��y)z�File Descriptor number for select().

        This method must be overridden or assigned in subclasses to
        indicate a valid file descriptor for the operating system.
        ���r8r#s r�filenozFileDescriptor.fileno�s��rrn)/r3r4r5r6r0r)r1rerfrarrbrr
�
IReactorFDSetrOrVrr\r^rjrdrgrqrr�rtrvryr|rr�rr�r�r�rRrSr�r%r'r{r�r,r~r*r�r8rrrHrH�s����I��L��M������J�
�F��J�
���)A�)A� B�
��$
�%�
�D�
�	
�9�v$�
�$�$����$�T�$�$�$�J�
/� �%� �D� �"�8�E�?��t��4'�2�(�(�%�%��H��J�� ���rrH�addr�familyr<c�@�t|t�r	|jd�}|tk(r|jdd�d}n,|tk(r|jd�dk7rytd|����	t||�y	#t$rYywxYw#ttf$rYywxYw)
a>
    Determine whether the given string represents an IP address of the given
    family; by default, an IPv4 address.

    @param addr: A string which may or may not be the decimal dotted
        representation of an IPv4 address.
    @param family: The address family to test for; one of the C{AF_*} constants
        from the L{socket} module.  (This parameter has only been available
        since Twisted 17.1.0; previously L{isIPAddress} could only test for IPv4
        addresses.)

    @return: C{True} if C{addr} represents an IPv4 address, C{False} otherwise.
    �asciiF�%rQr�.�zunknown address family T)rr�decode�UnicodeDecodeErrorr�splitr�count�
ValueErrorr�OSError)r�r�s  r�isIPAddressr��s����$���	��;�;�w�'�D�����z�z�#�q�!�!�$��	�7�	��:�:�c�?�a����2�6�*�=�>�>��	�&�$����)"�	��	��$
�� ����s#�A<�/B�<	B�B�B�Bc�"�t|t�S)a2
    Determine whether the given string represents an IPv6 address.

    @param addr: A string which may or may not be the hex
        representation of an IPv6 address.
    @type addr: C{str}

    @return: C{True} if C{addr} represents an IPv6 address, C{False}
        otherwise.
    @rtype: C{bool}
    )r�r)r�s r�
isIPv6Addressr�s���t�X�&�&r)rHr�r�N)$r6�socketrrr�typingrrr�zope.interfacer	rKr
r�twisted.pythonrr
�twisted.python.compatrrrrr>r:�
IPushProducer�IReadWriteDescriptor�	IConsumer�
ITransport�IHalfCloseableDescriptorrHrF�int�boolr�r��__all__r8rr�<module>r�s���
�
0�/�+�+�&�-�+�0�.�:�W �W �t
�Z�
'�
'�(���)��8
�����#�#��������'�'��E�^�Y�E��E�P
*1�%�c�%�3�%�T�%�P'��'��'�=�r

Zerion Mini Shell 1.0