o
    Á=a\	  ã                   @   s6   d Z ddlZddlmZ G dd„ dƒZeƒ ZejZdS )zRsupplies the "preloaded" registry to resolve circular module imports at
runtime.

é    Né   )Úcompatc                   @   s*   e Zd ZdZd
dd„Zdd„ Zdd„ Zd	S )Ú_ModuleRegistrya¥  Registry of modules to load in a package init file.

    To avoid potential thread safety issues for imports that are deferred
    in a function, like https://bugs.python.org/issue38884, these modules
    are added to the system module cache by importing them after the packages
    has finished initialization.

    A global instance is provided under the name :attr:`.preloaded`. Use
    the function :func:`.preload_module` to register modules to load and
    :meth:`.import_prefix` to load all the modules that start with the
    given path.

    While the modules are loaded in the global module cache, it's advisable
    to access them using :attr:`.preloaded` to ensure that it was actually
    registered. Each registered module is added to the instance ``__dict__``
    in the form `<package>_<module>`, omitting ``sqlalchemy`` from the package
    name. Example: ``sqlalchemy.sql.util`` becomes ``preloaded.sql_util``.
    úsqlalchemy.c                 C   s   t ƒ | _|| _d S ©N)ÚsetÚmodule_registryÚprefix)Úselfr	   © r   úP/var/www/html/gps/gps/lib/python3.10/site-packages/sqlalchemy/util/_preloaded.pyÚ__init__&   s   
z_ModuleRegistry.__init__c                 G   s   | j  |¡ dd„ S )z¿Adds the specified modules to the list to load.

        This method can be used both as a normal function and as a decorator.
        No change is performed to the decorated object.
        c                 S   s   | S r   r   )Úfnr   r   r   Ú<lambda>1   s    z0_ModuleRegistry.preload_module.<locals>.<lambda>)r   Úupdate)r
   Údepsr   r   r   Úpreload_module*   s   z_ModuleRegistry.preload_modulec                 C   sn   | j D ]1}| jr| | j¡d  dd¡}n|}|r| |¡r4|| jvr4t |tƒ t	ƒ ¡ t
j| | j|< qdS )z\Resolve all the modules in the registry that start with the
        specified path.
        éÿÿÿÿÚ.Ú_N)r   r	   ÚsplitÚreplaceÚ
startswithÚ__dict__r   Úimport_ÚglobalsÚlocalsÚsysÚmodules)r
   ÚpathÚmoduleÚkeyr   r   r   Úimport_prefix3   s   
ÿÿþ€÷z_ModuleRegistry.import_prefixN)r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r"   r   r   r   r   r      s
    
	r   )r&   r   Ú r   r   Ú	preloadedr   r   r   r   r   Ú<module>   s   1
