
    Rh                     
   d Z d ZdZdZdZdad Zd Z G d de      Z	 G d d      Z
i Zda G d	 d
      Z G d de      Zd Z G d d      Z G d d      Z G d d      Zd Zd Zd ZdddZd Zd Zd Zd Z G d d      Zddd d!ZdBd"Zd#d$d%Zd& Z d' Z!d( Z"d) Z#d* Z$d+ Z% G d, d-      Z& G d. d/      Z' G d0 d1      Z(d2 Z)dCd3Z*d4 Z+d5Z,e,d6z   Z-d7 Z. e/       Z0d8 Z1dDd9Z2d#d:d;Z3d< Z4dEd=Z5d> Z6d? Z7d@ Z8dA Z9y)FaS  Core implementation of import.

This module is NOT meant to be directly imported! It has been designed such
that it can be bootstrapped into Python as the implementation of import. As
such it requires the injection of specific modules and attributes in order to
work. One should use importlib as the public-facing version of this module.

c                 d    	 | j                   S # t        $ r t        |       j                   cY S w xY wN)__qualname__AttributeErrortype)objs    +/usr/lib/python3.12/importlib/_bootstrap.py_object_namer	      s2    & &Cy%%%&s    //Nc           	          dD ]&  }t        ||      st        | |t        ||             ( | j                  j	                  |j                         y)z/Simple substitute for functools.update_wrapper.)
__module____name__r   __doc__N)hasattrsetattrgetattr__dict__update)newoldreplaces      r   _wrapr   (   sF    H 93 C'#w"789 LL%    c                 ,     t        t              |       S r   )r   sysnames    r   _new_moduler   0   s    49T?r   c                       e Zd Zy)_ListNr   r   r    r   r   r   r   7       r   r   c                   .    e Zd Zd Zd Zd ZddZddZy)_WeakValueDictionaryc                     t         j                  |        G fddt         j                        }|| _        | j                          y )Nc                   B     e Zd ZdZ fdZ fdZefd       Z xZS )/_WeakValueDictionary.__init__.<locals>.KeyedRef)keyc                 L    t         |   | || j                        }||_        |S r   )super__new__remover'   )r   obr'   self	__class__s       r   r*   z7_WeakValueDictionary.__init__.<locals>.KeyedRef.__new__J   s%    wtR=r   c                 :    t         |   || j                         y r   )r)   __init__r+   )r-   r,   r'   r.   s      r   r0   z8_WeakValueDictionary.__init__.<locals>.KeyedRef.__init__O   s     T[[1r   c                             }|]|j                   r&|j                  j                  | j                         y t        j                  |j                  | j                         y y r   )
_iterating_pending_removalsappendr'   _weakref_remove_dead_weakrefdata)wrr-   self_weakrefs     r   r+   z6_WeakValueDictionary.__init__.<locals>.KeyedRef.removeR   sN     $~#..55bff= 55diiH	 $r   )	r   r   r   	__slots__r*   r0   staticmethodr+   __classcell__)r.   r9   s   @r   KeyedRefr&   F   s(    I
2 I Ir   r=   )r5   ref	_KeyedRefclear)r-   r=   r9   s     @r   r0   z_WeakValueDictionary.__init__@   s5    ||D)
	Ix|| 	I. "

