o
    )i                     @   s>  d Z ddlmZ ddlmZ ddlmZmZmZm	Z	 edZ
edZeeedf ed ed e
f Z	 d	ee
 d
ee
 fddZdee
gef d	ee
 d
ee fddZe	dee
e
ge
f d	ee
 d
e
fddZe	deee
gef d	ee
 ded
efddZ	ddedee
ef f d	ee
 ded
ee
ef fddZdS )z5Helper functions to work with nested JSON structures.    )Iterable)reduce)CallableTypeVarUnionoverload_T_UJSONTree[_T])r
   .valuereturnc                 c   s`    t | tr|  D ]	}t|E dH  q
dS t | ttfr+| D ]	}t|E dH  qdS | V  dS )z5Iterate through each leaf in a nested JSON structure.N)
isinstancedictvaluesjson_iter_leaveslisttuple)r   v r   _/home/app/PaddleOCR-VL-test/.venv_paddleocr/lib/python3.10/site-packages/vllm/utils/jsontree.pyr      s   

r   funcc                    sd   t |tr fdd| D S t |tr fdd|D S t |tr.t fdd|D S  |S )z9Apply a function to each leaf in a nested JSON structure.c                    s   i | ]
\}}|t  |qS r   json_map_leaves).0kr   r   r   r   
<dictcomp>"   s    z#json_map_leaves.<locals>.<dictcomp>c                    s   g | ]}t  |qS r   r   r   r   r   r   r   
<listcomp>$   s    z#json_map_leaves.<locals>.<listcomp>c                 3   s    | ]}t  |V  qd S Nr   r   r   r   r   	<genexpr>&   s    z"json_map_leaves.<locals>.<genexpr>)r   r   itemsr   r   r   r   r   r   r   r      s   


r   c                C      d S r   r   r"   r   r   r   json_reduce_leaves+   s   r$   initialc                C   r#   r   r   r   r   r%   r   r   r   r$   4   s   .c                C   s&   |du rt | t|S t | t||S )z
    Apply a function of two arguments cumulatively to each leaf in a
    nested JSON structure, from left to right, so as to reduce the
    sequence to a single value.
    .)r   r   r&   r   r   r   r$   >   s   N).)__doc__collections.abcr   	functoolsr   typingr   r   r   r   r   r	   r   strr   r   ZJSONTreer   r   r$   r   r   r   r   <module>   s\   

