/ lib / importlib / _bootstrap_external.pyc
_bootstrap_external.pyc
  1  o

  2  5�Hc��@s�dZdaddlZddlZddlZddlZddlZejdkZer(ddl	Z
  3  ddlZnddlZ
  4  er3ddgZ
ndgZ
edd�e
D��sAJ�e
dZee
�Zd�e
�Z
d	d
  5  �e
D�ZdZdZeeZd
d�Ze�Zdd�Zdd�Zdd�Zerwdd�Zndd�Zdd�Zdd�Zdd�Zdd�Z d d!�Z!er�d"d#�Z"nd$d#�Z"dpd&d'�Z#e$e#j%�Z&d(�'d)d*�d+Z(e)�*e(d*�Z+d,Z,d-Z-d.gZ.er�e.�/d/�e�0�Z1d0gZ2e2Z3Z4dqdd1�d2d3�Z5d4d5�Z6d6d7�Z7d8d9�Z8d:d;�Z9d<d=�Z:d>d?�Z;d@dA�Z<dBdC�Z=dDdE�Z>drdFdG�Z?dsdHdI�Z@dtdKdL�ZAdMdN�ZBeC�ZDdqdeDdO�dPdQ�ZEGdRdS�dS�ZFGdTdU�dU�ZGGdVdW�dWeG�ZHGdXdY�dY�ZIGdZd[�d[eIeH�ZJGd\d]�d]eIeG�ZKGd^d_�d_eIeG�ZLGd`da�da�ZMGdbdc�dc�ZNGddde�de�ZOGdfdg�dg�ZPdqdhdi�ZQdjdk�ZRdldm�ZSdndo�ZTdS)ua^Core implementation of path-based import.
  6  
  7  This module is NOT meant to be directly imported! It has been designed such
  8  that it can be bootstrapped into Python as the implementation of import. As
  9  such it requires the injection of specific modules and attributes in order to
 10  work. One should use importlib as the public-facing version of this module.
 11  
 12  N��win32�\�/ccs�|]	}t|�dkVqdS)�N)�len)�.0�sep�r	��C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2800.0_x64__qbz5n2kfra8p0\lib\importlib\_bootstrap_external.py�	<genexpr>.s�r�cCsh|]}d|���qS)�:r	)r�sr	r	r
 13  �	<setcomp>2sr)�win)�cygwin�darwincs>tj�t�rtj�t�rd�nd��fdd�}|Sdd�}|S)N�PYTHONCASEOKsPYTHONCASEOKcstjjo	�tjvS)z^True if filenames must be checked case-insensitively and ignore environment flags are not set.)�sys�flags�ignore_environment�_os�environr	��keyr	r
 14  �_relax_caseC�z%_make_relax_case.<locals>._relax_casecS�dS)z5True if filenames must be checked case-insensitively.Fr	r	r	r	r
 15  rG�)r�platform�
 16  startswith�_CASE_INSENSITIVE_PLATFORMS�#_CASE_INSENSITIVE_PLATFORMS_STR_KEY)rr	rr
 17  �_make_relax_case<s�r#cCst|�d@�dd�S)z*Convert a 32-bit integer to little-endian.�����little)�int�to_bytes)�xr	r	r
 18  �_pack_uint32Orr*cC�t|�dksJ�t�|d�S)z/Convert 4 bytes in little-endian to an integer.r%r&�rr'�
 19  from_bytes��datar	r	r
 20  �_unpack_uint32T�r0cCr+)z/Convert 2 bytes in little-endian to an integer.�r&r,r.r	r	r
 21  �_unpack_uint16Yr1r3cGs�|sdSt|�dkr|dSd}g}ttj|�D]=\}}|�t�s&|�t�r3|�t�p,|}t	|g}q|�d�rL|�
 22  �|�
 23  �krF|}|g}q|�|�q|pO|}|�|�qdd�|D�}t|�dkrk|dsk|t	S|t	�|�S)�Replacement for os.path.join().rrrr
cS�g|]	}|r|�t��qSr	��rstrip�path_separators�r�pr	r	r
 24 25  <listcomp>ws�_path_join.<locals>.<listcomp>)
r�mapr�_path_splitrootr �path_sep_tuple�endswithr7r8�path_sep�casefold�append�join)�
 26  path_parts�root�path�new_root�tailr	r	r
 27 28  _path_join`s*
 29  rJcGst�dd�|D��S)r4cSr5r	r6)r�partr	r	r
 30  r;�s�r<)rArD)rEr	r	r
 31  rJ~s
 32  �csBt�fdd�tD��}|dkrd�fS�d|��|dd�fS)z Replacement for os.path.split().c3s�|]}��|�VqdS�N)�rfindr9�rGr	r
 33  r�s�z_path_split.<locals>.<genexpr>rrNr)�maxr8)rG�ir	rNr
 34  �_path_split�srQcCs
 35  t�|�S)z~Stat the path.
 36  
 37      Made a separate function to make it easier to override in experiments
 38      (e.g. cache stat results).
 39  
 40      )r�statrNr	r	r
 41 42  _path_stat�s
 43  rScCs0zt|�}Wn
 44  tyYdSw|jd@|kS)z1Test whether the path is the specified mode type.Fi�)rS�OSError�st_mode)rG�mode�	stat_infor	r	r
 45  �_path_is_mode_type�s�rXcCs
 46  t|d�S)zReplacement for os.path.isfile.i�)rXrNr	r	r
 47  �_path_isfile��
 48  rYcCs|st��}t|d�S)zReplacement for os.path.isdir.i@)r�getcwdrXrNr	r	r
 49  �_path_isdir�s
 50  r\cCs>|sdSt�|�d�dd�}t|�dko|�d�p|�d�S)�Replacement for os.path.isabs.Frrrrz\\)rr>�replacerr r@)rGrFr	r	r
 51  �_path_isabs�s r_cCs
 52  |�t�S)r])r r8rNr	r	r
 53  r_�rZ�cCs�d�|t|��}t�|tjtjBtjB|d@�}z$t�|d��
}|�	|�Wd�n1s/wYt�
 54  ||�WdStyTzt�|�W�tySY�ww)z�Best-effort function to write data to a path atomically.
 55      Be prepared to handle a FileExistsError if concurrent writing of the
 56      temporary file is attempted.�{}.{}r`�wbN)