r   c                 >    g | _         t               | _        i | _        y r   )r3   setr2   r7   r-   s    r   r@   z_WeakValueDictionary.clear`   s    !#%	r   c                     | j                   j                  }| j                  }	 	  |       }t        j                  ||       # t        $ r Y y w xY wr   )r3   popr7   
IndexErrorr5   r6   )r-   rE   dr'   s       r   _commit_removalsz%_WeakValueDictionary._commit_removalse   sV    $$((IIe ))!S1   s   A 	AANc                     | j                   r| j                          	 | j                  |   } |       x}|S |S # t        $ r |cY S w xY wr   )r3   rH   r7   KeyError)r-   r'   defaultr8   os        r   getz_WeakValueDictionary.geto   sW    !!!!#	3B T	"  	N	s   : AAc                     	  | j                   |          }|=| j                  r| j                          | j	                  ||      | j                   |<   |S |S # t        $ r d }Y Nw xY wr   )r7   rJ   r3   rH   r?   )r-   r'   rK   rL   s       r   
setdefaultz_WeakValueDictionary.setdefault|   sm    			# A 9%%%%'!^^GS9DIIcNNH  	A	s   A A%$A%r   )r   r   r   r0   r@   rH   rM   rO   r    r   r   r#   r#   >   s    @
2r   r#   c                   "    e Zd ZdZd Zd Zd Zy)_BlockingOnManagerz;A context manager responsible to updating ``_blocking_on``.c                      || _         || _        y r   )	thread_idlock)r-   rS   rT   s      r   r0   z_BlockingOnManager.__init__   s    "	r   c                     t         j                  | j                  t                     | _        | j                  j                  | j                         y)zCMark the running thread as waiting for self.lock. via _blocking_on.N)_blocking_onrO   rS   r   
blocked_onr4   rT   rC   s    r   	__enter__z_BlockingOnManager.__enter__   s4     '11$..%'Jtyy)r   c                 N    | j                   j                  | j                         y)z6Remove self.lock from this thread's _blocking_on list.N)rW   r+   rT   r-   argskwargss      r   __exit__z_BlockingOnManager.__exit__   s    tyy)r   N)r   r   r   r   r0   rX   r]   r    r   r   rQ   rQ      s    E	**r   rQ   c                       e Zd Zy)_DeadlockErrorNr   r    r   r   r_   r_      r!   r   r_   c                    | |v ry|D ]W  }|j                  |      x}s||v r y|j                  |       |D cg c]  }|j                   }}t        | |||      sW y yc c}w )a  Check if 'target_id' is holding the same lock as another thread(s).

    The search within 'blocking_on' starts with the threads listed in
    'candidate_ids'.  'seen_ids' contains any threads that are considered
    already traversed in the search.

    Keyword arguments:
    target_id     -- The thread id to try to reach.
    seen_ids      -- A set of threads that have already been visited.
    candidate_ids -- The thread ids from which to begin.
    blocking_on   -- A dict representing the thread/blocking-on graph.  This may
                     be the same object as the global '_blocking_on' but it is
                     a parameter to reduce the impact that global mutable
                     state has on the result of this function.
    TF)seen_idscandidate_idsblocking_on)rM   addowner_has_deadlocked)	target_idra   rb   rc   tidcandidate_blocking_onrT   edgess           r   rf   rf      s      M!   )4)==%=H_
 S )>>>>9xu')!$  ?s   A#c                   .    e Zd ZdZd Zd Zd Zd Zd Zy)_ModuleLockzA recursive lock implementation which is able to detect deadlocks
    (e.g. thread 1 trying to take locks A then B, and thread 2 trying to
    take locks B then A).
    c                     t         j                         | _        t         j                         | _        || _        d | _        g | _        g | _        y r   )	_threadRLockrT   allocate_lockwakeupr   re   countwaitersr-   r   s     r   r0   z_ModuleLock.__init__   sE    * MMO	++- 	 
 
 r   c                 r    t        t        j                         t               | j                  gt
              S )N)rg   ra   rb   rc   )rf   rn   	get_identrB   re   rV   rC   s    r   has_deadlockz_ModuleLock.has_deadlock   s0    
 '')U  ::,$	
 		
r   c                 V   t         j                         }t        ||       5  	 | j                  5  | j                  g k(  s| j
                  |k(  r4|| _        | j                  j                  d       	 ddd       ddd       y| j                         rt        d|       | j                  j                  d      r| j                  j                  d       ddd       | j                  j                          | j                  j                          # 1 sw Y   >xY w# 1 sw Y   yxY w)z
        Acquire the module lock.  If a potential deadlock is detected,
        a _DeadlockError is raised.
        Otherwise, the lock is always acquired and True is returned.
        TNzdeadlock detected by F)rn   rv   rQ   rT   rr   re   r4   rw   r_   rq   acquirers   releaser-   rh   s     r   ry   z_ModuleLock.acquire0  s    !T* ;	& YY ,2zzR'4::+< &)


))$/#,2;	& ;	&D ((*,/DTH-MNN {{**51++D1Y,2b ##%
 ##%u ,2 ,2;	& ;	&s0   DAD1DAD=DD	DD(c                    t         j                         }| j                  5  | j                  |k7  rt	        d      t        | j                        dkD  sJ | j                  j                          t        | j                        sSd | _        t        | j                        dkD  r4| j                  j                          | j                  j                          d d d        y # 1 sw Y   y xY w)Ncannot release un-acquired lock    )rn   rv   rT   re   RuntimeErrorlenrr   rE   rs   rq   rz   r{   s     r   rz   z_ModuleLock.releaset  s    !YY 		*zzS "#DEEtzz?Q&&&JJNNtzz?!
t||$q(LL$$&KK'')		* 		* 		*s   B7C!!C*c                 8    d| j                   dt        |        S )Nz_ModuleLock() at r   idrC   s    r   __repr__z_ModuleLock.__repr__  s    dii]%4z::r   N)	r   r   r   r   r0   rw   ry   rz   r   r    r   r   rl   rl      s#    
6p
 B&H*;r   rl   c                   (    e Zd ZdZd Zd Zd Zd Zy)_DummyModuleLockzVA simple _ModuleLock equivalent for Python builds without
    multi-threading support.c                      || _         d| _        y Nr~   )r   rr   rt   s     r   r0   z_DummyModuleLock.__init__  s    	
r   c                 .    | xj                   dz  c_         y)N   T)rr   rC   s    r   ry   z_DummyModuleLock.acquire  s    

a
r   c                 b    | j                   dk(  rt        d      | xj                   dz  c_         y )Nr~   r}   r   )rr   r   rC   s    r   rz   z_DummyModuleLock.release  s&    ::?@AA

a
r   c                 8    d| j                   dt        |        S )Nz_DummyModuleLock(r   r   rC   s    r   r   z_DummyModuleLock.__repr__  s    "499-uRXJ??r   N)r   r   r   r   r0   ry   rz   r   r    r   r   r   r     s     
@r   r   c                       e Zd Zd Zd Zd Zy)_ModuleLockManagerc                      || _         d | _        y r   )_name_lockrt   s     r   r0   z_ModuleLockManager.__init__  s    

r   c                 l    t        | j                        | _        | j                  j                          y r   )_get_module_lockr   r   ry   rC   s    r   rX   z_ModuleLockManager.__enter__  s"    %djj1


r   c                 8    | j                   j                          y r   )r   rz   rZ   s      r   r]   z_ModuleLockManager.__exit__  s    

r   N)r   r   r   r0   rX   r]   r    r   r   r   r     s    r   r   c                 J   t         j                          	 	 t        |           }|?t        t        |       }nt        |       }| fd}t        j                  ||      t        | <   t         j                          |S # t        $ r d}Y dw xY w# t         j                          w xY w)zGet or create the module lock for a given module name.

    Acquire/release internally the global import lock to protect
    _module_locks.Nc                     t         j                          	 t        j                  |      | u rt        |= t         j	                          y # t         j	                          w xY wr   )_impacquire_lock_module_locksrM   release_lock)r>   r   s     r   cbz_get_module_lock.<locals>.cb  sI    !!#( %((.#5)$/%%'D%%'s   A	 	A)
r   r   r   rJ   rn   r   rl   r5   r>   r   )r   rT   r   s      r   r   r     s     		 &(D <'-"4(! 	( #+,,tR"8M$K1  	D	, 	s)   A; AB ;B	B B		B B"c                 z    t        |       }	 |j                          |j                          y# t        $ r Y yw xY w)zAcquires then releases the module lock for a given module name.

    This is used to ensure a module is completely initialized, in the
    event it is being imported by another thread.
    N)r   ry   rz   r_   )r   rT   s     r   _lock_unlock_moduler     s=     D!D 	   	s   . 	::c                      | |i |S )a.  remove_importlib_frames in import.c will always remove sequences
    of importlib frames that end with a call to this function

    Use it instead of a normal call in places where including the importlib
    frames introduces unwanted noise into the traceback (e.g. when executing
    module code)
    r    )fr[   kwdss      r   _call_with_frames_removedr     s     ddr   r   )	verbosityc                    t         j                  j                  |k\  r?| j                  d      sd| z   } t	         | j
                  | t         j                         yy)z=Print the message to stderr if -v/PYTHONVERBOSE is turned on.)#zimport z# )fileN)r   flagsverbose
startswithprintformatstderr)messager   r[   s      r   _verbose_messager     sJ    
yyI%!!"23WnGngnnd##**5 &r   c                 *      fd}t        |        |S )z1Decorator to verify the named module is built-in.c                 Z    |t         j                  vrt        |d|       | |      S )N is not a built-in moduler   )r   builtin_module_namesImportErrorr-   fullnamefxns     r   _requires_builtin_wrapperz4_requires_builtin.<locals>._requires_builtin_wrapper  s8    3333,EF#+- -4""r   r   )r   r   s   ` r   _requires_builtinr     s    #
 

