File: //usr/lib/python3/dist-packages/twisted/internet/__pycache__/_producer_helpers.cpython-38.pyc
U
��W[� � @ sp d Z ddlmZmZ ddlmZ ddlmZ ddlm Z ddl
mZ ddlm
Z
g Zee�G dd � d e��Zd
S )z%
Helpers for working with producers.
� )�division�absolute_import)�implementer)�
IPushProducer)� cooperate)�log)�safe_strc @ sL e Zd ZdZdZdd� Zdd� Zdd� Zd d
� Zdd� Z d
d� Z
dd� ZdS )�_PullToPusha�
An adapter that converts a non-streaming to a streaming producer.
Because of limitations of the producer API, this adapter requires the
cooperation of the consumer. When the consumer's C{registerProducer} is
called with a non-streaming producer, it must wrap it with L{_PullToPush}
and then call C{startStreaming} on the resulting object. When the
consumer's C{unregisterProducer} is called, it must call
C{stopStreaming} on the L{_PullToPush} instance.
If the underlying producer throws an exception from C{resumeProducing},
the producer will be unregistered from the consumer.
@ivar _producer: the underling non-streaming producer.
@ivar _consumer: the consumer with which the underlying producer was
registered.
@ivar _finished: C{bool} indicating whether the producer has finished.
@ivar _coopTask: the result of calling L{cooperate}, the task driving the
streaming producer.
Fc C s || _ || _d S )N)� _producer� _consumer)�selfZpullProducerZconsumer� r
�D/usr/lib/python3/dist-packages/twisted/internet/_producer_helpers.py�__init__3 s z_PullToPush.__init__c c s~ z| j �� W nb t�ddt| j �f � z| j�� W n. t�ddt| j�f � d| _Y Y dS X Y nX dV q dS )z�
A generator that calls C{resumeProducing} on the underlying producer
forever.
If C{resumeProducing} throws an exception, the producer is
unregistered, which should result in streaming stopping.
Nz%%s failed, producing will be stopped:z!%s failed to unregister producer:T)r
�resumeProducingr �errr r ZunregisterProducer� _finished�r r
r
r �_pull8 s
�
�z_PullToPush._pullc C s t | �� �| _dS )z�
This should be called by the consumer when the producer is registered.
Start streaming data to the consumer.
N)r r � _coopTaskr r
r
r �startStreamingT s z_PullToPush.startStreamingc C s | j r
dS d| _ | j�� dS )z�
This should be called by the consumer when the producer is
unregistered.
Stop streaming data to the consumer.
NT)r r �stopr r
r
r �
stopStreaming] s z_PullToPush.stopStreamingc C s | j �� dS )z7
@see: C{IPushProducer.pauseProducing}
N)r �pauser r
r
r �pauseProducingj s z_PullToPush.pauseProducingc C s | j �� dS )z8
@see: C{IPushProducer.resumeProducing}
N)r Zresumer r
r
r r q s z_PullToPush.resumeProducingc C s | � � | j�� dS )z6
@see: C{IPushProducer.stopProducing}
N)r r
�
stopProducingr r
r
r r x s z_PullToPush.stopProducingN)�__name__�
__module__�__qualname__�__doc__r r r r r r r r r
r
r
r r s
r N)r Z
__future__r r Zzope.interfacer Ztwisted.internet.interfacesr Ztwisted.internet.taskr Ztwisted.pythonr Ztwisted.python.reflectr �__all__�objectr r
r
r
r �<module> s