o
    K+g,                     @   s*  d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm	Z	 ddlm
Z
 dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlZddlZddlZddlZddlZdd Zdd Zd$ddZd$ddZedd Zdd Zdd Zdd ZG d d! d!ejZG d"d# d#eZ dS )%z-Utility code for constructing importers, etc.   )Loader)module_from_spec)_resolve_name)spec_from_loader)
_find_spec)MAGIC_NUMBER)_RAW_MAGIC_NUMBER)cache_from_source)decode_source)source_from_cache)spec_from_file_location    )contextmanagerNc                 C   s   t t| S )zBReturn the hash of *source_bytes* as used in hash-based pyc files.)_impsource_hashr   )source_bytes r   @/var/www/html/squashfs-root/usr/lib/python3.10/importlib/util.pyr      s   r   c                 C   s\   |  ds| S |stdt|  dd}| D ]}|dkr n|d7 }qt| |d ||S )z2Resolve a relative module name to an absolute one..zno package specified for z% (required for relative module names)r   r   N)
startswithImportErrorreprr   )namepackagelevel	characterr   r   r   resolve_name   s   

r   c                 C   sn   | t jvr
t| |S t j|  }|du rdS z|j}W n ty)   td| dw |du r5td| |S )a  Return the spec for the specified module.

    First, sys.modules is checked to see if the module was already imported. If
    so, then sys.modules[name].__spec__ is returned. If that happens to be
    set to None, then ValueError is raised. If the module is not in
    sys.modules, then sys.meta_path is searched for a suitable spec with the
    value of 'path' given to the finders. None is returned if no spec could
    be found.

    Dotted names do not have their parent packages implicitly imported. You will
    most likely need to explicitly import all parent packages in the proper
    order for a submodule to get the correct spec.

    N{}.__spec__ is not set{}.__spec__ is None)sysmodulesr   __spec__AttributeError
ValueErrorformat)r   pathmodulespecr   r   r   _find_spec_from_path*   s   



r(   c           	   
   C   s   |  dr
t| |n| }|tjvrG|dd }|r@t|dgd}z|j}W n ty? } ztd|d||d|d}~ww d}t	||S tj| }|du rRdS z|j
}W n tyf   td	| dw |du rrtd
| |S )a  Return the spec for the specified module.

    First, sys.modules is checked to see if the module was already imported. If
    so, then sys.modules[name].__spec__ is returned. If that happens to be
    set to None, then ValueError is raised. If the module is not in
    sys.modules, then sys.meta_path is searched for a suitable spec with the
    value of 'path' given to the finders. None is returned if no spec could
    be found.

    If the name is for submodule (contains a dot), the parent module is
    automatically imported.

    The name and package arguments work the same as importlib.import_module().
    In other words, relative module names (with leading dots) work.

    r   r   __path__)fromlistz __path__ attribute not found on z while trying to find )r   Nr   r   )r   r   r   r    
rpartition
__import__r)   r"   ModuleNotFoundErrorr   r!   r#   r$   )	r   r   fullnameparent_nameparentparent_pather&   r'   r   r   r   	find_specI   s>   




r3   c                 c   s    | t jv }t j| }|stt | }d|_|t j| < z-z|V  W n ty=   |s;zt j| = W n	 ty:   Y nw Y nw W d|_d S W d|_d S d|_w )NTF)r   r    gettypeZ__initializing__	ExceptionKeyError)r   	is_reloadr&   r   r   r   _module_to_loadv   s,   



 r9   c                       t   fdd}|S )zOSet __package__ on the returned module.

    This function is deprecated.

    c                     sV   t jdtdd  | i |}t|dd d u r)|j|_t|ds)|jdd |_|S )NkThe import system now takes care of this automatically; this decorator is slated for removal in Python 3.12   
stacklevel__package__r)   r   r   )warningswarnDeprecationWarninggetattr__name__r?   hasattrr+   )argskwargsr&   fxnr   r   set_package_wrapper   s   
z(set_package.<locals>.set_package_wrapper	functoolswraps)rI   rJ   r   rH   r   set_package   s   
rN   c                    r:   )zNSet __loader__ on the returned module.

    This function is deprecated.

    c                    s@   t jdtdd  | g|R i |}t|dd d u r| |_|S )Nr;   r<   r=   
