o
    ðpi@	  ã                   @   sT   d Z ddlZddlZe ¡ Zg Zdd„ Zdd„ Zdd„ Z	d	d
„ Z
dd„ Zdd„ ZdS )aÎ  
Default scope function.

`Paddle` manages Scope as programming language's scope.  It just a
thread-local stack of Scope. Top of that stack is current scope, the bottom
of that stack is all scopes' parent.

Invoking `var/find_var`  can `new/find` variable in current scope.
Invoking `enter_local_scope/leave_local_scope` can create or destroy local
scope.

A `scoped_function` will take a `function` as input. That function will be
invoked in a new local scope.
é    Nc                  C   sF   t tddƒ} | du rg t_ttjƒdkrtj tjj ¡ ¡ tjd S )z?
    Get current scope.
    :rtype: paddle.base.core.Scope
    Ú	cur_scopeNr   éÿÿÿÿ)	ÚgetattrÚ__tl_scope__r   ÚlenÚappendÚpaddleÚbaseÚcoreZScope)Zcur_scope_stack© r   úf/home/app/PaddleOCR-VL/.venv_paddleocr/lib/python3.10/site-packages/paddle/base/default_scope_funcs.pyÚget_cur_scope&   s   
r   c                  C   s   t ƒ } |  ¡ }tj |¡ dS )z!
    Enter a new local scope
    N)r   Ú	new_scoper   r   r   )r   r   r   r   r   Úenter_local_scope3   s   r   c                   C   s   t j ¡  tƒ  ¡  dS )z
    Leave local scope
    N)r   r   Úpopr   Z	drop_kidsr   r   r   r   Úleave_local_scope<   s   
r   c                 C   ó   t ƒ  | ¡S )z+
    create variable in current scope.
    )r   Úvar©Únamer   r   r   r   D   ó   r   c                 C   r   )z(
    get variable in current scope.
    )r   Úfind_varr   r   r   r   r   K   r   r   c                 C   s0   t ƒ  zz| ƒ  W n   ‚ W tƒ  dS tƒ  w )zƒ
    invoke `func` in new scope.

    :param func: a callable function that will be run in new scope.
    :type func: callable
    N)r   r   )Úfuncr   r   r   Úscoped_functionR   s   
þr   )Ú__doc__Ú	threadingZpaddle.base.corer   Úlocalr   Ú__all__r   r   r   r   r   r   r   r   r   r   Ú<module>   s   	