#S)$$r   c                 *      fd}t        |        |S )z/Decorator to verify the named module is frozen.c                 `    t         j                  |      st        |d|       | |      S )Nz is not a frozen moduler   )r   	is_frozenr   r   s     r   _requires_frozen_wrapperz2_requires_frozen.<locals>._requires_frozen_wrapper   s6    ~~h',CD#+- -4""r   r   )r   r   s   ` r   _requires_frozenr     s    #
 

"C(##r   c                     d}t         j                  |t               t        ||       }|t        j
                  v r2t        j
                  |   }t        ||       t        j
                  |   S t        |      S )zLoad the specified module into sys.modules and return it.

    This method is deprecated.  Use loader.exec_module() instead.

    zgthe load_module() method is deprecated and slated for removal in Python 3.12; use exec_module() instead)	_warningswarnDeprecationWarningspec_from_loaderr   modules_exec_load)r-   r   msgspecmodules        r   _load_module_shimr   
  sa    3CNN3*+Hd+D3;;X&dF{{8$$T{r   c                     t        | dd      }t        | dd      x}rt        |      S 	 | j                  }	 | j                  }d|d|dS # t        $ r d}Y #w xY w# t        $ r |d|dcY S d|d|d	cY S w xY w)
z,The implementation of ModuleType.__repr__().
__loader__N__spec__?<module  from > ()>)r   _module_repr_from_specr   r   __file__)r   loaderr   r   filenames        r   _module_reprr     s    V\40Fvz400t0%d++6?? $|155    5>dXQ''dXRz44	5s(   A A AAA;/	A;:A;c                       e Zd ZdZdddddZd Zd Zed        Zej                  d        Zed	        Z
ed
        Zej                  d        Zy)
ModuleSpeca  The specification for a module, used for loading.

    A module's spec is the source for information about the module.  For
    data associated with the module, including source, use the spec's
    loader.

    `name` is the absolute name of the module.  `loader` is the loader
    to use when loading the module.  `parent` is the name of the
    package the module is in.  The parent is derived from the name.

    `is_package` determines if the module is considered a package or
    not.  On modules this is reflected by the `__path__` attribute.

    `origin` is the specific location used by the loader from which to
    load the module, if that information is available.  When filename is
    set, origin will match.

    `has_location` indicates that a spec's "origin" reflects a location.
    When this is True, `__file__` attribute of the module is set.

    `cached` is the location of the cached bytecode file, if any.  It
    corresponds to the `__cached__` attribute.

    `submodule_search_locations` is the sequence of path entries to
    search when importing submodules.  If set, is_package should be
    True--and False otherwise.

    Packages are simply modules that (may) have submodules.  If a spec
    has a non-None value in `submodule_search_locations`, the import
    system will consider modules loaded from the spec as packages.

    Only finders (see importlib.abc.MetaPathFinder and
    importlib.abc.PathEntryFinder) should modify ModuleSpec instances.

    N)originloader_state
