o
    V۷iY                     @   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    | i |}t | |S )N)next)argskwargsgfunc A/home/ubuntu/vllm_env/lib/python3.10/site-packages/ijson/utils.pywrapper   s   zcoroutine.<locals>.wrapperr   )r	   r   r
   r   r   	coroutine   s   r   c                 G   s.   | }|D ]\}}}||g|R i |}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f	coro_func	coro_args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|g|R  }z@| D ]:}z|| W n# ty; } z|D ]}|V  q"t|tr6W Y d}~ W dS  d}~ww |D ]}|V  q>|dd= qW dS  tyc   z|  W Y dS    Y Y dS w )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   	Exception
isinstanceStopIterationGeneratorExitclose)sourcer   eventsr   valueexeventr
   r
   r   	coros2gen-   s2   
r'   N)	functoolsr   r   r   r   r   r'   r
   r
   r
   r   <module>   s
   