
    ;e,                     F   	 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 Zd ZddZddZed             Zd Zd Zd Z G d dej                  Z G d de          ZdS )   )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                 8    	 t          j        t          |           S N)_impsource_hashr	   )source_bytess    %/usr/lib/python3.11/importlib/util.pyr   r      s    H-|<<<    c                     	 |                      d          s| S |s t          dt          |            d          d}| D ]}|dk    r n|dz  }t          | |d          ||          S )N.zno package specified for z% (required for relative module names)r   r   )
startswithImportErrorreprr   )namepackagelevel	characters       r   resolve_namer       s    <??3 B B Ad4jj A A A B B 	BE  	E
effw666r   c                 *   	 | t           j        vrt          | |          S t           j        |          }|d S 	 |j        }|"t	          d                    |                     |S # t          $ r$ t	          d                    |                     d w xY w)N{}.__spec__ is None{}.__spec__ is not set)sysmodulesr   __spec__
ValueErrorformatAttributeError)r   pathmodulespecs       r   _find_spec_from_pathr-   *   s     3;$%%%T">4	?D | !6!=!=d!C!CDDDK  	N 	N 	N5<<TBBCCM	Ns   A$ $.Bc                 @   	 |                      d          rt          | |          n| }|t          j        vrt|                    d          d         }|rEt          |dg          }	 |j        }n,# t          $ r}t          d|d||          |d }~ww xY wd }t          ||          S t          j        |         }|d S 	 |j
        }|"t          d                    |                     |S # t          $ r$ t          d	                    |                     d w xY w)
Nr   r   __path__)fromlistz __path__ attribute not found on z while trying to find )r   r"   r#   )r   r    r$   r%   
rpartition
__import__r/   r)   ModuleNotFoundErrorr   r&   r'   r(   )	r   r   fullnameparent_nameparentparent_pather+   r,   s	            r   	find_specr9   I   s     /3ooc.B.BL|D'***Hs{""))#..q1 		zlCCCFP$o! P P P)9{ 9 9,49 9?GI I INOPP
 K(K000X&>4	?D | !6!=!=d!C!CDDDK  	N 	N 	N5<<TBBCCM	Ns$   'A/ /
B9BBC/ /.Dc              #   b  K   | t           j        v }t           j                            |           }|s3 t          t                     |           }d|_        |t           j        | <   	 |V  n1# t
          $ r$ |s	 t           j        | = n# t          $ r Y nw xY wY nw xY wd|_        d S # d|_        w xY w)NTF)r$   r%   gettype__initializing__	ExceptionKeyError)r   	is_reloadr+   s      r   _module_to_loadrA   v   s      #I[__T""F # c4 #'"D	(    	K%%   	 #(%''''sN   &A+ *B% +B8BB
BBBBB% BB% %	B.c                 H     	 t          j                    fd            }|S )Nc                      t          j        dt          d            | i |}t          |dd           A|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__rH   hasattrr1   )argskwargsr+   fxns      r   set_package_wrapperz(set_package.<locals>.set_package_wrapper   s     L(Q	8 	8 	8 	8 d%f%%6=$//7!'F6:.. K%+%7%B%B3%G%G%J"r   	functoolswraps)rQ   rR   s   ` r   set_packagerV      s@    
 _S	 	 	 	 	 r   c                 H     	 t          j                    fd            }|S )Nc                     t          j        dt          d            | g|R i |}t          |dd           | |_        |S )NrD   rE   rF   