is_packagec                |    || _         || _        || _        || _        |rg nd | _        g | _        d| _        d | _        y NF)r   r   r   r   submodule_search_locations_uninitialized_submodules_set_fileattr_cached)r-   r   r   r   r   r   s         r   r0   zModuleSpec.__init__W  sD    	(0:"')+& #r   c                 <   d| j                   d| j                  g}| j                  |j                  d| j                         | j                  |j                  d| j                          | j
                  j                   ddj                  |       dS )Nzname=zloader=zorigin=zsubmodule_search_locations=(z, ))r   r   r   r4   r   r.   r   join)r-   r[   s     r   r   zModuleSpec.__repr__d  s    		}%'@A;;"KK'$++12**6KK5d6U6U5VWX..))*!DIIdO+<A>>r   c                 r   | j                   }	 | j                  |j                  k(  xr{ | j                  |j                  k(  xr` | j                  |j                  k(  xrE ||j                   k(  xr4 | j                  |j                  k(  xr | j
                  |j
                  k(  S # t        $ r	 t        cY S w xY wr   )r   r   r   r   cachedhas_locationr   NotImplemented)r-   othersmsls      r   __eq__zModuleSpec.__eq__l  s    ..	"II+ <KK5<</<KK5<</< E<<<< KK5<</	<
 %%););;=  	"!!	"s   BB$ $B65B6c                     | j                   H| j                  <| j                  r0t        t        t        j                  | j                        | _         | j                   S r   )r   r   r   _bootstrap_externalNotImplementedError_get_cachedrC   s    r   r   zModuleSpec.cachedx  sJ    <<{{&4+=+=&.--2>>t{{K||r   c                     || _         y r   )r   )r-   r   s     r   r   zModuleSpec.cached  s	    r   c                 n    | j                   | j                  j                  d      d   S | j                  S )z The name of the module's parent..r~   )r   r   
rpartitionrC   s    r   parentzModuleSpec.parent  s4     **299'',Q//99r   c                     | j                   S r   )r   rC   s    r   r   zModuleSpec.has_location  s    !!!r   c                 $    t        |      | _        y r   )boolr   )r-   values     r   r   zModuleSpec.has_location  s    !%[r   )r   r   r   r   r0   r   r   propertyr   setterr   r   r    r   r   r   r   2  s    "H 04$ ?
"   ]]    " " ) )r   r   r   r   c                4   |t        |dd      }|sEt        |d      r9t        t        t        j                  }|
 || |      S |rg nd} || ||      S |!t        |d      r	 |j                  |       }nd}t        | |||      S # t        $ r d}Y w xY w)	z5Return a module spec based on various loader methods.N_ORIGINget_filename)r   )r   r   r   Fr   )r   r   r   r   spec_from_file_locationr   r   r   )r   r   r   r   r  searchs         r   r   r     s    ~D1gfn5&%%"5"M"M*4??!t&tFBHJ 	J 6<("#..t4

 JdF6jII  "!
"s   &B	 	BBc                    	 | j                   }||S | j                  }|	 | j                  }	 | j                  }||t        |dd       }|s||}	 | j                  }	 t        | j                        }t        |||      }|dn||k(  |_
        ||_        ||_        |S # t        $ r Y w xY w# t        $ r Y w xY w# t        $ r d }Y w xY w# t        $ r d }Y ~w xY w# t        $ r d }Y yw xY w)Nr   r   F)r   r   r   r   r   r   
__cached__list__path__r   r   r   r   )r   r   r   r   r   locationr   r   s           r   _spec_from_moduler
    s5    K??D~	&&F?? ~VY5F(.F""*%)&//%:" dF62D"*"289KDDK&@D#KG    		
      *%)"*sW   B  B/ B> C C   	B,+B,/	B;:B;>CCCC C.-C.Foverridec                |   |st        |dd       	 | j                  |_        |st        |dd       n| j                  }|X| j
                  Lt        t        t        j                  }|j                  |      }| j
                  |_
        || _        d |_        	 ||_        |st        |dd       	 | j                  |_        	 | |_        |st        |dd       | j
                  	 | j
                  |_        | j"                  rP|st        |dd       	 | j$                  |_        |st        |dd        | j&                  	 | j&                  |_        |S |S # t        $ r Y =w xY w# t        $ r Y w xY w# t        $ r Y w xY w# t        $ r Y w xY w# t        $ r Y w xY w# t        $ r Y w xY w# t        $ r Y |S w xY w)Nr   r   __package__r  r   r  )r   r   r   r   r   r   r   r   NamespaceLoaderr*   _pathr   r   r   r  r   r  r   r   r   r  )r   r   r  r   r  s        r   _init_module_attrsr    s    	GFJ5=	"iiFO 76<6>>..:&.--"5"E"E(00A#>>$ #'	 &F 76=$7?	!%F 76:t4<**6"&"A"A wvz48@"&++ wv|T:B{{&(,F% M6M  		8  		  		
   "  "  & Ms}   E E# /E2 F $F F >F. 	E E #	E/.E/2	E>=E>	FF	FF	F+*F+.	F;:F;c                     d}t        | j                  d      r| j                  j                  |       }n!t        | j                  d      rt        d      |t	        | j
                        }t        | |       |S )z+Create a module based on the provided spec.Ncreate_moduleexec_modulezBloaders that define exec_module() must also define create_module())r   r   r  r   r   r   r  r   r   s     r   module_from_specr  &  so     Ft{{O, **40	m	, = > 	>~TYY'tV$Mr   c                 x   | j                   dn| j                   }| j                  Y| j                  }|d|dS t        6t	        |t        j
                        rd|dt        |j                         dS d|d|dS | j                  rd|d| j                  dS d| j                   d| j                   dS )z&Return the repr to use for the module.r   r   r   z (namespace) from r   r   r   )	r   r   r   r   
isinstancer  r  r  r   )r   r   r   s      r   r   r   7  s    ))#3D{{>dXQ''+6#6#F#FGdX%7V\\8J7K1MMdXRz44dXVDKK?!<<dii]"T[[M<<r   c                    | j                   }t        |      5  t        j                  j	                  |      |urd|d}t        ||      	 | j                  2| j                  t        d| j                         t        | |d       nt        | |d       t        | j                  d      sNt        | j                         d	}t        j                  |t               | j                  j                  |       n| j                  j                  |       t        j                  j!                  | j                         }|t        j                  | j                   <   	 ddd       |S # t        j                  j!                  | j                         }|t        j                  | j                   <   w xY w# 1 sw Y   |S xY w)
zFExecute the spec's specified module in an existing module's namespace.zmodule z not in sys.modulesr   Nmissing loaderTr  r  7.exec_module() not found; falling back to load_module())r   r   r   r   rM   r   r   r   r  r   r	   r   r   ImportWarningload_moduler  rE   )r   r   r   r   s       r   r   r   M  sX   99D	D	! ,;;??4 .D8#67Cc--	,{{"22:%&6TYYGG"4$?"4$?t{{M:*4;;78 9; ;CNN36KK++D1KK++F3 [[__TYY/F%+CKK		"/,0 M [[__TYY/F%+CKK		"/,0 Ms&   5F5CE*AF5*AF22F55F?c                    	 | j                   j                  | j                         t        j                  j                  | j                        }|t        j                  | j                  <   t        |dd       	 | j                   |_        t        |dd       A	 |j                  |_
        t        |d      s#| j                  j                  d      d   |_
        t        |dd       
	 | |_        |S |S #  | j                  t        j                  v rFt        j                  j                  | j                        }|t        j                  | j                  <    xY w# t        $ r Y w xY w# t        $ r Y w xY w# t        $ r Y |S w xY w)Nr   r  r  r   r~   r   )r   r  r   r   r   rE   r   r   r   r   r  r   r   r   r  s     r   _load_backward_compatibler  k  sY   		* [[__TYY'F#CKK		v|T*2	 $F v}d+3	 "(F6:.%)YY%9%9#%>q%A" vz4(0	"FO M6M;99#[[__TYY/F%+CKK		"  		  		
  	M	sC   %C3 ;E A E* (E9 3A%E	E'&E'*	E65E69	FFc                    | j                   St        | j                   d      s=t        | j                          d}t        j	                  |t
               t        |       S t        |       }d| _        	 |t        j                  | j                  <   	 | j                   #| j                  2t        d| j                        | j                   j                  |       t        j                  j!                  | j                        }|t        j                  | j                  <   t#        d| j                  | j                          d| _        |S #  	 t        j                  | j                  =  # t        $ r Y  w xY wxY w# d| _        w xY w)Nr  r  Tr  r   zimport {!r} # {!r}F)r   r   r	   r   r   r  r  r  _initializingr   r   r   r   r   r  rJ   rE   r   )r   r   r   s      r   _load_unlockedr"    sH   {{t{{M2"4;;/0 14 4CNN3.,T22d#F
 D#!'DII	{{"22:%&6TYYGG ''/ +!'DII-tyy$++F"M!	KK		*    #sJ   3E< A
E A'E< E9E*)E9*	E63E95E66E99E< <	Fc                 n    t        | j                        5  t        |       cddd       S # 1 sw Y   yxY w)zReturn a new module object, loaded by the spec's loader.

    The module is not added to its parent.

    If a module is already in sys.modules, that existing module gets
    clobbered.

    N)r   r   r"  r   s    r   r   r     s-     
DII	& $d#$ $ $s   +4c                       e Zd ZdZdZed
d       Zed        Zed        Z	ee
d               Zee
d               Zee
d	               Z ee      Zy)BuiltinImporterzMeta path import for built-in modules.

    All methods are either class or static methods to avoid the need to
    instantiate the class.

    zbuilt-inNc                 ^    t         j                  |      rt        || | j                        S y )Nr  )r   
is_builtinr   r   )clsr   pathtargets       r   	find_speczBuiltinImporter.find_spec  s$    ??8$#Hc#++FFr   c                     | j                   t        j                  vr$t        | j                   d| j                         t	        t
        j                  |       S )zCreate a built-in moduler   r   )r   r   r   r   r   r   create_builtinr$  s    r   r  zBuiltinImporter.create_module  sK     99C444-FG#'99. .()<)<dCCr   c                 8    t        t        j                  |        y)zExec a built-in moduleN)r   r   exec_builtin)r   s    r   r  zBuiltinImporter.exec_module  s     	"$"3"3V<r   c                      y)z9Return None as built-in modules do not have code objects.Nr    r)  r   s     r   get_codezBuiltinImporter.get_code       r   c                      y)z8Return None as built-in modules do not have source code.Nr    r2  s     r   
get_sourcezBuiltinImporter.get_source  r4  r   c                      y)z4Return False as built-in modules are never packages.Fr    r2  s     r   r   zBuiltinImporter.is_package  s     r   NN)r   r   r   r   r   classmethodr,  r;   r  r  r   r3  r6  r   r   r  r    r   r   r&  r&    s     G  D D = =          /0Kr   r&  c                       e Zd ZdZdZed        Zedd       Zedd       Ze	d        Z
e	d        Zed	        Zeed
               Zeed               Zeed               Zy)FrozenImporterzMeta path import for frozen modules.

    All methods are either class or static methods to avoid the need to
    instantiate the class.

    frozenc                    |j                   }|j                  }|Xt        |      j                  dd       }|sJ d       t	        |d      }t
        j                  |j                        |k(  sJ |       | j                  ||j                  |      \  }} t        t        j                        ||      |_        |j                  }|r+|g k(  sJ |       |r&|j                  j                  d|       n	|J |       t	        |d      rJ |j                         |r	 ||_        |r|j"                  |k7  r|j"                  g k(  sJ |j"                         |j"                  j%                  |       nv|j                  }|d u}t'        t        |            ddgk(  sJ |       |j(                  rm| j                  |j(                  |j                  |      \  }	}|j*                  |	k(  sJ |j*                  |	f       |r||gk(  sHJ ||f       ||rg nd k(  s6J |       d }	|j*                  J |j*                         ||rg nd k(  sJ |       |	r0t	        |d      sJ |j                  |	k(  s0J |j                  |	f       t	        |d      rJ |j                         |r0t	        |d      sJ |j"                  |k(  s0J |j"                  |f       t	        |d      rJ |j"                         |j,                  rJ y # t         $ r Y w xY w)	N__origname__z'see PyImport_ImportFrozenModuleObject()r  r   orignamer~   r   r   r@  )r   r   varsrE   r   r   is_frozen_packager   _resolve_filenamer   r   r   implementationr   insertr   r   r  extendsortedr@  r   r   )
r)  r   r   stater@  ispkgr   pkgdirr  r   s
             r   _fix_up_modulezFrozenImporter._fix_up_module
  s   !!= F|''=HFFF8FJ/E))&//:eCJUJC"44Xtyy%PHf 8S%7%7 8!!!D 66H2~/x/~33::1fE'11' vz2CFOOC2&.FO ??h.!??b0A&//A0OO**84 66HD(E$u+&:z*BBIEIB~~ **5>>499eL6~~1MENNH3MM1#x/C(F1CC/#e>HH>~~-=u~~=-%BT:DHD:vz222(2OV__h4OO2"6:6GG6vz222(2OV__h4OO2"6:6GG6$$$$$K & s   K9 9	LLNc                    |rt        t        dd       sy	 | j                  }||k7  r |j                  d      r|dd  }|s| d}nd	}|j                  d
|      }|r!t        j                   | | }| | d}||fS d }t        j                   | | d}||fS # t        $ r! t        j                  dk(  rdndx}| _        Y w xY w)N_stdlib_dirr8  win32\/<r   z	.__init__Fr   z__init__.pyz.py)r   r   _SEPr   platformr   r   rM  )r)  r   aliasrI  seprelfilerJ  r   s           r   rC  z FrozenImporter._resolve_filenameO  s    wsM4@	F((C u""3'#AB<"*95H""3,(gY7F #k2H  F//*3%y<H#  	F%(\\W%<T#EC#(	Fs   B 'CCc                 2   t        t        j                  |      }|y |\  }}}t        || | j                  |      }| j                  |||      \  }	}
 t        t        j                        |	|      |_	        |
r|j                  j                  d|
       |S )Nr   r?  r~   )r   r   find_frozenr   r   rC  r   r   rD  r   r   rE  )r)  r   r*  r+  info_rI  r@  r   r   rJ  s              r   r,  zFrozenImporter.find_spech  s    ()9)98D< "5(#'*{{+02 008UK&4D!3!34
 ++221f=r   c                     t        | j                        }	 | j                  j                  }|r||_        |S # t
        $ r Y |S w xY w)zSet __file__, if able.)r   r   r   r   r   r   )r   r   r   s      r   r  zFrozenImporter.create_module  sT     TYY'	+((11H "*  	 	s   8 	AAc                     | j                   }|j                  }t        t        j                  |      }t        || j                         y r   )r   r   r   r   get_frozen_objectexecr   )r   r   r   codes       r   r  zFrozenImporter.exec_module  s4    yy()?)?FT6??#r   c                     t        | |      }t        j                  |      }|J |\  }}}||_        t	        |      j                  dd       |rg |_        | j                  |       |S )z_Load a frozen module.

        This method is deprecated.  Use exec_module() instead.

        Nr   )r   r   rX  r>  rA  rE   r  rK  )r)  r   r   rY  rZ  rI  r@  s          r   r  zFrozenImporter.load_module  sq     #31)!5(&VT* FO6"r   c                 ,    t         j                  |      S )z-Return the code object for the frozen module.)r   r]  r2  s     r   r3  zFrozenImporter.get_code       %%h//r   c                      y)z6Return None as frozen modules do not have source code.Nr    r2  s     r   r6  zFrozenImporter.get_source  r4  r   c                 ,    t         j                  |      S )z.Return True if the frozen module is a package.)r   rB  r2  s     r   r   zFrozenImporter.is_package  rb  r   r   r8  )r   r   r   r   r   r9  rK  rC  r,  r;   r  r  r  r   r3  r6  r   r    r   r   r;  r;    s     GB% B%H    0  : 
 
 $ $  $ 0  0    0  0r   r;  c                       e Zd ZdZd Zd Zy)_ImportLockContextz$Context manager for the import lock.c                 ,    t         j                          y)zAcquire the import lock.N)r   r   rC   s    r   rX   z_ImportLockContext.__enter__      r   c                 ,    t         j                          y)z<Release the import lock regardless of any raised exceptions.N)r   r   )r-   exc_type	exc_valueexc_tracebacks       r   r]   z_ImportLockContext.__exit__  rh  r   N)r   r   r   r   rX   r]   r    r   r   rf  rf    s    .r   rf  c                 ~    |j                  d|dz
        }t        |      |k  rt        d      |d   }| r| d|  S |S )z2Resolve a relative module name to an absolute one.r   r   z2attempted relative import beyond top-level packager~   )rsplitr   r   )r   packagelevelbitsbases        r   _resolve_namers    sO    >>#uqy)D
4y5NOO7D#dV1TF--r   c                    t         j                  }|t        d      |st        j	                  dt
               | t         j                  v }|D ]q  }t               5  	 |j                  } || ||      }	 ddd       1|s<| t         j                  v r*t         j                  |    }	 |j                  }	|	|c S |	c S |c S  y# t        $ r Y ddd       w xY w# 1 sw Y   gxY w# t        $ r |cY c S w xY w)zFind a module's spec.Nz5sys.meta_path is None, Python is likely shutting downzsys.meta_path is empty)r   	meta_pathr   r   r   r  r   rf  r,  r   r   )
r   r*  r+  ru  	is_reloadfinderr,  r   r   r   s
             r   
_find_specrx    s   I * + 	+ /?
 #I ! 	55",,	 !tV4	5 !4T*(%H  '#'36 / " 		5 	5	5 	5 &    K	 sB   CC)
C'C&	CCCCC#	&C65C6c                     t        | t              st        dt        |              |dk  rt	        d      |dkD  r(t        |t              st        d      |st        d      | s|dk(  rt	        d      yy)zVerify arguments are "sane".zmodule name must be str, not r~   zlevel must be >= 0z__package__ not set to a stringz6attempted relative import with no known parent packagezEmpty module nameN)r  str	TypeErrorr   
ValueErrorr   r   ro  rp  s      r   _sanity_checkr~    s    dC 7T
|DEEqy-..qy'3'=>> ( ) )EQJ,-- 4r   zNo module named z{!r}c                 V   d }| j                  d      d   }d }|r|t        j                  vrt        ||       | t        j                  v rt        j                  |    S t        j                  |   }	 |j                  }|j                  }| j                  d      d   }t        | |      }|t        t         | |       |r|j                  j                         	 t        |      }	|r|j                  j                          	 |r#t        j                  |   }	 t        ||	       |	S |	S # t
        $ r t         | d|d}t        ||       d w xY w# |r|j                  j                          w w xY w# t
        $ r& d|d}t        j!                  |t"               Y |	S w xY w)	Nr   r~   z; z is not a packager      zCannot set an attribute on z for child module )r   r   r   r   r  r   _ERR_MSG_PREFIXModuleNotFoundErrorr   rx  r   r4   r"  rE   r   r   r   r  )
r   import_r*  r   parent_specparent_moduler   childr   r   s
             r   _find_and_load_unlockedr    s   D__S!!$FK$%gv63;;;;t$$F+	@ ))D $,,$Q'dD!D|!_$5dX">TJJ 1188?	<#D)F5599;F+	/M5&1 M6M5  	@$%dXRz9JKC%c54?	@  5599;   	//z9KE9UCNN3.M	/s*   2D. E E9 .&EE69+F('F(c                    t         j                  j                  | t              }|t        u st	        t	        |dd      dd      rat        |       5  t         j                  j                  | t              }|t        u rt        | |      cddd       S 	 ddd       t        |        |d|  d}t        ||       |S # 1 sw Y   +xY w)zFind and load the module.r   Nr!  Fz
import of z halted; None in sys.modulesr   )	r   r   rM   _NEEDS_LOADINGr   r   r  r   r  )r   r  r   r   s       r   _find_and_loadr  E  s    
 [[__T>2F. 
D1?EJ% 	>[[__T>:F'.tW=	> 	>'	> 	D!~tf$@A!'55M	> 	>s   8B==Cc                 `    t        | ||       |dkD  rt        | ||      } t        | t              S )a2  Import and return the module based on its name, the package the call is
    being made from, and the level adjustment.

    This function represents the greatest common denominator of functionality
    between import_module and __import__. This includes setting __package__ if
    the loader did not.

    r~   )r~  rs  r  _gcd_importr}  s      r   r  r  _  s2     $'qyT7E2$,,r   	recursivec          	         |D ]  }t        |t              s8|r| j                  dz   }nd}t        d| dt	        |      j                         |dk(  r*|rSt        | d      s`t        | | j                  |d       zt        | |      r| j                   d	| }	 t        ||        | S # t        $ r>}|j                  |k(  r)t        j                  j                  |t              Y d
}~ d
}~ww xY w)zFigure out what __import__ should return.

    The import_ parameter is a callable which takes the name of module to
    import. It is required to decouple the function from assuming importlib's
    import implementation is desired.

    z.__all__z``from list''zItem in z must be str, not *__all__Tr  r   N)r  rz  r   r{  r   r   _handle_fromlistr  r   r  r   r   r   rM   r  )r   fromlistr  r  xwhere	from_nameexcs           r   r  r  n  s      !S!*4'hug .##'7#3#3"46 7 7#X!; +/1#!??+1QC0I	)'9=0 M '  HH	)KKOOI~>Js   B,,	C353C.-C..C3c                 \   | j                  d      }| j                  d      }|@|<||j                  k7  r-t        j                  d|d|j                  dt        d       |S ||j                  S t        j                  dt
        d       | d	   }d
