U
    ×€»d  ã                   @   s8   d dl mZ dd„ Zdd„ ZG dd„ deƒZdd	„ Zd
S )é    ©Úwrapsc                    s   t ˆ ƒ‡ fdd„ƒ}|S )zè
    Wraps a generator which is intended to be used as a pure coroutine by
    .send()ing it values. The only thing that the wrapper does is calling
    .next() for the first time which is required by Python generator protocol.
    c                     s   ˆ | |Ž}t |ƒ |S )N)Únext)ÚargsÚkwargsÚg©Úfunc© ú^/mounts/lovelace/software/anaconda3/envs/rescript-2/lib/python3.8/site-packages/ijson/utils.pyÚwrapper   s    
zcoroutine.<locals>.wrapperr   )r	   r   r
   r   r   Ú	coroutine   s    r   c                 G   s(   | }|D ]\}}}||f|ž|Ž}q|S )aT  
    Chains together a sink and a number of coroutines to form a coroutine
    pipeline. The pipeline works by calling send() on the coroutine created with
    the information in `coro_pipeline[-1]`, which sends its results to the
    coroutine created from `coro_pipeline[-2]`, and so on, until the final
    result is sent to `sink`.
    r
   )ÚsinkÚcoro_pipelineÚfZ	coro_funcZ	coro_argsZcoro_kwargsr
   r
   r   Úchain   s    r   c                   @   s   e Zd ZdZejZdS )Úsendable_lista[  
    A list that mimics a coroutine receiving values.

    Coroutine are sent values via their send() method. This class defines such a
    method so that values sent into it are appended into the list, which can be
    inspected later. As such, this type can be used as an "accumulating sink" in
    a pipeline consisting on many coroutines.
    N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚlistÚappendÚsendr
   r
   r
   r   r   !   s   r   c              	   g   sª   t ƒ }t|f|žŽ }zb| D ]X}z| |¡ W n* tk
rV   |D ]
}|V  q@Y  W dS X |D ]
}|V  q\|dd…= qW n. tk
r¤   z| ¡  W n   Y nX Y nX dS )z¡
    A utility function that returns a generator yielding values dispatched by a
    coroutine pipeline after *it* has received values coming from `source`.
    N)r   r   r   ÚStopIterationÚGeneratorExitÚclose)Úsourcer   Úeventsr   ÚvalueÚeventr
   r
   r   Ú	coros2gen-   s$    r!   N)Ú	functoolsr   r   r   r   r   r!   r
   r
   r
   r   Ú<module>   s   