__loader__)rI   rJ   rK   rL   rY   )selfrO   rP   r+   rQ   s       r   set_loader_wrapperz&set_loader.<locals>.set_loader_wrapper   sg     L(Q	8 	8 	8 	8 T+D+++F++6<..6 $Fr   rS   )rQ   r[   s   ` r   
set_loaderr\      s@    
 _S     r   c                      	 t          j        dt          d           t          j                    fd            }|S )NrD   rE   rF   c                 .   t          |          5 }| |_        	 |                     |          }|r||_        n8|                    d          d         |_        n# t
          t          f$ r Y nw xY w | |g|R i |cd d d            S # 1 swxY w Y   d S )Nr   r   )rA   rY   
is_packagerH   r1   r   r)   )rZ   r4   rO   rP   r+   r_   rQ   s         r   module_for_loader_wrapperz4module_for_loader.<locals>.module_for_loader_wrapper   s   X&& 	6& $FE!__X66
  E)1F&&)1)<)<S)A)A!)DF&&  0    3tV5d555f55	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6s3   B
A+B
A.+B
-A..B

BB)rI   rJ   rK   rT   rU   )rQ   r`   s   ` r   module_for_loaderra      sf    " M H$4 4 4 4 _S6 6 6 6 6 %$r   c                       e Zd Z	 d Zd ZdS )_LazyModulec                 R   	 t           j        | _        | j        j        }| j        j        d         }| j        }i }|                                D ]@\  }}||vr|||<   t          ||                   t          ||                   k    r|||<   A| j        j	        
                    |            |t          j        v rCt          |           t          t          j        |                   k    rt          d|d          | j                            |           t          | |          S )N__dict__zmodule object for z. substituted in sys.modules during a lazy load)types
ModuleType	__class__r&   r   loader_statere   itemsidloaderexec_moduler$   r%   r'   updaterL   )rZ   attroriginal_name
attrs_then	attrs_nowattrs_updatedkeyvalues           r   __getattribute__z_LazyModule.__getattribute__   s7   F ) * ]/
;
M	#//++ 	+ 	+JC *$$%*c""IcN##r*S/':':::%*c"((... CK''$xx2ck-89999  ")m ") ") ") * * *
 	]+++tT"""r   c                 R    	 |                      |           t          | |           d S r   )rv   delattr)rZ   ro   s     r   __delattr__z_LazyModule.__delattr__  s1    = 	d###dr   N)rM   
__module____qualname__rv   ry    r   r   rc   rc      s6        U #  #  #D    r   rc   c                   N    e Zd Z	 ed             Zed             Zd Zd Zd Z	dS )
LazyLoaderc                 D    t          | d          st          d          d S )Nrm   z loader must define exec_module())rN   	TypeError)rl   s    r   __check_eager_loaderzLazyLoader.__check_eager_loader  s0    v}-- 	@>???	@ 	@r   c                 >     	                                   fdS )Nc                  &      | i |          S r   r|   )rO   rP   clsrl   s     r   <lambda>z$LazyLoader.factory.<locals>.<lambda>  s     ss664+B6+B+B'C'C r   )_LazyLoader__check_eager_loader)r   rl   s   ``r   factoryzLazyLoader.factory  s-    L  (((CCCCCCr   c                 >    |                      |           || _        d S r   )r   rl   )rZ   rl   s     r   __init__zLazyLoader.__init__  s!    !!&)))r   c                 6    | j                             |          S r   )rl   create_module)rZ   r,   s     r   r   zLazyLoader.create_module  s    {((...r   c                     	 | j         |j        _         | j         |_        i }|j                                        |d<   |j        |d<   ||j        _        t          |_        d S )Nre   rh   )rl   r&   rY   re   copyrh   ri   rc   )rZ   r+   ri   s      r   rm   zLazyLoader.exec_module"  s_    *!% K
 #)?#7#7#9#9Z $*$4[!'3$&r   N)
rM   rz   r{   staticmethodr   classmethodr   r   r   rm   r|   r   r   r~   r~     s~        U@ @ \@ D D [D
  / / /' ' ' ' 'r   r~   r   ) _abcr   
_bootstrapr   r   r   r   _bootstrap_externalr   r	   r
   r   r   r   
contextlibr   r   rT   r$   rf   rI   r   r    r-   r9   rA   rV   r\   ra   rg   rc   r~   r|   r   r   <module>r      s   3       ( ( ( ( ( ( % % % % % % ( ( ( ( ( ( " " " " " " - - - - - - 2 2 2 2 2 2 2 2 2 2 2 2 . . . . . . 2 2 2 2 2 2 8 8 8 8 8 8 % % % % % %      



  = = =
7 7 7   >* * * *Z ( ( (2  (  $%% %% %%P+ + + + +%" + + +\"' "' "' "' "' "' "' "' "' "'r   