| vr|j                  d      d   }|S )zCalculate what __package__ should be.

    __package__ is not guaranteed to be defined or could be set to None
    to represent that its proper value is unknown.

    r  r   z __package__ != __spec__.parent (z != r      )
stacklevelzYcan't resolve package from __spec__ or __package__, falling back on __name__ and __path__r   r  r   r~   )rM   r   r   r   r   r  r   )globalsro  r   s      r   _calc___package__r    s     kk-(G;;z"D4;; 6NN &kdkk_A?-!  = 		{{ ?$ 	 	4 *%W$((-a0GNr   c                    |dk(  rt        |       }n||ni }t        |      }t        | ||      }|s|dk(  rt        | j                  d      d         S | s|S t        |       t        | j                  d      d         z
  }t        j
                  |j                  dt        |j                        |z
      S t        |d      rt        ||t               S |S )a  Import a module.

    The 'globals' argument is used to infer where the import is occurring from
    to handle relative imports. The 'locals' argument is ignored. The
    'fromlist' argument specifies what should exist as attributes on the module
    being imported (e.g. ``from module import <fromlist>``).  The 'level'
    argument represents the package location to import from in a relative
    import (e.g. ``from ..pkg import mod`` would have a 'level' of 2).

    r~   Nr   r  )	r  r  	partitionr   r   r   r   r   r  )	r   r  localsr  rp  r   globals_ro  cut_offs	            r   
