
    Vhb                         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	             Zy
)z%
Helpers for working with producers.
    )List)implementer)IPushProducer)	cooperate)Logger__all__c                   >    e Zd ZdZdZd Zd Zd Zd Zd Z	d Z
d	 Zy
)_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                      || _         || _        y )N)	_producer	_consumer)selfpullProducerconsumers      R/home/dcms/DCMS/lib/python3.12/site-packages/twisted/internet/_producer_helpers.py__init__z_PullToPush.__init__3   s    %!    c              #     K   	 t         j                  d| j                        5 }| j                  j                          ddd       j                  rXt         j                  d| j
                        5 }| j
                  j                          ddd       j                  rd| _        yd # 1 sw Y   rxY w# 1 sw Y   .xY ww)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
handlingops      r   _pullz_PullToPush._pull7   s      %%= &  1..01 yy))D!^^ *  8  NN557	8
 $$ &*DNJ! 1 1
8 8s4   #C	B1 5C	5B=!C	1B:6C	=CC	c                 @    t        | j                               | _        y)z
        This should be called by the consumer when the producer is registered.

        Start streaming data to the consumer.
        N)r   r   	_coopTaskr   s    r   startStreamingz_PullToPush.startStreamingQ   s     #4::<0r   c                 `    | j                   ryd| _         | j                  j                          y)z
        This should be called by the consumer when the producer is
        unregistered.

        Stop streaming data to the consumer.
        NT)r   r    stopr!   s    r   stopStreamingz_PullToPush.stopStreamingY   s%     >>r   c                 8    | j                   j                          y)z7
        @see: C{IPushProducer.pauseProducing}
        N)r    pauser!   s    r   pauseProducingz_PullToPush.pauseProducinge   s     	r   c                 8    | j                   j                          y)z8
        @see: C{IPushProducer.resumeProducing}
        N)r    resumer!   s    r   r   z_PullToPush.resumeProducingk   s     	r   c                 X    | j                          | j                  j                          y)z6
        @see: C{IPushProducer.stopProducing}
        N)r%   r   stopProducingr!   s    r   r,   z_PullToPush.stopProducingq   s      	$$&r   N)__name__
__module____qualname____doc__r   r   r   r"   r%   r(   r   r,    r   r   r
   r
      s1    0 I"41
 'r   r
   N)r0   typingr   zope.interfacer   twisted.internet.interfacesr   twisted.internet.taskr   twisted.loggerr   r   r   str__annotations__r
   r1   r   r   <module>r9      sS   
  & 5 + !x c  ]^' ^' ^'r   