File: //usr/lib/python3/dist-packages/twisted/internet/__pycache__/abstract.cpython-38.pyc
U
W[JK � @ s d Z ddlmZmZ ddlmZmZmZmZ ddl m
Z
ddlmZm
Z
mZ ddlmZmZ ddlmZmZ erzdd � Zndd
lmZ dd � ZG dd
� d
e�Ze
ej�G dd� de��Ze
ejejejejej �G dd� dee��Z!efdd�Z"dd� Z#dddgZ$dS )z+
Support for generic select()able objects.
� )�division�absolute_import)�AF_INET�AF_INET6� inet_pton�error)�implementer)�unicode�
lazyByteSlice�_PY3)�reflect�failure)�
interfaces�mainc C s d� t| �|d � g| �S �N� )�join�
memoryview�ZbObj�offsetZbArray� r �;/usr/lib/python3/dist-packages/twisted/internet/abstract.py�_concatenate s r )�bufferc C s t | |�d�|� S r )r r r r r r r s c @ s4 e Zd ZdZdZdZdZdd� Zdd� Zdd � Z dS )
�_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 C s t d��dS )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 startWritingN)�NotImplementedError��selfr r r �startWritingM s z_ConsumerMixin.startWritingc C sH | j dk rtd|| j f ��| jr,|�� n|| _ || _|sD|�� dS )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.
NzHCannot register producer %s, because producer %s was never unregistered.)�producer�RuntimeError�disconnected�
stopProducing�streamingProducer�resumeProducing)r r Z streamingr r r �registerProducerW s
��
z_ConsumerMixin.registerProducerc C s d| _ | jr| jr| �� dS )zM
Stop consuming data from a producer, without disconnecting.
N)r � connected�
disconnectingr r r r r �unregisterProducert s z!_ConsumerMixin.unregisterProducer)
�__name__�
__module__�__qualname__�__doc__r �producerPausedr# r r% r( r r r r r # s %
r c @ s e Zd ZdZdd� Zdd� ZdS )� _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.
c C s t j�|�r|�� S |jjS )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 �ILoggingContextZ
providedBy� logPrefix� __class__r) )r ZapplicationObjectr r r �
_getLogPrefix� s z_LogOwner._getLogPrefixc C s dS )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.
�-r r r r r r0 � s z_LogOwner.logPrefixN)r) r* r+ r, r2 r0 r r r r r. ~ s
r. c @ s e Zd ZdZdZdZdZdZdZdZ dZ
dZd8dd�Zd d
� Z
dd� Zd
d� Zdd� Zdd� Zdd� Zdd� Zdd� Zdd� Zdd� Zdd� Zdd � Ze�ej�fd!d"�Zd#d$� Zd%d&� Zd'd(� Z d)d*� Z!d+d,� Z"dZ#d-Z$d.d/� Z%d0d1� Z&d2d3� Z'd4d5� Z(d6d7� Z)dS )9�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).
r Fr i Nc C s&