Ë
    ojE  ã                   ó�   — 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y)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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      úD/usr/lib/python3/dist-packages/twisted/internet/_producer_helpers.pyÚ__init__z_PullToPush.__init__2   s   € Ø%ˆŒØ!ˆ�ó    c              #   ó€  K  — 	 	 | j                   j                  «        d–— Œ # t        $ rŽ t        j                  dt        | j                   «      ›d�«       	 | j                  j                  «        nC# t        $ r7 t        j                  dt        | j                  «      ›d�«       d| _        Y Y yw xY wY Œ›w 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.
        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ð* ŠJð/ øô !ò Ü—‘Øä §¡Õ/ð2ôð
Ø—N‘N×5Ñ5Õ7øô %ò 	ô —G‘GØä# D§N¡NÕ3ð6ôð
 &*�D”NÚð	úñ 8ðüsO   ‚B>…$ ŸB>¤5B;ÁA5Á4B;Á5<B5Â1B;Â2B>Â4B5Â5B;Â8B>Â:B;Â;B>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   Ú	_coopTaskr   s    r   ÚstartStreamingz_PullToPush.startStreamingW   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.stopStreaming_   s%   € ð �>Š>ØØˆŒØ�‰×ÑÕr   c                 ó8   — | j                   j                  «        y)z7
        @see: C{IPushProducer.pauseProducing}
        N)r   Úpauser   s    r   ÚpauseProducingz_PullToPush.pauseProducingk   s   € ð 	�‰×ÑÕr   c                 ó8   — | j                   j                  «        y)z8
        @see: C{IPushProducer.resumeProducing}
        N)r   Úresumer   s    r   r   z_PullToPush.resumeProducingq   s   € ð 	�‰×ÑÕr   c                 óX   — | j                  «        | j                  j                  «        y)z6
        @see: C{IPushProducer.stopProducing}
        N)r"   r   ÚstopProducingr   s    r   r)   z_PullToPush.stopProducingw   s    € ð 	×ÑÔØ�‰×$Ñ$Õ&r   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r"   r%   r   r)   © r   r   r   r      s2   „ ñð0 €Iò"òòB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      sO   ðò
õ å &å 5Ý +Ý Ý +ð €ˆˆc‰Ó ñ ˆ]Ó÷e'ð e'ó ñe'r   