
    /JfE                         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
 ddlmZ g Zee         ed<    ee           G d	 d
                      ZdS )z%
Helpers for working with producers.
    )List)implementer)IPushProducer)	cooperate)log)safe_str__all__c                   @    e Zd ZdZdZd Zd Zd Zd Zd Z	d Z
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                 "    || _         || _        d S )N)	_producer	_consumer)selfpullProducerconsumers      e/home/alex/cs2snipeproduction/venv/lib/python3.11/site-packages/twisted/internet/_producer_helpers.py__init__z_PullToPush.__init__2   s    %!    c              #   x  K   	 	 | j                                          n# t          $ r t          j        dt          | j                   d           	 | j                                         nC# t          $ r6 t          j        dt          | j                  d           d| _        Y Y dS w xY wY nw xY wdV  )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.
        TNz# failed, producing will be stopped:z failed to unregister producer:)	r   resumeProducingBaseExceptionr   errr   r   unregisterProducer	_finishedr   s    r   _pullz_PullToPush._pull6   s     	..0000    ////2  
N557777 % 	 	 	 G#DN33336  
 &*DNFFF	 87( JJJ/	s3    4B4A.-B4.;B.)B4-B..B43B4c                 R    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   	_coopTaskr   s    r   startStreamingz_PullToPush.startStreamingW   s     #4::<<00r   c                 X    | 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   s    r   stopStreamingz_PullToPush.stopStreaming_   s4     > 	Fr   c                 8    | j                                          dS )z7
        @see: C{IPushProducer.pauseProducing}
        N)r   pauser   s    r   pauseProducingz_PullToPush.pauseProducingk   s     	r   c                 8    | j                                          dS )z8
        @see: C{IPushProducer.resumeProducing}
        N)r   resumer   s    r   r   z_PullToPush.resumeProducingq   s     	r   c                 `    |                                   | j                                         dS )z6
        @see: C{IPushProducer.stopProducing}
        N)r"   r   stopProducingr   s    r   r)   z_PullToPush.stopProducingw   s0     	$$&&&&&r   N)__name__
__module____qualname____doc__r   r   r   r   r"   r%   r   r)    r   r   r   r      s         0 I" " "  B1 1 1
 
 
       ' ' ' ' 'r   r   N)r-   typingr   zope.interfacer   twisted.internet.interfacesr   twisted.internet.taskr   twisted.pythonr   twisted.python.reflectr   r	   str__annotations__r   r.   r   r   <module>r7      s   
         & & & & & & 5 5 5 5 5 5 + + + + + +       + + + + + + c    ]e' e' e' e' e' e' e' e' e' e'r   