o
    >hb                     @   sr   U d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 e
 Zg Zee ed< eeG dd	 d	Zd
S )z%
Helpers for working with producers.
    )List)implementer)IPushProducer)	cooperate)Logger__all__c                   @   sL   e Zd ZdZdZdd Zdd Zdd Zd	d
 Zdd Z	dd Z
dd ZdS )_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)selfpullProducerconsumer r   /var/www/vedio/testing/chatpythonscript.ninositsolution.com/env/lib/python3.10/site-packages/twisted/internet/_producer_helpers.py__init__3   s   
z_PullToPush.__init__c                 c   s    	 t jd| jd}| j  W d   n1 sw   Y  |jrGt jd| jd}| j  W d   n1 s:w   Y  |jrGd| _dS dV  q)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.
        Tz+while calling resumeProducing on {producer})producerNz.while calling unregisterProducer on {consumer})r   )_logfailuresHandledr	   resumeProducingfailedr
   unregisterProducer	_finished)r   op
handlingopr   r   r   _pull7   s*   z_PullToPush._pullc                 C   s   t |  | _dS )z
        This should be called by the consumer when the producer is registered.

        Start streaming data to the consumer.
        N)r   r   	_coopTaskr   r   r   r   startStreamingQ   s   z_PullToPush.startStreamingc                 C   s   | j rdS d| _ | j  dS )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   stopStreamingY   s   z_PullToPush.stopStreamingc                 C      | j   dS )z7
        @see: C{IPushProducer.pauseProducing}
        N)r   pauser   r   r   r   pauseProducinge      z_PullToPush.pauseProducingc                 C   r    )z8
        @see: C{IPushProducer.resumeProducing}
        N)r   resumer   r   r   r   r   k   r#   z_PullToPush.resumeProducingc                 C   s   |    | j  dS )z6
        @see: C{IPushProducer.stopProducing}
        N)r   r	   stopProducingr   r   r   r   r%   q   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)   typingr   zope.interfacer   twisted.internet.interfacesr   twisted.internet.taskr   twisted.loggerr   r   r   str__annotations__r   r   r   r   r   <module>   s   