o
    1/ÊiÝ  ã                   @   s`   d Z ddlmZ ddlmZ defdd„Zdedd	fd
d„Zedefdd„ƒZde	fdd„Z
d	S )z"Global configuration for XGrammar.é    )Úcontextmanageré   )Ú_coreÚreturnc                   C   ó
   t j ¡ S )a¾  Get the maximum allowed recursion depth. The depth is shared per process.

    The maximum recursion depth is determined in the following order:

    1. Manually set via :py:func:`set_max_recursion_depth`
    2. ``XGRAMMAR_MAX_RECURSION_DEPTH`` environment variable (if set and is a valid integer <= 1,000,000)
    3. Default value of 10,000

    Returns
    -------
    max_recursion_depth : int
        The maximum allowed recursion depth.
    )r   ÚconfigÚget_max_recursion_depth© r	   r	   ú\/lsinfo/ai/hellotax_ai/llm_service/venv_vllm/lib/python3.10/site-packages/xgrammar/config.pyr      s   
r   Úmax_recursion_depthNc                 C   s   t j | ¡ dS )zØSet the maximum allowed recursion depth. The depth is shared per process. This method is
    thread-safe.

    Parameters
    ----------
    max_recursion_depth : int
        The maximum allowed recursion depth.
    N)r   r   Úset_max_recursion_depth)r   r	   r	   r
   r      s   	r   Ú
temp_depthc                 c   s0    t ƒ }t| ƒ z
dV  W t|ƒ dS t|ƒ w )zòA context manager for temporarily setting recursion depth.

    Examples
    --------
    >>> with recursion_depth(1000):
    ...     # recursion depth is 1000 here
    ...     pass
    >>> # recursion depth is restored to original value
    N)r   r   )r   Ú
prev_depthr	   r	   r
   r   %   s   €c                   C   r   )zªGet the serialization version number. The current version is "v4".

    Returns
    -------
    serialization_version : str
        The serialization version number.
    )r   r   Úget_serialization_versionr	   r	   r	   r
   r   8   s   
r   )Ú__doc__Ú
contextlibr   Úbaser   Úintr   r   r   Ústrr   r	   r	   r	   r
   Ú<module>   s    