o
    Û)iÊ  ã                   @   sR   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	S )z"Global configuration for XGrammar.é    )Úcontextmanageré   )Ú_coreÚreturnc                   C   s
   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   ú[/home/app/PaddleOCR-VL-test/.venv_paddleocr/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   Z
prev_depthr   r   r	   r
   %   s   €)	Ú__doc__Ú
contextlibr   Úbaser   Úintr   r   r
   r   r   r   r	   Ú<module>   s    