�format�idr�open�O_EXCL�O_CREAT�O_WRONLY�_io�FileIO�writer^rT�unlink)rGr/rV�path_tmp�fd�filer	r	r
 57  �
_write_atomic�s$�����rpio
r2r&s
 58  �__pycache__zopt-z.pyz.pywz.pyc)�optimizationcCsP|durt�dt�|durd}t|��|rdnd}t�|�}t|�\}}|�d�\}}}tj	j
 59  }	|	dur9td��d�|r?|n|||	g�}
 60  |durVtj
jdkrRd}ntj
j}t|�}|dkrp|��sitd	�|���d
 61  �|
 62  t|�}
 63  |
 64  td}tjdur�t|�s�tt��|�}|ddkr�|dtvr�|dd�}ttj|�t�|�St|t|�S)
a�Given the path to a .py file, return the path to its .pyc file.
 65  
 66      The .py file does not need to exist; this simply returns the path to the
 67      .pyc file calculated as if the .py file were imported.
 68  
 69      The 'optimization' parameter controls the presumed optimization level of
 70      the bytecode file. If 'optimization' is not None, the string representation
 71      of the argument is taken and verified to be alphanumeric (else ValueError
 72      is raised).
 73  
 74      The debug_override parameter is deprecated. If debug_override is not None,
 75      a True value is the same as setting 'optimization' to the empty string
 76      while a False value is equivalent to setting 'optimization' to '1'.
 77  
 78      If sys.implementation.cache_tag is None then NotImplementedError is raised.
 79  
 80      NzFthe debug_override parameter is deprecated; use 'optimization' insteadz2debug_override or optimization must be set to Nonerr�.�$sys.implementation.cache_tag is Nonerz{!r} is not alphanumericz{}.{}{}r
r2)�	_warnings�warn�DeprecationWarning�	TypeErrorr�fspathrQ�
 81  rpartitionr�implementation�	cache_tag�NotImplementedErrorrDr�optimize�str�isalnum�
 82  ValueErrorrc�_OPT�BYTECODE_SUFFIXES�pycache_prefixr_rJr[r8�lstrip�_PYCACHE)rG�debug_overriderr�message�headrI�baser�rest�tag�almost_filename�filenamer	r	r
 83  �cache_from_source|sH�
 84  
 85  	�r�c
 86  Cs(tjjdur
 87  td��t�|�}t|�\}}d}tjdur3tj�t	�}|�
 88  |t�r3|t|�d�}d}|sHt|�\}}|t
krHtt
�d|����|�d�}|dvrXtd|����|d	kr�|�dd
 89  �d}|�
 90  t�sptdt����|tt�d�}|��s�td
|�d���|�d�d}	t||	td�S)anGiven the path to a .pyc. file, return the path to its .py file.
 91  
 92      The .pyc file does not need to exist; this simply returns the path to
 93      the .py file calculated to correspond to the .pyc file.  If path does
 94      not conform to PEP 3147/488 format, ValueError will be raised. If
 95      sys.implementation.cache_tag is None then NotImplementedError is raised.
 96  
 97      NrtFTz not bottom-level directory in rs>r2�zexpected only 2 or 3 dots in r�r2�����z5optimization portion of filename does not start with zoptimization level z is not an alphanumeric valuer)rr{r|r}rryrQr�r7r8r rArr�r��count�rsplitr�r��	partitionrJ�SOURCE_SUFFIXES)
 98  rGr��pycache_filename�found_in_pycache_prefix�
stripped_path�pycache�	dot_countrr�	opt_level�
base_filenamer	r	r
 99  �source_from_cache�s<	