__import__r    s     zT"%17r#H-T7E2 A:t~~c21566M $i#dnnS&9!&<"==G ;;v/LFOO0DW0LMNN		$+>>r   c                 b    t         j                  |       }|t        d| z         t        |      S )Nzno built-in module named )r&  r,  r   r"  )r   r   s     r   _builtin_from_namer    s3    $$T*D|5<==$r   c                 ,   |a | at        t              }t        j                  j	                         D ]z  \  }}t        ||      s|t        j                  v rt        }nt         j                  |      rt        }nIt        ||      }t        ||       |t        u sj|j                  |       | t        j                  t           }dD ]@  }|t        j                  vrt        |      }	nt        j                  |   }	t        |||	       B t!               ay)zSetup importlib by importing needed built-in modules and injecting them
    into the global namespace.

    As sys is needed for sys.modules access and _imp is needed to load built-in
    modules, those two modules must be explicitly passed in.

    )rn   r   r5   N)r   r   r   r   itemsr  r   r&  r   r;  r
  r  rK  r   r  r   r#   rV   )

sys_module_imp_modulemodule_typer   r   r   r   self_modulebuiltin_namebuiltin_modules
             r   _setupr    s     D
C s)K))+ .ffk*s///(%'$VV4DtV,'%%f-. ++h'K< ;s{{*/=N [[6N\>:; ()Lr   c                     t        | |       t        j                  j                  t               t        j                  j                  t
               y)z0Install importers for builtin and frozen modulesN)r  r   ru  r4   r&  r;  )r  r  s     r   _installr    s0    
:{#MM)MM(r   c                  \    ddl } | a| j                  t        j                  t
                  y)z9Install importers that require external filesystem accessr~   N)_frozen_importlib_externalr   r  r   r   r   )r  s    r   _install_external_importersr  
  s$     &4''H(=>r   r8  r   r   )NNr    r~   ):r   r	   rn   r   r5   r   r   r   r  r   r#   r   rV   rQ   r   r_   rf   rl   r   r   r   r   r   r   r   r   r   r   r   r   r
  r  r  r   r   r  r"  r   r&  r;  rf  rs  rx  r~  r  _ERR_MSGr  objectr  r  r  r  r  r  r  r  r  r  r    r   r   <module>r     s  ,& 	  &	D 	I I\  * *,	\ 	
(V`; `;F@ @*  "J" 01 6%$&6*a) a)H .2d J:'T 27 FR"=,<"H)Z
$11 11h~0 ~0F
 
.*Z.  %V#'T 4- >C "J6"J %*P)?r   