__loader__)r@   rA   rB   rC   rO   )selfrF   rG   r&   rH   r   r   set_loader_wrapper   s   z&set_loader.<locals>.set_loader_wrapperrK   )rI   rQ   r   rH   r   
set_loader   s   rR   c                    s*   t jdtdd t  fdd}|S )a*  Decorator to handle selecting the proper module for loaders.

    The decorated function is passed the module to use instead of the module
    name. The module passed in to the function is either from sys.modules if
    it already exists or is a new module. If the module is new, then __name__
    is set the first argument to the method, __loader__ is set to self, and
    __package__ is set accordingly (if self.is_package() is defined) will be set
    before it is passed to the decorated function (if self.is_package() does
    not work for the module it will be set post-load).

    If an exception is raised and the decorator created the module it is
    subsequently removed from sys.modules.

    The decorator assumes that the decorated function takes the module name as
    the second argument.

    r;   r<   r=   c              
      s   t |8}| |_z| |}W n ttfy   Y nw |r!||_n|dd |_ | |g|R i |W  d    S 1 s?w   Y  d S )Nr   r   )r9   rO   
is_packager   r"   r?   r+   )rP   r.   rF   rG   r&   rS   rH   r   r   module_for_loader_wrapper   s   
$z4module_for_loader.<locals>.module_for_loader_wrapper)r@   rA   rB   rL   rM   )rI   rT   r   rH   r   module_for_loader   s   rU   c                   @   s    e Zd ZdZdd Zdd ZdS )_LazyModulezKA subclass of the module type which triggers loading upon attribute access.c                 C   s   t j| _| jj}| jjd }| j}i }| D ]\}}||vr$|||< qt|| t|| kr4|||< q| jj	
|  |tjv rTt| ttj| krTtd|d| j| t| |S )z8Trigger the load of the module and return the attribute.__dict__zmodule object for z. substituted in sys.modules during a lazy load)types
ModuleType	__class__r!   r   loader_staterW   itemsidloaderexec_moduler   r    r#   updaterC   )rP   attrZoriginal_nameZ
attrs_thenZ	attrs_nowZattrs_updatedkeyvaluer   r   r   __getattribute__   s"   


z_LazyModule.__getattribute__c                 C   s   |  | t| | dS )z/Trigger the load and then perform the deletion.N)rd   delattr)rP   ra   r   r   r   __delattr__  s   
z_LazyModule.__delattr__N)rD   
__module____qualname____doc__rd   rf   r   r   r   r   rV      s    "rV   c                   @   s@   e Zd ZdZedd Zedd Zdd Zdd	 Z	d
d Z
dS )
LazyLoaderzKA loader that creates a module which defers loading until attribute access.c                 C   s   t | ds	tdd S )Nr_   z loader must define exec_module())rE   	TypeError)r^   r   r   r   Z__check_eager_loader  s   
zLazyLoader.__check_eager_loaderc                    s       fddS )z>Construct a callable which returns the eager loader made lazy.c                     s    | i |S Nr   )rF   rG   clsr^   r   r   <lambda>  s    z$LazyLoader.factory.<locals>.<lambda>)_LazyLoader__check_eager_loaderrm   r   rm   r   factory  s   
zLazyLoader.factoryc                 C   s   |  | || _d S rl   )rp   r^   )rP   r^   r   r   r   __init__  s   

zLazyLoader.__init__c                 C   s   | j |S rl   )r^   create_module)rP   r'   r   r   r   rs     s   zLazyLoader.create_modulec                 C   s@   | j |j_ | j |_i }|j |d< |j|d< ||j_t|_dS )zMake the module load lazily.rW   rZ   N)r^   r!   rO   rW   copyrZ   r[   rV   )rP   r&   r[   r   r   r   r_   "  s   


zLazyLoader.exec_moduleN)rD   rg   rh   ri   staticmethodrp   classmethodrq   rr   rs   r_   r   r   r   r   rj     s    

rj   rl   )!ri   _abcr   
_bootstrapr   r   r   r   _bootstrap_externalr   r   r	   r
   r   r   
contextlibr   r   rL   r   rX   r@   r   r   r(   r3   r9   rN   rR   rU   rY   rV   rj   r   r   r   r   <module>   s:    

-
(.