100  
101  �
102  
103  �r�c	Cs|t|�dkrdS|�d�\}}}|r|��dd�dkr|Szt|�}Wnttfy5|dd�}Ynwt|�r<|S|S)z�Convert a bytecode file path to a source path (if possible).
104  
105      This function exists purely for backwards-compatibility for
106      PyImport_ExecCodeModuleWithFilenames() in the C API.
107  
108      rNrs�����������py)rrz�lowerr�r}r�rY)�
bytecode_pathr��_�	extension�source_pathr	r	r
109  �_get_sourcefile�s�r�cCsD|�tt��rzt|�WStyYdSw|�tt��r |SdSrL)r@�tupler�r�r}r�)r�r	r	r
110  �_get_cached�s
111  �r�cCs2zt|�j}Wntyd}Ynw|dO}|S)z3Calculate the mode permissions for a bytecode file.r`�)rSrUrT)rGrVr	r	r
112113  _calc_mode
114  s�r�cs4d�fdd�	}tdurtj}ndd�}||��|S)z�Decorator to verify that the module being requested matches the one the
115      loader can handle.
116  
117      The first argument (self) must define _name which the second argument is
118      compared against. If the comparison fails then ImportError is raised.
119  
120      NcsH|dur|j}n|j|krtd|j|f|d���||g|�Ri|��S)Nzloader for %s cannot handle %s��name)r��ImportError)�selfr��args�kwargs��methodr	r
121  �_check_name_wrappers
122  ��z(_check_name.<locals>._check_name_wrappercSs8dD]}t||�rt||t||��q|j�|j�dS)N)�
123  __module__�__name__�__qualname__�__doc__)�hasattr�setattr�getattr�__dict__�update)�new�oldr^r	r	r
124  �_wrap+s
125  
126  �z_check_name.<locals>._wraprL)�
127  _bootstrapr�)r�r�r�r	r�r
128  �_check_names
129  
130  r�cCsHt�dt�|�|�\}}|dur"t|�r"d}t�|�|d�t�|S)z�Try to find a loader for the specified module by delegating to
131      self.find_loader().
132  
133      This method is deprecated in favor of finder.find_spec().
134  
135      zZfind_module() is deprecated and slated for removal in Python 3.12; use find_spec() insteadNz,Not importing directory {}: missing __init__r)rurvrw�find_loaderrrc�
ImportWarning)r��fullname�loader�portions�msgr	r	r
136  �_find_module_shim5s�r�cCs�|dd�}|tkr d|�d|��}t�d|�t|fi|���t|�dkr5d|��}t�d|�t|��t|dd��}|d	@rQd
137  |�d|��}t|fi|���|S)aTPerform basic validity checking of a pyc header and return the flags field,
138      which determines how the pyc should be further validated against the source.
139  
140      *data* is the contents of the pyc file. (Only the first 16 bytes are
141      required, though.)
142  
143      *name* is the name of the module being imported. It is used for logging.
144  
145      *exc_details* is a dictionary passed to ImportError if it raised for
146      improved debugging.
147  
148      ImportError is raised when the magic number is incorrect or when the flags
149      field is invalid. EOFError is raised when the data is found to be truncated.
150  
151      Nr%zbad magic number in z: �{}�z(reached EOF while reading pyc header of ������zinvalid flags z in )�MAGIC_NUMBERr��_verbose_messager�r�EOFErrorr0)r/r��exc_details�magicr�rr	r	r
152  �
_classify_pycIs
153  r�cCs|t|dd��|d@krd|��}t�d|�t|fi|���|dur:t|dd��|d@kr<td|��fi|���dSdS)aValidate a pyc against the source last-modified time.
154  
155      *data* is the contents of the pyc file. (Only the first 16 bytes are
156      required.)
157  
158      *source_mtime* is the last modified timestamp of the source file.
159  
160      *source_size* is None or the size of the source file in bytes.
161  
162      *name* is the name of the module being imported. It is used for logging.
163  
164      *exc_details* is a dictionary passed to ImportError if it raised for
165      improved debugging.
166  
167      An ImportError is raised if the bytecode is stale.
168  
169      r��r$zbytecode is stale for r�Nr�)r0r�r�r�)r/�source_mtime�source_sizer�r�r�r	r	r
170  �_validate_timestamp_pycjs
171  �r�cCs*|dd�|krtd|��fi|���dS)a�Validate a hash-based pyc by checking the real source hash against the one in
172      the pyc header.
173  
174      *data* is the contents of the pyc file. (Only the first 16 bytes are
175      required.)
176  
177      *source_hash* is the importlib.util.source_hash() of the source file.
178  
179      *name* is the name of the module being imported. It is used for logging.
180  
181      *exc_details* is a dictionary passed to ImportError if it raised for
182      improved debugging.
183  
184      An ImportError is raised if the bytecode is stale.
185  
186      r�r�z.hash in bytecode doesn't match hash of source N)r�)r/�source_hashr�r�r	r	r
187  �_validate_hash_pyc�s���r�cCsLt�|�}t|t�rt�d|�|durt�||�|Std�	|�||d��)z#Compile bytecode as found in a pyc.zcode object from {!r}NzNon-code object in {!r}�r�rG)
188  �marshal�loads�
189  isinstance�
190  _code_typer�r��_imp�_fix_co_filenamer�rc)r/r�r�r��coder	r	r
191  �_compile_bytecode�s
192  
193  
194  �r�cCsFtt�}|�td��|�t|��|�t|��|�t�|��|S)z+Produce the data for a timestamp-based pyc.r)�	bytearrayr��extendr*r��dumps)r��mtimer�r/r	r	r
195  �_code_to_timestamp_pyc�sr�TcCsPtt�}d|d>B}|�t|��t|�dksJ�|�|�|�t�|��|S)z&Produce the data for a hash-based pyc.rr�)r�r�r�r*rr�r�)r�r��checkedr/rr	r	r
196  �_code_to_hash_pyc�s
197  r�cCs>ddl}t�|�j}|�|�}t�dd�}|�|�|d��S)zyDecode bytes representing source code and return the string.
198  
199      Universal newline support is used in the decoding.
200      rNT)�tokenizeri�BytesIO�readline�detect_encoding�IncrementalNewlineDecoder�decode)�source_bytesr��source_bytes_readline�encoding�newline_decoderr	r	r
201  �
decode_source�s
202  
203  r��r��submodule_search_locationsc	Cs6|durd}t|d�rz|�|�}Wn&tyYnwnt�|�}t|�s9z	tt��|�}Wn	ty8Ynwt	j
204  |||d�}d|_|durct�D]\}}|�
t|��r`|||�}||_nqKdS|tur�t|d�r�z|�|�}Wn	ty|Yn
205  w|r�g|_n||_|jgkr�|r�t|�d}|j�|�|S)a=Return a module spec based on a file location.
206  
207      To indicate that the module is a package, set
208      submodule_search_locations to a list of directory paths.  An
209      empty list is sufficient, though its not otherwise useful to the
210      import system.
211  
212      The loader must take a spec as its only __init__() arg.
213  
214      Nz	<unknown>�get_filename��originT�
215  is_packager)r�r�r�rryr_rJr[rTr��
216  ModuleSpec�
_set_fileattr�_get_supported_file_loadersr@r�r��	_POPULATEr�r�rQrC)	r��locationr�r��spec�loader_class�suffixesr��dirnamer	r	r
217  �spec_from_file_location�sT
218  ��
219  �	
220  �
221  ��
222  rc@sXeZdZdZdZdZeodevZe	dd��Z
223  edd��Zedd
224  d��Z
eddd
��Zd	S)�WindowsRegistryFinderz>Meta path finder for modules declared in the Windows registry.z;Software\Python\PythonCore\{sys_version}\Modules\{fullname}zASoftware\Python\PythonCore\{sys_version}\Modules\{fullname}\Debugz_d.pydcCs2zt�tj|�WStyt�tj|�YSwrL)�winreg�OpenKey�HKEY_CURRENT_USERrT�HKEY_LOCAL_MACHINErr	r	r
225  �_open_registry&s
226  �z$WindowsRegistryFinder._open_registrycCs�|jr|j}n|j}|j|dtjdd�d�}z |�|��}t�|d�}Wd�W|S1s1wYW|St	yBYdSw)Nz%d.%dr2)r��sys_versionr)
227  �DEBUG_BUILD�REGISTRY_KEY_DEBUG�REGISTRY_KEYrcr�version_infor	r�
228  QueryValuerT)�clsr��registry_keyr�hkey�filepathr	r	r
229  �_search_registry-s �����z&WindowsRegistryFinder._search_registryNcCsx|�|�}|durdSzt|�Wn
230  tyYdSwt�D]\}}|�t|��r9tj||||�|d�}|SqdS)Nr�)rrSrTr�r@r�r��spec_from_loader)rr�rG�targetrr�rr�r	r	r
231  �	find_spec<s"
232  ����zWindowsRegistryFinder.find_speccCs*t�dt�|�||�}|dur|jSdS)zjFind module named in the registry.
233  
234          This method is deprecated.  Use find_spec() instead.
235  
236          zpWindowsRegistryFinder.find_module() is deprecated and slated for removal in Python 3.12; use find_spec() insteadN�rurvrwrr��rr�rGr�r	r	r
237  �find_moduleLs�z!WindowsRegistryFinder.find_module�NNrL)r�r�r�r�r
r�_MS_WINDOWS�EXTENSION_SUFFIXESr�staticmethodr	�classmethodrrrr	r	r	r
238  rs��
239  
240  rc@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
241  S)�
_LoaderBasicszSBase class of common code needed by both SourceLoader and
242      SourcelessFileLoader.cCs@t|�|��d}|�dd�d}|�d�d}|dko|dkS)z�Concrete implementation of InspectLoader.is_package by checking if
243          the path returned by get_filename has a filename of '__init__.py'.rrsrr2�__init__)rQr�r�rz)r�r�r��
filename_base�	tail_namer	r	r
244  r�bsz_LoaderBasics.is_packagecCr�z*Use default semantics for module creation.Nr	�r�r�r	r	r
245  �
create_modulej�z_LoaderBasics.create_modulecCs8|�|j�}|durtd�|j���t�t||j�dS)zExecute the module.Nz4cannot load module {!r} when get_code() returns None)�get_coder�r�rcr��_call_with_frames_removed�execr�)r��moduler�r	r	r
246  �exec_modulems�z_LoaderBasics.exec_modulecCst�||�S)zThis method is deprecated.)r��_load_module_shim�r�r�r	r	r
247  �load_moduleusz_LoaderBasics.load_moduleN)r�r�r�r�r�r&r,r/r	r	r	r
248  r ]sr c@sJeZdZdd�Zdd�Zdd�Zdd�Zd	d
249  �Zdd�d
d�Zdd�Z	dS)�SourceLoadercCst�)z�Optional method that returns the modification time (an int) for the
250          specified path (a str).
251  
252          Raises OSError when the path cannot be handled.
253          )rT�r�rGr	r	r
254255  path_mtime}szSourceLoader.path_mtimecCsd|�|�iS)a�Optional method returning a metadata dict for the specified
256          path (a str).
257  
258          Possible keys:
259          - 'mtime' (mandatory) is the numeric timestamp of last source
260            code modification;
261          - 'size' (optional) is the size in bytes of the source code.
262  
263          Implementing this method allows the loader to read bytecode files.
264          Raises OSError when the path cannot be handled.
265          r�)r2r1r	r	r
266267  path_stats�szSourceLoader.path_statscCs|�||�S)z�Optional method which writes data (bytes) to a file path (a str).
268  
269          Implementing this method allows for the writing of bytecode files.
270  
271          The source path is needed in order to correctly transfer permissions
272          )�set_data)r�r��
273  cache_pathr/r	r	r
274  �_cache_bytecode�szSourceLoader._cache_bytecodecCr)z�Optional method which writes data (bytes) to a file path (a str).
275  
276          Implementing this method allows for the writing of bytecode files.
277          Nr	)r�rGr/r	r	r
278  r4�r'zSourceLoader.set_datac
279  CsF|�|�}z
280  |�|�}Wt|�Sty"}ztd|d�|�d}~ww)z4Concrete implementation of InspectLoader.get_source.z'source not available through get_data()r�N)r��get_datarTr�r�)r�r�rGr��excr	r	r
281282  get_source�s
283  �����zSourceLoader.get_sourcer�)�	_optimizecCstjt||dd|d�S)z�Return the code object compiled from source.
284  
285          The 'data' argument can be any object type that compile() supports.
286          r*T)�dont_inheritr~)r�r)�compile)r�r/rGr:r	r	r
287  �source_to_code�s�zSourceLoader.source_to_codec	Cs|�|�}d}d}d}d}d}zt|�}Wnty d}Yn�wz|�|�}	Wn	ty1Ynwt|	d�}z|�|�}
288  Wn	tyHYnhw||d�}zGt|
289  ||�}t|
290  �dd�}
|d@dk}|r�|d	@dk}t	j
291  d
292  kr�|swt	j
293  dkr�|�|�}t	�t|�}t
|
294  |||�n
295  t|
296  ||	d||�Wnttfy�Ynwt�d
||�t|
|||d�S|dur�|�|�}|�||�}t�d|�tjs�|dur�|dur�|r�|dur�t	�|�}t|||�}
297  nt||t|��}
298  z
299  |�|||
300  �W|Sty�Y|Sw|S)z�Concrete implementation of InspectLoader.get_code.
301  
302          Reading of bytecode requires path_stats to be implemented. To write
303          bytecode, set_data must also be implemented.
304  
305          NFTr�r�r�rrr2�never�always�sizez
{} matches {})r�r�r�zcode object from {})r�r�r}r3rTr'r7r��
306  memoryviewr��check_hash_based_pycsr��_RAW_MAGIC_NUMBERr�r�r�r�r�r�r�r=r�dont_write_bytecoder�r�rr6)r�r�r�r�r�r��
307  hash_based�check_sourcer��str/r�r�
308  bytes_data�code_objectr	r	r
309  r(�s�
310  ����
311  �
312  
313  ��������
314  
315  ���zSourceLoader.get_codeN)
316  r�r�r�r2r3r6r4r9r=r(r	r	r	r
317  r0{s
318  
319  r0cs\eZdZdZdd�Zdd�Zdd�Ze�fdd	��Zed
320  d��Z	dd
�Z
321  edd��Z�ZS)�
322  FileLoaderzgBase file loader class which implements the loader protocol methods that
323      require file system usage.cCs||_||_dS)zKCache the module name and the path to the file found by the
324          finder.Nr�)r�r�rGr	r	r
325  r!s
326  zFileLoader.__init__cC�|j|jko|j|jkSrL��	__class__r��r��otherr	r	r
327  �__eq__�
328  �zFileLoader.__eq__cC�t|j�t|j�ASrL��hashr�rG�r�r	r	r
329  �__hash__�zFileLoader.__hash__cstt|��|�S)zdLoad a module from a file.
330  
331          This method is deprecated.  Use exec_module() instead.
332  
333          )�superrJr/r.�rMr	r
334  r/s
335  zFileLoader.load_modulecC�|jS�z:Return the path to the source file as found by the finder.rNr.r	r	r
336  r�)�zFileLoader.get_filenamecCs�t|ttf�r$t�t|���}|��Wd�S1swYdSt�|d��}|��Wd�S1s9wYdS)z'Return the data from path as raw bytes.N�r)r�r0�ExtensionFileLoaderri�	open_coder�readrj)r�rGror	r	r
337  r7.s$�$�zFileLoader.get_datacCsddlm}||�S)Nr)�
338  FileReader)�importlib.readersra)r�r+rar	r	r
339  �get_resource_reader7szFileLoader.get_resource_reader)
r�r�r�r�r!rPrVr�r/r�r7rc�
__classcell__r	r	rYr
340  rJs
341  	rJc@s.eZdZdZdd�Zdd�Zdd�dd	�Zd
342  S)�SourceFileLoaderz>Concrete implementation of SourceLoader using the file system.cCst|�}|j|jd�S)z!Return the metadata for the path.)r�r@)rS�st_mtime�st_size)r�rGrGr	r	r
343  r3AszSourceFileLoader.path_statscCst|�}|j|||d�S)N��_mode)r�r4)r�r�r�r/rVr	r	r
344  r6Fsz SourceFileLoader._cache_bytecoder`rhc	Cs�t|�\}}g}|rt|�st|�\}}|�|�|rt|�rt|�D]1}t||�}zt�|�Wq#ty:Yq#tyT}zt	�
345  d||�WYd}~dSd}~wwzt|||�t	�
346  d|�WdSty~}zt	�
347  d||�WYd}~dSd}~ww)zWrite bytes data to a file.zcould not create {!r}: {!r}Nzcreated {!r})rQr\rC�reversedrJr�mkdir�FileExistsErrorrTr�r�rp)	r�rGr/ri�parentr�rErKr8r	r	r
348  r4Ks8
349  �
350  ������zSourceFileLoader.set_dataN)r�r�r�r�r3r6r4r	r	r	r
351  re=s
352  rec@s eZdZdZdd�Zdd�ZdS)�SourcelessFileLoaderz-Loader which handles sourceless file imports.cCsD|�|�}|�|�}||d�}t|||�tt|�dd�||d�S)Nr�r�)r�r�)r�r7r�r�rA)r�r�rGr/r�r	r	r
353  r(ns
354  
355  ��zSourcelessFileLoader.get_codecCr)z'Return None as there is no source code.Nr	r.r	r	r
356  r9~rzSourcelessFileLoader.get_sourceN)r�r�r�r�r(r9r	r	r	r
357  rnjsrnc@s\eZdZdZdd�Zdd�Zdd�Zdd	�Zd
358  d�Zdd
�Z	dd�Z
359  dd�Zedd��Z
dS)r^z]Loader for extension modules.
360  
361      The constructor is designed to work with FileFinder.
362  
363      cCs||_||_dSrLr�)r�r�rGr	r	r
364  r!�s
365  zExtensionFileLoader.__init__cCrKrLrLrNr	r	r
366  rP�rQzExtensionFileLoader.__eq__cCrRrLrSrUr	r	r
367  rV�rWzExtensionFileLoader.__hash__cCs$t�tj|�}t�d|j|j�|S)z&Create an unitialized extension modulez&extension module {!r} loaded from {!r})r�r)r��create_dynamicr�r�rG)r�r�r+r	r	r
368  r&�s��z!ExtensionFileLoader.create_modulecCs$t�tj|�t�d|j|j�dS)zInitialize an extension modulez(extension module {!r} executed from {!r}N)r�r)r��exec_dynamicr�r�rG�r�r+r	r	r
369  r,�s�zExtensionFileLoader.exec_modulecs$t|j�d�t�fdd�tD��S)z1Return True if the extension module is a package.rc3s�|]	}�d|kVqdS)r!Nr	�r�suffix��	file_namer	r
370  r�s��z1ExtensionFileLoader.is_package.<locals>.<genexpr>)rQrG�anyrr.r	rtr
371  r��s�zExtensionFileLoader.is_packagecCr)z?Return None as an extension module cannot create a code object.Nr	r.r	r	r
372  r(�rzExtensionFileLoader.get_codecCr)z5Return None as extension modules have no source code.Nr	r.r	r	r
373  r9�rzExtensionFileLoader.get_sourcecCrZr[rNr.r	r	r
374  r��r\z ExtensionFileLoader.get_filenameN)r�r�r�r�r!rPrVr&r,r�r(r9r�r�r	r	r	r
375  r^�sr^c@sleZdZdZdZdd�Zdd�Zdd�Zd	d
376  �Zdd�Z	d
d�Z
377  dd�Zdd�Zdd�Z
dd�Zdd�ZdS)�_NamespacePatha&Represents a namespace package's path.  It uses the module name
378      to find its parent module, and from there it looks up the parent's
379      __path__.  When this changes, the module's own path is recomputed,
380      using path_finder.  For top-level modules, the parent module's path
381      is sys.path.rcCs,||_||_t|���|_|j|_||_dSrL)�_name�_pathr��_get_parent_path�_last_parent_path�_epoch�_last_epoch�_path_finder�r�r�rG�path_finderr	r	r
382  r!�s
383  
384  z_NamespacePath.__init__cCs&|j�d�\}}}|dkrdS|dfS)z>Returns a tuple of (parent-module-name, parent-path-attr-name)rsr)rrG�__path__)rxrz)r�rm�dot�mer	r	r
385  �_find_parent_path_names�sz&_NamespacePath._find_parent_path_namescCs|��\}}ttj||�SrL)r�r�r�modules)r��parent_module_name�path_attr_namer	r	r
386  rz�sz_NamespacePath._get_parent_pathcCsdt|���}||jks|j|jkr/|�|j|�}|dur(|jdur(|jr(|j|_	||_|j|_|j	SrL)
387  r�rzr{r|r}r~rxr�r�ry)r��parent_pathr�r	r	r
388  �_recalculate�sz_NamespacePath._recalculatecC�t|���SrL)�iterr�rUr	r	r
389  �__iter__��z_NamespacePath.__iter__cCs|��|SrL�r�)r��indexr	r	r
390  �__getitem__�r�z_NamespacePath.__getitem__cCs||j|<dSrL)ry)r�r�rGr	r	r
391  �__setitem__�sz_NamespacePath.__setitem__cCr�rL)rr�rUr	r	r
392  �__len__�r�z_NamespacePath.__len__cC�d�|j�S)Nz_NamespacePath({!r}))rcryrUr	r	r
393  �__repr__�r�z_NamespacePath.__repr__cCs||��vSrLr��r��itemr	r	r
394  �__contains__�r�z_NamespacePath.__contains__cCs|j�|�dSrL)ryrCr�r	r	r
395  rC��z_NamespacePath.appendN)r�r�r�r�r|r!r�rzr�r�r�r�r�r�r�rCr	r	r	r
396  rw�s
397  rwc@sXeZdZdd�Zedd��Zdd�Zdd�Zd	d
398  �Zdd�Z	d
d�Z
399  dd�Zdd�ZdS)�_NamespaceLoadercCst|||�|_dSrL)rwryrr	r	r
400  r!�sz_NamespaceLoader.__init__cCst�dt�d�|j�S)zsReturn repr for the module.
401  
402          The method is deprecated.  The import machinery does the job itself.
403  
404          zR_NamespaceLoader.module_repr() is deprecated and slated for removal in Python 3.12z<module {!r} (namespace)>)rurvrwrcr�)r+r	r	r
405  �module_reprs�z_NamespaceLoader.module_reprcCr)NTr	r.r	r	r
406  r��z_NamespaceLoader.is_packagecCr)Nrr	r.r	r	r
407  r9r�z_NamespaceLoader.get_sourcecCstddddd�S)Nrz<string>r*T)r;)r<r.r	r	r
408  r(r�z_NamespaceLoader.get_codecCrr$r	r%r	r	r
409  r&r'z_NamespaceLoader.create_modulecCsdSrLr	rqr	r	r
410  r,r�z_NamespaceLoader.exec_modulecCst�d|j�t�||�S)zbLoad a namespace module.
411  
412          This method is deprecated.  Use exec_module() instead.
413  
414          z&namespace module loaded with path {!r})r�r�ryr-r.r	r	r
415  r/s�z_NamespaceLoader.load_modulecCsddlm}||j�S)Nr)�NamespaceReader)rbr�ry)r�r+r�r	r	r
416  rc's
417  z$_NamespaceLoader.get_resource_readerN)
r�r�r�r!rr�r�r9r(r&r,r/rcr	r	r	r
418  r��s
419  
420  r�c@sveZdZdZedd��Zedd��Zedd��Zedd	��Z	eddd��Z
421  edd
d��Zeddd��Zedd��Z
d
422  S)�
423  PathFinderz>Meta path finder for sys.path and package __path__ attributes.cCsNttj���D]\}}|durtj|=qt|d�r|��qtjd7_dS)z}Call the invalidate_caches() method on all path entry finders
424          stored in sys.path_importer_caches (where implemented).N�invalidate_cachesr)�listr�path_importer_cache�itemsr�r�rwr|)r��finderr	r	r
425  r�2s
426  
427  �zPathFinder.invalidate_cachesc	CsLtjdurtjst�dt�tjD]}z||�WSty#YqwdS)z.Search sys.path_hooks for a finder for 'path'.Nzsys.path_hooks is empty)r�
428  path_hooksrurvr�r�)rG�hookr	r	r
429  �_path_hooks?s
430  �zPathFinder._path_hookscCsd|dkrzt��}Wn
431  tyYdSwztj|}W|Sty1|�|�}|tj|<Y|Sw)z�Get the finder for the path entry from sys.path_importer_cache.
432  
433          If the path entry is not in the cache, find the appropriate finder
434          and cache it. If no finder is available, store None.
435  
436          rN)rr[�FileNotFoundErrorrr��KeyErrorr�)rrGr�r	r	r
437  �_path_importer_cacheLs��
438  �zPathFinder._path_importer_cachecCs�t|d�rt�|��d�}t�|t�|�|�\}}nt�|��d�}t�|t�|�|�}g}|dur:t�||�St�	|d�}||_
439  |S)Nr�z5.find_spec() not found; falling back to find_loader()z5.find_spec() not found; falling back to find_module())r�r��_object_namerurvr�r�rrr�r�)rr�r�r�r�r�r�r	r	r
440  �_legacy_get_specbs
441  
442  zPathFinder._legacy_get_specNc	Cs�g}|D]C}t|ttf�sq|�|�}|durGt|d�r#|�||�}n|�||�}|dur.q|jdur7|S|j}|durBt	d��|�
443  |�qt�|d�}||_|S)z?Find the loader or namespace_path for this module/package name.Nrzspec missing loader)
r�r�bytesr�r�rr�r�r�r�r�r�r�)	rr�rGr�namespace_path�entryr�r�r�r	r	r
444  �	_get_specws*
445  
446  
447  
448  �zPathFinder._get_speccCs^|durtj}|�|||�}|durdS|jdur-|j}|r+d|_t|||j�|_|SdS|S)z�Try to find a spec for 'fullname' on sys.path or 'path'.
449  
450          The search is based on sys.path_hooks and sys.path_importer_cache.
451          N)rrGr�r�r�r�rw)rr�rGrr�r�r	r	r
452  r�s
453  zPathFinder.find_speccCs*t�dt�|�||�}|durdS|jS)z�find the module on sys.path or 'path' based on sys.path_hooks and
454          sys.path_importer_cache.
455  
456          This method is deprecated.  Use find_spec() instead.
457  
458          zePathFinder.find_module() is deprecated and slated for removal in Python 3.12; use find_spec() insteadNrrr	r	r
459  r�s�zPathFinder.find_modulecOsddlm}|j|i|��S)a 
460          Find distributions.
461  
462          Return an iterable of all Distribution instances capable of
463          loading the metadata for packages matching ``context.name``
464          (or all names if ``None`` indicated) along the paths in the list
465          of directories ``context.path``.
466          r)�MetadataPathFinder)�importlib.metadatar��find_distributions)r�r�r�r	r	r
467  r��s
468  zPathFinder.find_distributionsrLr)r�r�r�r�rr�r�rr�r�r�rrr�r	r	r	r
469  r�.s$
470  
471  
472  
473  r�c@sZeZdZdZdd�Zdd�ZeZdd�Zdd	�Z	ddd�Z
474  d
d�Zedd��Z
dd�Zd
475  S)�
476  FileFinderz�File-based finder.
477  
478      Interactions with the file system are cached for performance, being
479      refreshed when the directory the finder is handling has been modified.
480  
481      cspg}|D]\�}|��fdd�|D��q||_|pd|_t|j�s+tt��|j�|_d|_t�|_	t�|_
482  dS)z�Initialize with the path to search on and a variable number of
483          2-tuples containing the loader and the file suffixes the loader
484          recognizes.c3s�|]}|�fVqdSrLr	rr�r�r	r
485  r�s�z&FileFinder.__init__.<locals>.<genexpr>rsr�N)r��_loadersrGr_rJrr[�_path_mtime�set�_path_cache�_relaxed_path_cache)r�rG�loader_details�loadersrr	r�r
486  r!�s
487  
488  zFileFinder.__init__cCs
489  d|_dS)zInvalidate the directory mtime.r�N)r�rUr	r	r
490  r��rZzFileFinder.invalidate_cachescCs6t�dt�|�|�}|durdgfS|j|jpgfS)z�Try to find a loader for the specified module, or the namespace
491          package portions. Returns (loader, list-of-portions).
492  
493          This method is deprecated.  Use find_spec() instead.
494  
495          zeFileFinder.find_loader() is deprecated and slated for removal in Python 3.12; use find_spec() insteadN)rurvrwrr�r�)r�r�r�r	r	r
496  r��s�
497  zFileFinder.find_loadercCs|||�}t||||d�S)Nr�)r)r�rr�rG�smslrr�r	r	r
498  r��s
499  �zFileFinder._get_specNc	Cszd}|�d�d}zt|jpt���j}Wnty d}Ynw||jkr-|��||_t	�r8|j
500  }|��}n|j}|}||vrlt
|j|�}|jD]\}	}
501  d|	}t
||�}t|�rg|�|
502  |||g|�SqJt|�}|jD]7\}	}
503  z
504  t
|j||	�}Wnty�YdSwtjd|dd�||	|vr�t|�r�|�|
505  ||d|�Sqo|r�t�d	|�t�|d�}
|g|
_|
SdS)
506  zoTry to find a spec for the specified module.
507  
508          Returns the matching spec, or None if not found.
509          Frsr2r�r!Nz	trying {})�	verbosityzpossible namespace for {})rzrSrGrr[rfrTr��_fill_cacherr�r�r�rJr�rYr�r\r�r�r�r�r�)r�r�r�is_namespace�tail_moduler��cache�cache_module�	base_pathrsr�
init_filename�	full_pathr�r	r	r
510  rsV�
511  
512  
513  ��
514  ��zFileFinder.find_specc	
515  Cs�|j}zt�|pt���}Wntttfyg}Ynwtj�	d�s)t
516  |�|_n%t
517  �}|D]}|�d�\}}}|rCd�
||���}n|}|�|�q.||_tj�	t�r^dd�|D�|_dSdS)zDFill the cache of potential modules and packages for this directory.rrsracSsh|]}|���qSr	)r�)r�fnr	r	r
518  rPsz)FileFinder._fill_cache.<locals>.<setcomp>N)rGr�listdirr[r��PermissionError�NotADirectoryErrorrrr r�r�r�rcr��addr!r�)	r�rG�contents�lower_suffix_contentsr�r�r�rs�new_namer	r	r
519  r�3s&��zFileFinder._fill_cachecs��fdd�}|S)aA class method which returns a closure to use on sys.path_hook
520          which will return an instance using the specified loaders and the path
521          called on the closure.
522  
523          If the path called on the closure is not a directory, ImportError is
524          raised.
525  
526          cs$t|�s
527  td|d���|g��R�S)z-Path hook for importlib.machinery.FileFinder.zonly directories are supportedrN)r\r�rN�rr�r	r
528  �path_hook_for_FileFinder\sz6FileFinder.path_hook.<locals>.path_hook_for_FileFinderr	)rr�r�r	r�r
529  �	path_hookRs
530  zFileFinder.path_hookcCr�)NzFileFinder({!r}))rcrGrUr	r	r
531  r�dr�zFileFinder.__repr__rL)r�r�r�r�r!r�r�rr�r�rr�rr�r�r	r	r	r
532  r��s
533  3
534  r�cCs�|�d�}|�d�}|s!|r|j}n||krt||�}nt||�}|s*t|||d�}z||d<||d<||d<||d<WdStyGYdSw)N�
535  __loader__�__spec__r��__file__�
536  __cached__)�getr�rnrer�	Exception)�nsr��pathname�	cpathnamer�r�r	r	r
537  �_fix_up_modulejs$
538  
539  
540  �r�cCs&tt��f}ttf}ttf}|||gS)z_Returns a list of file-based module loaders.
541  
542      Each item is a tuple (loader, suffixes).
543      )r^r��extension_suffixesrer�rnr�)�
544  extensions�source�bytecoder	r	r
545  r��s
546  r�cCs|adSrL)r�)�_bootstrap_moduler	r	r
547  �_set_bootstrap_module�sr�cCs2t|�t�}tj�tj|�g�tj�t	�dS)z)Install the path-based import components.N)
548  r�r�rr�r�r�r��	meta_pathrCr�)r��supported_loadersr	r	r
549  �_install�sr�)r`rL)NNN)rr)T)Ur�r�r�rirrur�rr�ntrr�posixr8�allrAr�r?rD�_pathseps_with_colonr"�%_CASE_INSENSITIVE_PLATFORMS_BYTES_KEYr!r#rr*r0r3rJrQrSrXrYr\r_rp�type�__code__r�r(r�r'r-rCr�r�r�rCr�rr��DEBUG_BYTECODE_SUFFIXES�OPTIMIZED_BYTECODE_SUFFIXESr�r�r�r�r�r�r�r�r�r�r�r�r�r��objectr�rrr r0rJrernr^rwr�r�r�r�r�r�r�r	r	r	r
550  �<module>s�
551  
552  
553  
554  �
555  
556  	
557  
558  
559  
560  G(!
561  
562  
563  
564  �IC2-5E1 
565