AlkantarClanX12

Your IP : 3.138.69.39


Current Path : /opt/alt/python34/lib64/python3.4/importlib/__pycache__/
Upload File :
Current File : //opt/alt/python34/lib64/python3.4/importlib/__pycache__/_bootstrap.cpython-34.pyc

�
e f!S�@s�dZd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Zdd�Zdd�Z	dd�Z
ddd�Zdd�Zdd�Z
eej�ZGdd�d�ZiZiZGdd �d e�ZGd!d"�d"�ZGd#d$�d$�ZGd%d&�d&�Zd'd(�Zd)d*�Zd+d,�Zd-jd.d/�d0Zejed/�Z d1Z!d2gZ"d3gZ#d4gZ$d5d6d7�Z%d8d9�Z&d:d;�Z'd<d=�Z(d>d?d@dA�Z)dBdC�Z*dDdE�Z+dFdG�Z,dHdI�Z-dJdK�Z.d5d5d5dLdM�Z/d5d5d5dNdO�Z0dPdPdQdR�Z1dSdT�Z2dUdV�Z3GdWdX�dX�Z4GdYdZ�dZ�Z5d[d5d\d5d]d^�Z6e7�Z8d5d_d5d`e8dadb�Z9d5d5dcdd�Z:Gdedf�df�Z;d5dgdh�Z<Gdidj�dj�Z=Gdkdl�dl�Z>Gdmdn�dn�Z?Gdodp�dp�Z@Gdqdr�dre@�ZAGdsdt�dt�ZBGdudv�dveBeA�ZCGdwdx�dxeBe@�ZDgZEGdydz�dz�ZFGd{d|�d|�ZGGd}d~�d~�ZHGdd��d��ZIGd�d��d��ZJGd�d��d��ZKd�d��ZLd�d��ZMd5d�d��ZNd�d��ZOd�ZPePd�ZQd�d��ZRd�d��ZSd5dPd�d��ZTd�d��ZUd�d��ZVd�d��ZWd5d5fdPd�d��ZXd�d��ZYd�d��ZZd�d��Z[d5S)�aSCore 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.

�win�cygwin�darwincCs1tjjt�r!dd�}ndd�}|S)NcSs
dtjkS)z5True if filenames must be checked case-insensitively.sPYTHONCASEOK)�_os�environ�rr�9/opt/alt/python34/lib64/python3.4/importlib/_bootstrap.py�_relax_casesz%_make_relax_case.<locals>._relax_casecSsdS)z5True if filenames must be checked case-insensitively.Frrrrrr"s)�sys�platform�
startswith�_CASE_INSENSITIVE_PLATFORMS)rrrr�_make_relax_casesr
cCst|�d@jdd�S)z*Convert a 32-bit integer to little-endian.l����little)�int�to_bytes)�xrrr�_w_long(srcCstj|d�S)z/Convert 4 bytes in little-endian to an integer.r)r�
from_bytes)�	int_bytesrrr�_r_long-srcGstjdd�|D��S)zReplacement for os.path.join().cSs%g|]}|r|jt��qSr)�rstrip�path_separators)�.0�partrrr�
<listcomp>4s	z_path_join.<locals>.<listcomp>)�path_sep�join)�
path_partsrrr�
_path_join2srcCs�tt�dkr4|jt�\}}}||fSxEt|�D]7}|tkrA|j|dd�\}}||fSqAWd|fS)z Replacement for os.path.split().��maxsplit�)�lenr�
rpartitionr�reversed�rsplit)�path�front�_�tailrrrr�_path_split8s
r+cCs
tj|�S)z~Stat the path.

    Made a separate function to make it easier to override in experiments
    (e.g. cache stat results).

    )r�stat)r'rrr�
_path_statDsr-cCs:yt|�}Wntk
r(dSYnX|jd@|kS)z1Test whether the path is the specified mode type.Fi�)r-�OSError�st_mode)r'�mode�	stat_inforrr�_path_is_mode_typeNs

	r2cCs
t|d�S)zReplacement for os.path.isfile.i�)r2)r'rrr�_path_isfileWsr3cCs"|stj�}nt|d�S)zReplacement for os.path.isdir.i@)r�getcwdr2)r'rrr�_path_isdir\sr5i�cCs�dj|t|��}tj|tjtjBtjB|d@�}y<tj|d��}|j	|�WdQXtj
||�Wn;tk
r�ytj|�Wntk
r�YnX�YnXdS)z�Best-effort function to write data to a path atomically.
    Be prepared to handle a FileExistsError if concurrent writing of the
    temporary file is attempted.z{}.{}i��wbN)
�format�idr�open�O_EXCL�O_CREAT�O_WRONLY�_io�FileIO�write�replacer.�unlink)r'�datar0�path_tmp�fd�filerrr�
_write_atomiccs	!

rFcCs_xEddddgD]1}t||�rt||t||��qqW|jj|j�dS)z/Simple substitute for functools.update_wrapper.�
__module__�__name__�__qualname__�__doc__N)�hasattr�setattr�getattr�__dict__�update)�new�oldr@rrr�_wrapys rRcCstt�|�S)N)�typer	)�namerrr�_new_module�srUc@s:eZdZdZdd�Zdd�Zdd�ZdS)	�
_ManageReloadz?Manages the possible clean-up of sys.modules for load_module().cCs
||_dS)N)�_name)�selfrTrrr�__init__�sz_ManageReload.__init__cCs|jtjk|_dS)N)rWr	�modules�
_is_reload)rXrrr�	__enter__�sz_ManageReload.__enter__cGsPtdd�|D��rL|jrLytj|j=WqLtk
rHYqLXndS)Ncss|]}|dk	VqdS)Nr)r�argrrr�	<genexpr>�sz)_ManageReload.__exit__.<locals>.<genexpr>)�anyr[r	rZrW�KeyError)rX�argsrrr�__exit__�s
#
z_ManageReload.__exit__N)rHrGrIrJrYr\rbrrrrrV�srVc@seZdZdS)�_DeadlockErrorN)rHrGrIrrrrrc�srcc@sReZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�_ModuleLockz�A 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).
    cCsFtj�|_tj�|_||_d|_d|_d|_dS)N�)�_thread�
allocate_lock�lock�wakeuprT�owner�count�waiters)rXrTrrrrY�s			z_ModuleLock.__init__cCsXtj�}|j}x<tj|�}|dkr7dS|j}||krdSqWdS)NFT)rf�	get_identrj�_blocking_on�get)rX�me�tidrhrrr�has_deadlock�s		z_ModuleLock.has_deadlockcCs�tj�}|t|<z�x�|j��|jdksD|j|kr`||_|jd7_dS|j�rtd|��n|jj	d�r�|j
d7_
nWdQX|jj	�|jj�qWWdt|=XdS)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.
        rer Tzdeadlock detected by %rFN)rfrmrnrhrkrjrrrcri�acquirerl�release)rXrqrrrrs�s 

	
z_ModuleLock.acquirec
Cs�tj�}|j��|j|kr4td��n|jdksIt�|jd8_|jdkr�d|_|jr�|jd8_|jj	�q�nWdQXdS)Nzcannot release un-acquired lockrer )
rfrmrhrj�RuntimeErrorrk�AssertionErrorrlrirt)rXrqrrrrt�s
		z_ModuleLock.releasecCsdj|jt|��S)Nz_ModuleLock({!r}) at {})r7rTr8)rXrrr�__repr__�sz_ModuleLock.__repr__N)	rHrGrIrJrYrrrsrtrwrrrrrd�s
rdc@sFeZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�_DummyModuleLockzVA simple _ModuleLock equivalent for Python builds without
    multi-threading support.cCs||_d|_dS)Nre)rTrk)rXrTrrrrY�s	z_DummyModuleLock.__init__cCs|jd7_dS)Nr T)rk)rXrrrrs�sz_DummyModuleLock.acquirecCs1|jdkrtd��n|jd8_dS)Nrezcannot release un-acquired lockr )rkru)rXrrrrt�sz_DummyModuleLock.releasecCsdj|jt|��S)Nz_DummyModuleLock({!r}) at {})r7rTr8)rXrrrrw�sz_DummyModuleLock.__repr__N)rHrGrIrJrYrsrtrwrrrrrx�s
rxc@s4eZdZdd�Zdd�Zdd�ZdS)�_ModuleLockManagercCs||_d|_dS)N)rW�_lock)rXrTrrrrYs	z_ModuleLockManager.__init__c
Cs5zt|j�|_Wdtj�X|jj�dS)N)�_get_module_lockrWrz�_imp�release_lockrs)rXrrrr\sz_ModuleLockManager.__enter__cOs|jj�dS)N)rzrt)rXra�kwargsrrrrbsz_ModuleLockManager.__exit__N)rHrGrIrYr\rbrrrrry�srycs�d}yt��}Wntk
r+YnX|dkr�tdkrSt��}nt��}�fdd�}tj||�t�<n|S)zmGet or create the module lock for a given module name.

    Should only be called with the import lock taken.Ncst�=dS)N)�
_module_locks)r))rTrr�cb sz_get_module_lock.<locals>.cb)rr`rfrxrd�_weakref�ref)rTrhr�r)rTrr{s
r{cCsGt|�}tj�y|j�Wntk
r8YnX|j�dS)aRelease the global import lock, and acquires then release 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.

    Should only be called with the import lock taken.N)r{r|r}rsrcrt)rTrhrrr�_lock_unlock_module%s

r�cOs
|||�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)�fra�kwdsrrr�_call_with_frames_removed9sr�i��rs
�__pycache__z.pyz.pycz.pyoNcCs�|dkrtjjn|}|r.t}nt}t|�\}}|jd�\}}}tjj}	|	dkr�t	d��ndj
|r�|n|||	|dg�}
t|t|
�S)a�Given the path to a .py file, return the path to its .pyc/.pyo file.

    The .py file does not need to exist; this simply returns the path to the
    .pyc/.pyo file calculated as if the .py file were imported.  The extension
    will be .pyc unless sys.flags.optimize is non-zero, then it will be .pyo.

    If debug_override is not None, then it must be a boolean and is used in
    place of sys.flags.optimize.

    If sys.implementation.cache_tag is None then NotImplementedError is raised.

    N�.z$sys.implementation.cache_tag is Noner"re)
r	�flags�optimize�DEBUG_BYTECODE_SUFFIXES�OPTIMIZED_BYTECODE_SUFFIXESr+r$�implementation�	cache_tag�NotImplementedErrorrr�_PYCACHE)r'�debug_override�debug�suffixes�headr*�base�sep�rest�tag�filenamerrr�cache_from_source�s
	+r�cCs�tjjdkr!td��nt|�\}}t|�\}}|tkrltdjt|���n|jd�dkr�tdj|���n|j	d�d}t
||td�S)ayGiven the path to a .pyc./.pyo file, return the path to its .py file.

    The .pyc/.pyo file does not need to exist; this simply returns the path to
    the .py file calculated to correspond to the .pyc/.pyo file.  If path does
    not conform to PEP 3147 format, ValueError will be raised. If
    sys.implementation.cache_tag is None then NotImplementedError is raised.

    Nz$sys.implementation.cache_tag is Nonez%{} not bottom-level directory in {!r}r�r�zexpected only 2 dots in {!r}re)r	r�r�r�r+r��
ValueErrorr7rk�	partitionr�SOURCE_SUFFIXES)r'r��pycache_filename�pycache�
base_filenamerrr�source_from_cache�s			r�cCs�t|�dkrdS|jd�\}}}|sQ|j�dd�dkrU|Syt|�}Wn(ttfk
r�|dd	�}YnXt|�r�|S|S)
z�Convert a bytecode file path to a source path (if possible).

    This function exists purely for backwards-compatibility for
    PyImport_ExecCodeModuleWithFilenames() in the C API.

    reNr��r �py������r�)r#r$�lowerr�r�r�r3)�
bytecode_pathr�r)�	extension�source_pathrrr�_get_sourcefile�s#r�cCs<yt|�j}Wntk
r-d}YnX|dO}|S)z3Calculate the mode permissions for a bytecode file.i��)r-r/r.)r'r0rrr�
_calc_mode�s

r��	verbosityr cGsQtjj|krM|jd�s.d|}nt|j|�dtj�ndS)z=Print the message to stderr if -v/PYTHONVERBOSE is turned on.�#�import z# rEN)r�r�)r	r��verboser�printr7�stderr)�messager�rarrr�_verbose_messages
r�cs&d�fdd�}t|��|S)z�Decorator to verify that the module being requested matches the one the
    loader can handle.

    The first argument (self) must define _name which the second argument is
    compared against. If the comparison fails then ImportError is raised.

    NcsS|dkr|j}n(|j|kr@td|d|��n�||||�S)Nzloader cannot handle %srT)rT�ImportError)rXrTrar~)�methodrr�_check_name_wrappers
z(_check_name.<locals>._check_name_wrapper)rR)r�r�r)r�r�_check_names
r�cs#�fdd�}t|��|S)z1Decorator to verify the named module is built-in.cs:|tjkr-tdj|�d|��n�||�S)Nz{!r} is not a built-in modulerT)r	�builtin_module_namesr�r7)rX�fullname)�fxnrr�_requires_builtin_wrapper"sz4_requires_builtin.<locals>._requires_builtin_wrapper)rR)r�r�r)r�r�_requires_builtin s
r�cs#�fdd�}t|��|S)z/Decorator to verify the named module is frozen.cs:tj|�s-tdj|�d|��n�||�S)Nz{!r} is not a frozen modulerT)r|�	is_frozenr�r7)rXr�)r�rr�_requires_frozen_wrapper-sz2_requires_frozen.<locals>._requires_frozen_wrapper)rR)r�r�r)r�r�_requires_frozen+s
r�cCsW|j|�\}}|dkrSt|�rSd}tj|j|d�t�n|S)z�Try to find a loader for the specified module by delegating to
    self.find_loader().

    This method is deprecated in favor of finder.find_spec().

    Nz,Not importing directory {}: missing __init__re)�find_loaderr#�	_warnings�warnr7�
ImportWarning)rXr��loader�portions�msgrrr�_find_module_shim6s

 r�cCs]t||�}t|�}|tjkrOtj|}|j|�tj|S|j�SdS)z�Load the specified module into sys.modules and return it.

    This method is deprecated.  Use loader.exec_module instead.

    N)�spec_from_loader�_SpecMethodsr	rZ�exec�load)rXr��spec�methods�modulerrr�_load_module_shimGs

r�cCs�i}|dk	r||d<nd}|dk	r>||d<n|dd�}|dd�}|dd�}|tkr�dj||�}td	|�t||��nzt|�dkr�d
j|�}td	|�t|��n=t|�dkr%dj|�}td	|�t|��n|dk	r�yt|d�}	Wntk
rYYnAXt|�|	kr�d
j|�}td	|�t||��ny|dd@}
Wntk
r�Yq�Xt|�|
kr�td
j|�|��q�n|dd�S)azValidate the header of the passed-in bytecode against source_stats (if
    given) and returning the bytecode that can be compiled by compile().

    All other arguments are used to enhance error reporting.

    ImportError is raised when the magic number is incorrect or the bytecode is
    found to be stale. EOFError is raised when the data is found to be
    truncated.

    NrTz
<bytecode>r'r��zbad magic number in {!r}: {!r}z{}z+reached EOF while reading timestamp in {!r}z0reached EOF while reading size of source in {!r}�mtimezbytecode is stale for {!r}�sizel��)	�MAGIC_NUMBERr7r�r�r#�EOFErrorrr`r)rB�source_statsrTr'�exc_details�magic�
raw_timestamp�raw_sizer��source_mtime�source_sizerrr�_validate_bytecode_headerWsL







r�cCsstj|�}t|t�rNtd|�|dk	rJtj||�n|Stdj|�d|d|��dS)z<Compile bytecode as returned by _validate_bytecode_header().zcode object from {!r}NzNon-code object in {!r}rTr')	�marshal�loads�
isinstance�
_code_typer�r|�_fix_co_filenamer�r7)rBrTr�r��coderrr�_compile_bytecode�s
r�recCsLtt�}|jt|��|jt|��|jtj|��|S)zPCompile a code object into bytecode for writing out to a byte-compiled
    file.)�	bytearrayr��extendrr��dumps)r�r�r�rBrrr�_code_to_bytecode�s
r�cCsYddl}tj|�j}|j|�}tjdd�}|j|j|d��S)zyDecode bytes representing source code and return the string.

    Universal newline support is used in the decoding.
    reNT)�tokenizer=�BytesIO�readline�detect_encoding�IncrementalNewlineDecoder�decode)�source_bytesr��source_bytes_readline�encoding�newline_decoderrrr�
decode_source�s
r�c#Cst|dd�}t|d�rJy|j|�SWqJtk
rFYqJXny
|j}Wntk
rkYnX|dk	r�t|�j�Sy
|j}Wntk
r�d}YnXy
|j}Wn;tk
r�|dkr�dj	|�Sdj	||�SYnXdj	||�SdS)N�
__loader__�module_repr�?z
<module {!r}>z<module {!r} ({!r})>z<module {!r} from {!r}>)
rMrKr��	Exception�__spec__�AttributeErrorr�rH�__file__r7)r�r�r�rTr�rrr�_module_repr�s.







r�c@s4eZdZdd�Zdd�Zdd�ZdS)�_installed_safelycCs||_|j|_dS)N)�_moduler��_spec)rXr�rrrrY�s	z_installed_safely.__init__cCs&d|j_|jtj|jj<dS)NT)r�
_initializingr�r	rZrT)rXrrrr\�sz_installed_safely.__enter__cGsyze|j}tdd�|D��rNytj|j=Wqdtk
rJYqdXntd|j|j�Wdd|j_XdS)Ncss|]}|dk	VqdS)Nr)rr]rrrr^�sz-_installed_safely.__exit__.<locals>.<genexpr>zimport {!r} # {!r}F)	rr_r	rZrTr`r�r�r)rXrar�rrrrb�s	
z_installed_safely.__exit__N)rHrGrIrYr\rbrrrrr��sr�c@s�eZdZdZdddddddd�Zdd	�Zd
d�Zedd
��Zej	dd
��Zedd��Z
edd��Zej	dd��ZdS)�
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.

    �originN�loader_state�
is_packagecCsO||_||_||_||_|r0gnd|_d|_d|_dS)NF)rTr�rr�submodule_search_locations�
_set_fileattr�_cached)rXrTr�rrrrrrrYs					zModuleSpec.__init__cCs�dj|j�dj|j�g}|jdk	rO|jdj|j��n|jdk	rz|jdj|j��ndj|jjdj|��S)Nz	name={!r}zloader={!r}zorigin={!r}zsubmodule_search_locations={}z{}({})z, )	r7rTr�r�appendr�	__class__rHr)rXrarrrrw"szModuleSpec.__repr__cCs�|j}yk|j|jkor|j|jkor|j|jkor||jkor|j|jkor|j|jkSWntk
r�dSYnXdS)NF)rrTr�r�cached�has_locationr�)rX�other�smslrrr�__eq__,s	
zModuleSpec.__eq__cCs�|jdkr�|jdk	r�|jr�|j}|jtt��rpyt|�|_Wq�tk
rlYq�Xq�|jtt��r�||_q�q�n|jS)N)	rrr�endswith�tupler�r�r��BYTECODE_SUFFIXES)rXr�rrrr8s	
zModuleSpec.cachedcCs
||_dS)N)r)rXrrrrrFscCs.|jdkr#|jjd�dS|jSdS)z The name of the module's parent.Nr�re)rrTr$)rXrrr�parentJszModuleSpec.parentcCs|jS)N)r)rXrrrrRszModuleSpec.has_locationcCst|�|_dS)N)�boolr)rX�valuerrrrVs)rHrGrIrJrYrwr�propertyr�setterrrrrrrr�s#
rrrcCs�t|d�rS|dkr+t|d|�S|r7gnd}t|d|d|�S|dkr�t|d�r�y|j|�}Wq�tk
r�d}Yq�Xq�d}nt||d|d|�S)z5Return a module spec based on various loader methods.�get_filenameNr�rrFr)rK�spec_from_file_locationrr�r)rTr�rr�searchrrrr�[s
	r�r�rc	Csn|dkrOd}t|d�rOy|j|�}WqLtk
rHYqLXqOnt||d|�}d|_|dkr�xOt�D]=\}}|jt|��r�|||�}||_Pq�q�WdSn|t	kr&t|d�r/y|j
|�}Wntk
r
Yq#X|r#g|_q#q/n	||_|jgkrj|rjt|�d}|jj
|�qjn|S)a=Return a module spec based on a file location.

    To indicate that the module is a package, set
    submodule_search_locations to a list of directory paths.  An
    empty list is sufficient, though its not otherwise useful to the
    import system.

    The loader must take a spec as its only __init__() arg.

    Nz	<unknown>rrTrre)rKrr�rr�_get_supported_file_loadersrrr��	_POPULATErrr+r	)	rT�locationr�rr��loader_classr�r�dirnamerrrrts<
		
	rc5Cs|y
|j}Wntk
r!YnX|dk	r2|S|j}|dkrly
|j}Wqltk
rhYqlXny
|j}Wntk
r�d}YnX|dkr�|dkr�y
|j}Wq�tk
r�d}Yq�Xq�|}ny
|j}Wntk
rd}YnXyt|j�}Wntk
r5d}YnXt	||d|�}|dkr]dnd|_
||_||_|S)NrFT)
r�r�rHr�r��_ORIGIN�
__cached__�list�__path__rrrr)r�r�rr�rTrrrrrr�_spec_from_module�sH

	





	


		r$c@s�eZdZdZdd�Zdd�Zdddd	d
d�Zdd
�Zdd�Zdd�Z	dd�Z
dd�Zdd�ZdS)r�zMConvenience wrapper around spec objects to provide spec-specific
    methods.cCs
||_dS)N)r�)rXr�rrrrY�sz_SpecMethods.__init__cCs�|j}|jdkrdn|j}|jdkrh|jdkrRdj|�Sdj||j�Sn2|jr�dj||j�Sdj|j|j�SdS)z&Return the repr to use for the module.Nr�z
<module {!r}>z<module {!r} ({!r})>z<module {!r} from {!r}>z<module {!r} ({})>)r�rTrr�r7r)rXr�rTrrrr��s	
	z_SpecMethods.module_repr�	_overrideF�_force_nameTc;CsK|j}|s-|s-t|dd�dkrUy|j|_WqUtk
rQYqUXn|sst|dd�dkr�|j}|dkr�|jdk	r�tjt�}|j|_	q�ny
||_
Wq�tk
r�Yq�Xn|s�t|dd�dkr#y|j|_Wq#tk
rYq#Xny
||_
Wntk
rDYnX|sct|dd�dkr�|jdk	r�y|j|_Wq�tk
r�Yq�Xq�n|jrG|s�t|dd�dkr�y|j|_Wq�tk
r�Yq�Xn|s
t|dd�dkrG|jdk	rDy|j|_WqAtk
r=YqAXqDqGndS)aSet the module's attributes.

        All missing import-related module attributes will be set.  Here
        is how the spec attributes map onto the module:

        spec.name -> module.__name__
        spec.loader -> module.__loader__
        spec.parent -> module.__package__
        spec -> module.__spec__

        Optional:
        spec.origin -> module.__file__ (if spec.set_fileattr is true)
        spec.cached -> module.__cached__ (if __file__ also set)
        spec.submodule_search_locations -> module.__path__ (if set)

        rHNr��__package__r#r�r!)r�rMrTrHr�r�r�_NamespaceLoader�__new__�_pathr�rr'r�r#rrr�rr!)rXr�r%r&r�r�rrr�init_module_attrs�sX	
	





	

z_SpecMethods.init_module_attrscCse|j}t|jd�r0|jj|�}nd}|dkrTt|j�}n|j|�|S)z�Return a new module to be loaded.

        The import-related module attributes are also set with the
        appropriate values from the spec.

        �
create_moduleN)r�rKr�r,rUrTr+)rXr�r�rrr�createKs	
z_SpecMethods.createcCs|jjj|�dS)z�Do everything necessary to execute the module.

        The namespace of `module` is used as the target of execution.
        This method uses the loader's `exec_module()` method.

        N)r�r��exec_module)rXr�rrr�_execbsz_SpecMethods._execcCs|jj}tj�t|���tjj|�|k	r_dj|�}t	|d|��n|jj
dkr�|jjdkr�t	dd|jj��n|j|dd�|S|j|dd�t
|jj
d�s�|jj
j|�n
|j|�WdQXtj|S)z3Execute the spec in an existing module's namespace.zmodule {!r} not in sys.modulesrTNzmissing loaderr%Tr.)r�rTr|�acquire_lockryr	rZror7r�r�rr+rK�load_moduler/)rXr�rTr�rrrr�ls 

z_SpecMethods.execcCs|j}|jj|j�tj|j}t|dd�dkrly|j|_Wqltk
rhYqlXnt|dd�dkr�y;|j	|_
t|d�s�|jjd�d|_
nWq�tk
r�Yq�Xnt|dd�dkry
||_
Wqtk
rYqXn|S)Nr�r'r#r�rer�)r�r�r1rTr	rZrMr�r�rHr'rKr$r�)rXr�r�rrr�_load_backward_compatible�s*	
 


z&_SpecMethods._load_backward_compatiblecCs�|jjdk	r4t|jjd�s4|j�Sn|j�}t|��T|jjdkr�|jjdkr�tdd|jj��q�n
|j	|�WdQXt
j|jjS)Nr.zmissing loaderrT)r�r�rKr2r-r�rr�rTr/r	rZ)rXr�rrr�_load_unlocked�s

z_SpecMethods._load_unlockedcCs1tj�t|jj��|j�SWdQXdS)z�Return 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|r0ryr�rTr3)rXrrrr��s	
z_SpecMethods.loadN)
rHrGrIrJrYr�r+r-r/r�r2r3r�rrrrr��sP
r�cCs�|jd�}|jd�}|sf|r6|j}qf||krTt||�}qft||�}n|s�t||d|�}ny,||d<||d<||d<||d<Wntk
r�YnXdS)Nr�r�r�r�r!)ror��SourcelessFileLoader�SourceFileLoaderrr�)�nsrT�pathname�	cpathnamer�r�rrr�_fix_up_module�s"



r9c@s�eZdZdZedd��Zedddd��Zeddd��Zee	d	d
���Z
ee	dd���Zee	d
d���Zee	dd���Z
dS)�BuiltinImporterz�Meta path import for built-in modules.

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

    cCsdj|j�S)zsReturn repr for the module.

        The method is deprecated.  The import machinery does the job itself.

        z<module {!r} (built-in)>)r7rH)r�rrrr��szBuiltinImporter.module_reprNcCs:|dk	rdStj|�r2t||dd�SdSdS)Nrzbuilt-in)r|�
is_builtinr�)�clsr�r'�targetrrr�	find_spec�s
zBuiltinImporter.find_speccCs)|j||�}|dk	r%|jSdS)z�Find the built-in module.

        If 'path' is ever specified then the search is considered a failure.

        This method is deprecated.  Use find_spec() instead.

        N)r>r�)r<r�r'r�rrr�find_module�s	zBuiltinImporter.find_modulec
Cs;t|��ttj|�}WdQX||_d|_|S)zLoad a built-in module.Nr")rVr�r|�init_builtinr�r')r<r�r�rrrr1s

		zBuiltinImporter.load_modulecCsdS)z9Return None as built-in modules do not have code objects.Nr)r<r�rrr�get_codeszBuiltinImporter.get_codecCsdS)z8Return None as built-in modules do not have source code.Nr)r<r�rrr�
get_sourceszBuiltinImporter.get_sourcecCsdS)z4Return False as built-in modules are never packages.Fr)r<r�rrrrszBuiltinImporter.is_package)rHrGrIrJ�staticmethodr��classmethodr>r?r�r1rArBrrrrrr:�s	r:c@s�eZdZdZedd��Zedddd��Zeddd��Zed	d
��Z	edd��Z
eed
d���Zeedd���Z
eedd���ZdS)�FrozenImporterz�Meta path import for frozen modules.

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

    cCsdj|j�S)zsReturn repr for the module.

        The method is deprecated.  The import machinery does the job itself.

        z<module {!r} (frozen)>)r7rH)�mrrrr�/szFrozenImporter.module_reprNcCs*tj|�r"t||dd�SdSdS)Nr�frozen)r|r�r�)r<r�r'r=rrrr>8szFrozenImporter.find_speccCstj|�r|SdS)z]Find a frozen module.

        This method is deprecated.  Use find_spec() instead.

        N)r|r�)r<r�r'rrrr??szFrozenImporter.find_modulecCs_|jj}tj|�s9tdj|�d|��nttj|�}t||j	�dS)Nz{!r} is not a frozen modulerT)
r�rTr|r�r�r7r��get_frozen_objectr�rN)r�rTr�rrrr.HszFrozenImporter.exec_modulecCs
t||�S)z_Load a frozen module.

        This method is deprecated.  Use exec_module() instead.

        )r�)r<r�rrrr1QszFrozenImporter.load_modulecCs
tj|�S)z-Return the code object for the frozen module.)r|rH)r<r�rrrrAZszFrozenImporter.get_codecCsdS)z6Return None as frozen modules do not have source code.Nr)r<r�rrrrB`szFrozenImporter.get_sourcecCs
tj|�S)z.Return True if the frozen module is a package.)r|�is_frozen_package)r<r�rrrrfszFrozenImporter.is_package)rHrGrIrJrCr�rDr>r?r.r1r�rArBrrrrrrE&s			rEc@syeZdZdZdZdZdZedd��Zedd��Z	ed	d	d
d��Z
ed	d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}\DebugFcCsCytjtj|�SWn%tk
r>tjtj|�SYnXdS)N)�_winreg�OpenKey�HKEY_CURRENT_USERr.�HKEY_LOCAL_MACHINE)r<�keyrrr�_open_registryys
z$WindowsRegistryFinder._open_registrycCs�|jr|j}n	|j}|jd|dtjdd��}y.|j|��}tj|d�}WdQXWnt	k
r�dSYnX|S)Nr��sys_versionr�r")
�DEBUG_BUILD�REGISTRY_KEY_DEBUG�REGISTRY_KEYr7r	�versionrPrK�
QueryValuer.)r<r��registry_keyrO�hkey�filepathrrr�_search_registry�s		
	z&WindowsRegistryFinder._search_registryNcCs�|j|�}|dkrdSyt|�Wntk
rEdSYnXxNt�D]C\}}|jt|��rPt||||�d|�}|SqPWdS)Nr)rZr-r.rrrr�)r<r�r'r=rYr�r�r�rrrr>�s
		zWindowsRegistryFinder.find_speccCs-|j||�}|dk	r%|jSdSdS)zlFind module named in the registry.

        This method is deprecated.  Use exec_module() instead.

        N)r>r�)r<r�r'r�rrrr?�sz!WindowsRegistryFinder.find_module)rHrGrIrJrTrSrRrDrPrZr>r?rrrrrJmsrJc@s4eZdZdZdd�Zdd�ZeZdS)�
_LoaderBasicszSBase class of common code needed by both SourceLoader and
    SourcelessFileLoader.cCsXt|j|��d}|jdd�d}|jd�d}|dkoW|dkS)z�Concrete implementation of InspectLoader.is_package by checking if
        the path returned by get_filename has a filename of '__init__.py'.r r�rer�rY)r+rr&r$)rXr�r��
filename_base�	tail_namerrrr�sz_LoaderBasics.is_packagecCsP|j|j�}|dkr9tdj|j���ntt||j�dS)zExecute the module.Nz4cannot load module {!r} when get_code() returns None)rArHr�r7r�r�rN)rXr�r�rrrr.�s
	z_LoaderBasics.exec_moduleN)rHrGrIrJrr.r�r1rrrrr[�sr[c@sjeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zddd
d�Zdd�Z	dS)�SourceLoadercCs
t�dS)z�Optional method that returns the modification time (an int) for the
        specified path, where path is a str.

        Raises IOError when the path cannot be handled.
        N)�IOError)rXr'rrr�
path_mtime�szSourceLoader.path_mtimecCsi|j|�d6S)a�Optional method returning a metadata dict for the specified path
        to by the path (str).
        Possible keys:
        - 'mtime' (mandatory) is the numeric timestamp of last source
          code modification;
        - 'size' (optional) is the size in bytes of the source code.

        Implementing this method allows the loader to read bytecode files.
        Raises IOError when the path cannot be handled.
        r�)r`)rXr'rrr�
path_stats�szSourceLoader.path_statscCs|j||�S)z�Optional method which writes data (bytes) to a file path (a str).

        Implementing this method allows for the writing of bytecode files.

        The source path is needed in order to correctly transfer permissions
        )�set_data)rXr��
cache_pathrBrrr�_cache_bytecode�szSourceLoader._cache_bytecodecCsdS)z�Optional method which writes data (bytes) to a file path (a str).

        Implementing this method allows for the writing of bytecode files.
        Nr)rXr'rBrrrrb�szSourceLoader.set_datacCsi|j|�}y|j|�}Wn:tk
r^}ztdd|�|�WYdd}~XnXt|�S)z4Concrete implementation of InspectLoader.get_source.z'source not available through get_data()rTN)r�get_datar.r�r�)rXr�r'r��excrrrrB�s	zSourceLoader.get_source�	_optimizer c	Cstt||dddd|�S)z�Return the code object compiled from source.

        The 'data' argument can be any object type that compile() supports.
        r��dont_inheritTr�)r��compile)rXrBr'rgrrr�source_to_code�szSourceLoader.source_to_codec
+Cs�|j|�}d}yt|�}Wntk
r?d}Yn�Xy|j|�}Wntk
rgYn�Xt|d�}y|j|�}Wntk
r�YnjXy"t|d|d|d|�}Wnt	t
fk
r�Yn-Xtd||�t|d|d|d|�S|j|�}|j
||�}	td	|�tjr�|dk	r�|dk	r�t|	|t|��}y$|j|||�td
|�Wq�tk
r�Yq�Xn|	S)z�Concrete implementation of InspectLoader.get_code.

        Reading of bytecode requires path_stats to be implemented. To write
        bytecode, set_data must also be implemented.

        Nr�r�rTr'z
{} matches {}r�r�zcode object from {}z
wrote {!r})rr�r�rar_rrer.r�r�r�r�r�rjr	�dont_write_bytecoder�r#rd)
rXr�r�r�r��strB�
bytes_datar��code_objectrrrrA�sN


	
	
	
zSourceLoader.get_codeNr�)
rHrGrIr`rardrbrBrjrArrrrr^�s


r^cspeZdZdZdd�Zdd�Zdd�Ze�fdd	��Zed
d��Z	dd
�Z
�S)�
FileLoaderzgBase file loader class which implements the loader protocol methods that
    require file system usage.cCs||_||_dS)zKCache the module name and the path to the file found by the
        finder.N)rTr')rXr�r'rrrrY7s	zFileLoader.__init__cCs"|j|jko!|j|jkS)N)r
rN)rXr
rrrr=szFileLoader.__eq__cCst|j�t|j�AS)N)�hashrTr')rXrrr�__hash__AszFileLoader.__hash__cstt|�j|�S)zdLoad a module from a file.

        This method is deprecated.  Use exec_module() instead.

        )�superror1)rXr�)r
rrr1Ds
zFileLoader.load_modulecCs|jS)z:Return the path to the source file as found by the finder.)r')rXr�rrrrPszFileLoader.get_filenamecCs)tj|d��}|j�SWdQXdS)z'Return the data from path as raw bytes.�rN)r=r>�read)rXr'rErrrreUszFileLoader.get_data)rHrGrIrJrYrrqr�r1rrerr)r
rro2sroc@s@eZdZdZdd�Zdd�Zdddd	�Zd
S)r5z>Concrete implementation of SourceLoader using the file system.cCs$t|�}i|jd6|jd6S)z!Return the metadata for the path.r�r�)r-�st_mtime�st_size)rXr'rlrrrra_szSourceFileLoader.path_statscCs"t|�}|j||d|�S)N�_mode)r�rb)rXr�r�rBr0rrrrddsz SourceFileLoader._cache_bytecoderwi�c	Cs5t|�\}}g}x6|rPt|�rPt|�\}}|j|�qWx�t|�D]v}t||�}ytj|�Wq^tk
r�w^Yq^tk
r�}zt	d||�dSWYdd}~Xq^Xq^Wy!t
|||�t	d|�Wn5tk
r0}zt	d||�WYdd}~XnXdS)zWrite bytes data to a file.zcould not create {!r}: {!r}Nzcreated {!r})r+r5r	r%rr�mkdir�FileExistsErrorr.r�rF)	rXr'rBrwrr�rrrfrrrrbis&
zSourceFileLoader.set_dataN)rHrGrIrJrardrbrrrrr5[sr5c@s.eZdZdZdd�Zdd�ZdS)r4z-Loader which handles sourceless file imports.cCsL|j|�}|j|�}t|d|d|�}t|d|d|�S)NrTr'r�)rrer�r�)rXr�r'rBrmrrrrA�szSourcelessFileLoader.get_codecCsdS)z'Return None as there is no source code.Nr)rXr�rrrrB�szSourcelessFileLoader.get_sourceN)rHrGrIrJrArBrrrrr4�sr4c@s�eZdZdZdd�Zdd�Zdd�Zedd	��Zd
d�Z	dd
�Z
dd�Zedd��ZdS)�ExtensionFileLoaderz]Loader for extension modules.

    The constructor is designed to work with FileFinder.

    cCs||_||_dS)N)rTr')rXrTr'rrrrY�s	zExtensionFileLoader.__init__cCs"|j|jko!|j|jkS)N)r
rN)rXr
rrrr�szExtensionFileLoader.__eq__cCst|j�t|j�AS)N)rprTr')rXrrrrq�szExtensionFileLoader.__hash__cCs�t|��ttj||j�}WdQXtd|j�|j|�}|r|t|d�r|t|j�dg|_	n||_
|j|_|s�|jj
d�d|_n|S)zLoad an extension module.Nz!extension module loaded from {!r}r#rer�)rVr�r|�load_dynamicr'r�rrKr+r#r�rHr'r$)rXr�r�rrrrr1�s
		zExtensionFileLoader.load_modulecs0t|j�d�t�fdd�tD��S)z1Return True if the extension module is a package.r c3s|]}�d|kVqdS)rYNr)r�suffix)�	file_namerrr^�sz1ExtensionFileLoader.is_package.<locals>.<genexpr>)r+r'r_�EXTENSION_SUFFIXES)rXr�r)r}rr�szExtensionFileLoader.is_packagecCsdS)z?Return None as an extension module cannot create a code object.Nr)rXr�rrrrA�szExtensionFileLoader.get_codecCsdS)z5Return None as extension modules have no source code.Nr)rXr�rrrrB�szExtensionFileLoader.get_sourcecCs|jS)z:Return the path to the source file as found by the finder.)r')rXr�rrrr�sz ExtensionFileLoader.get_filenameN)
rHrGrIrJrYrrqr�r1rrArBrrrrrrz�srzc@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�ZdS)�_NamespacePatha&Represents a namespace package's path.  It uses the module name
    to find its parent module, and from there it looks up the parent's
    __path__.  When this changes, the module's own path is recomputed,
    using path_finder.  For top-level modules, the parent module's path
    is sys.path.cCs4||_||_t|j��|_||_dS)N)rWr*r�_get_parent_path�_last_parent_path�_path_finder)rXrTr'�path_finderrrrrY�s		z_NamespacePath.__init__cCs5|jjd�\}}}|dkr+dS|dfS)z>Returns a tuple of (parent-module-name, parent-path-attr-name)r�r"r	r'r#)zsyszpath)rWr$)rXr�dotrprrr�_find_parent_path_names�sz&_NamespacePath._find_parent_path_namescCs&|j�\}}ttj||�S)N)r�rMr	rZ)rX�parent_module_name�path_attr_namerrrr��sz_NamespacePath._get_parent_pathcCst|j��}||jkrx|j|j|�}|dk	rl|jdkrl|jrl|j|_qln||_n|jS)N)rr�r�r�rWr�rr*)rX�parent_pathr�rrr�_recalculate�s	z_NamespacePath._recalculatecCst|j��S)N)�iterr�)rXrrr�__iter__�sz_NamespacePath.__iter__cCst|j��S)N)r#r�)rXrrr�__len__�sz_NamespacePath.__len__cCsdj|j�S)Nz_NamespacePath({!r}))r7r*)rXrrrrwsz_NamespacePath.__repr__cCs||j�kS)N)r�)rX�itemrrr�__contains__sz_NamespacePath.__contains__cCs|jj|�dS)N)r*r	)rXr�rrrr	sz_NamespacePath.appendN)
rHrGrIrJrYr�r�r�r�r�rwr�r	rrrrr�s

rc@sjeZdZdd�Zedd��Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dS)r(cCst|||�|_dS)N)rr*)rXrTr'r�rrrrYsz_NamespaceLoader.__init__cCsdj|j�S)zsReturn repr for the module.

        The method is deprecated.  The import machinery does the job itself.

        z<module {!r} (namespace)>)r7rH)r<r�rrrr�sz_NamespaceLoader.module_reprcCsdS)NTr)rXr�rrrrsz_NamespaceLoader.is_packagecCsdS)Nr"r)rXr�rrrrBsz_NamespaceLoader.get_sourcecCstddddd�S)Nr"z<string>r�rhT)ri)rXr�rrrrAsz_NamespaceLoader.get_codecCsdS)Nr)rXr�rrrr.!sz_NamespaceLoader.exec_modulecCstd|j�t||�S)zbLoad a namespace module.

        This method is deprecated.  Use exec_module() instead.

        z&namespace module loaded with path {!r})r�r*r�)rXr�rrrr1$sz_NamespaceLoader.load_moduleN)rHrGrIrYrDr�rrBrAr.r1rrrrr(s	r(c@s�eZdZdZedd��Zedd��Zedd��Zedd	��Zed
dd��Z	ed
d
d
d��Z
ed
dd��Zd
S)�
PathFinderz>Meta path finder for sys.path and package __path__ attributes.cCs:x3tjj�D]"}t|d�r|j�qqWdS)z}Call the invalidate_caches() method on all path entry finders
        stored in sys.path_importer_caches (where implemented).�invalidate_cachesN)r	�path_importer_cache�valuesrKr�)r<�finderrrrr�5szPathFinder.invalidate_cachescCs^tjstjdt�nx;tjD],}y||�SWq&tk
rQw&Yq&Xq&WdSdS)zqSearch sequence of hooks for a finder for 'path'.

        If 'hooks' is false then use sys.path_hooks.

        zsys.path_hooks is emptyN)r	�
path_hooksr�r�r�r�)r<r'�hookrrr�_path_hooks=s	
zPathFinder._path_hookscCsa|dkrtj�}nytj|}Wn.tk
r\|j|�}|tj|<YnX|S)z�Get the finder for the path entry from sys.path_importer_cache.

        If the path entry is not in the cache, find the appropriate finder
        and cache it. If no finder is available, store None.

        r")rr4r	r�r`r�)r<r'r�rrr�_path_importer_cacheNs
zPathFinder._path_importer_cachecCsqt|d�r'|j|�\}}n|j|�}g}|dk	rUt||�St|d�}||_|S)Nr�)rKr�r?r�rr)r<r�r�r�r�r�rrr�_legacy_get_spec_s
	zPathFinder._legacy_get_specNc	Cs�g}x�|D]�}t|ttf�s.q
n|j|�}|dk	r
t|d�rm|j||�}n|j||�}|dkr�q
n|jdk	r�|S|j}|dkr�t	d��n|j
|�q
q
Wt|d�}||_|SdS)z?Find the loader or namespace_path for this module/package name.Nr>zspec missing loader)r��str�bytesr�rKr>r�r�rr�r�r)	r<r�r'r=�namespace_path�entryr�r�r�rrr�	_get_specns(
		zPathFinder._get_speccCs�|dkrtj}n|j|||�}|dkr=dS|jdkr�|j}|r�d|_t|||j�|_|SdSn|SdS)zbfind the module on sys.path or 'path' based on sys.path_hooks and
        sys.path_importer_cache.N�	namespace)r	r'r�r�rrr)r<r�r'r=r�r�rrrr>�s		zPathFinder.find_speccCs)|j||�}|dkr"dS|jS)z�find the module on sys.path or 'path' based on sys.path_hooks and
        sys.path_importer_cache.

        This method is deprecated.  Use find_spec() instead.

        N)r>r�)r<r�r'r�rrrr?�szPathFinder.find_module)rHrGrIrJrDr�r�r�r�r�r>r?rrrrr�1sr�c@s�eZdZdZdd�Zdd�ZeZdd�Zdd	�Z	d
dd�Z
d
d�Zedd��Z
dd�Zd
S)�
FileFinderz�File-based finder.

    Interactions with the file system are cached for performance, being
    refreshed when the directory the finder is handling has been modified.

    cszg}x4|D],\�}|j�fdd�|D��q
W||_|pOd|_d|_t�|_t�|_dS)z�Initialize with the path to search on and a variable number of
        2-tuples containing the loader and the file suffixes the loader
        recognizes.c3s|]}|�fVqdS)Nr)rr|)r�rrr^�sz&FileFinder.__init__.<locals>.<genexpr>r�r Nr�)r��_loadersr'�_path_mtime�set�_path_cache�_relaxed_path_cache)rXr'�loader_details�loadersr�r)r�rrY�s$		zFileFinder.__init__cCs
d|_dS)zInvalidate the directory mtime.r Nr�)r�)rXrrrr��szFileFinder.invalidate_cachescCs;|j|�}|dkr%dgfS|j|jp7gfS)z�Try to find a loader for the specified module, or the namespace
        package portions. Returns (loader, list-of-portions).

        This method is deprecated.  Use find_spec() instead.

        N)r>r�r)rXr�r�rrrr��s
zFileFinder.find_loadercCs(|||�}t||d|d|�S)Nr�r)r)rXrr�r'rr=r�rrrr��szFileFinder._get_specNcCs�d}|jd�d}y"t|jp1tj��j}Wntk
rUd
}YnX||jkr{|j�||_nt	�r�|j
}|j�}n|j}|}||kr3t
|j|�}xg|jD]M\}	}
d|	}t
||�}t|�r�|j|
|||g|�Sq�Wt|�}nx~|jD]s\}	}
t
|j||	�}tdj|�dd�||	|kr=t|�r�|j|
||d|�Sq=q=W|r�td	j|��t|d�}
|g|
_|
SdS)z}Try to find a loader for the specified module, or the namespace
        package portions. Returns (loader, list-of-portions).Fr�r�r rYz	trying {}r�Nzpossible namespace for {}r�)r$r-r'rr4rur.r��_fill_cacherr�r�r�rr�r3r�r5r�r7rr)rXr�r=�is_namespace�tail_moduler��cache�cache_module�	base_pathr|r�
init_filename�	full_pathr�rrrr>�sD"

			
  zFileFinder.find_specc	
Cs|j}ytj|p!tj��}Wn!tttfk
rKg}YnXtjj	d�spt
|�|_not
�}xZ|D]R}|jd�\}}}|r�dj
||j��}n|}|j|�q�W||_tjj	t�r
dd�|D�|_ndS)zDFill the cache of potential modules and packages for this directory.rr�z{}.{}cSsh|]}|j��qSr)r�)r�fnrrr�	<setcomp>*s	z)FileFinder._fill_cache.<locals>.<setcomp>N)r'r�listdirr4�FileNotFoundError�PermissionError�NotADirectoryErrorr	r
rr�r�r�r7r��addrr�)	rXr'�contents�lower_suffix_contentsr�rTr�r|�new_namerrrr�
s"		
	zFileFinder._fill_cachecs��fdd�}|S)aA class method which returns a closure to use on sys.path_hook
        which will return an instance using the specified loaders and the path
        called on the closure.

        If the path called on the closure is not a directory, ImportError is
        raised.

        cs.t|�s!tdd|��n�|��S)z-Path hook for importlib.machinery.FileFinder.zonly directories are supportedr')r5r�)r')r<r�rr�path_hook_for_FileFinder6sz6FileFinder.path_hook.<locals>.path_hook_for_FileFinderr)r<r�r�r)r<r�r�	path_hook,s
zFileFinder.path_hookcCsdj|j�S)NzFileFinder({!r}))r7r')rXrrrrw>szFileFinder.__repr__)rHrGrIrJrYr�r�r?r�r�r>r�rDr�rwrrrrr��s-r�c@s.eZdZdZdd�Zdd�ZdS)�_ImportLockContextz$Context manager for the import lock.cCstj�dS)zAcquire the import lock.N)r|r0)rXrrrr\Hsz_ImportLockContext.__enter__cCstj�dS)z<Release the import lock regardless of any raised exceptions.N)r|r})rX�exc_type�	exc_value�
exc_tracebackrrrrbLsz_ImportLockContext.__exit__N)rHrGrIrJr\rbrrrrr�Dsr�cCs[|jd|d�}t|�|kr7td��n|d}|rWdj||�S|S)z2Resolve a relative module name to an absolute one.r�r z2attempted relative import beyond top-level packagerez{}.{})r&r#r�r7)rT�package�level�bitsr�rrr�
_resolve_nameQs

r�cCs/|j||�}|dkr"dSt||�S)N)r?r�)r�rTr'r�rrr�_find_spec_legacyZsr�c	Cs"tjstjdt�n|tjk}x�tjD]�}t��]y
|j}Wn6tk
r�t	|||�}|dkr�w5nYnX||||�}WdQX|dk	r5|r|tjkrtj|}y
|j
}Wntk
r�|SYqX|dkr|S|Sq|Sq5q5WdSdS)zFind a module's loader.zsys.meta_path is emptyN)r	�	meta_pathr�r�r�rZr�r>r�r�r�)	rTr'r=�	is_reloadr�r>r�r�r�rrr�
_find_speccs0	





	r�cCs�t|t�s-tdjt|����n|dkrHtd��n|r�t|t�sltd��q�|tjkr�d}t|j|���q�n|r�|dkr�td��ndS)zVerify arguments are "sane".zmodule name must be str, not {}rezlevel must be >= 0z__package__ not set to a stringz=Parent module {!r} not loaded, cannot perform relative importzEmpty module nameN)	r�r��	TypeErrorr7rSr�r	rZ�SystemError)rTr�r�r�rrr�
_sanity_check�sr�zNo module named z{!r}cCs4d}|jd�d}|r�|tjkr>t||�n|tjkrXtj|Stj|}y
|j}Wq�tk
r�tdj||�}t|d|��Yq�Xnt	||�}|dkr�ttj|�d|��nt
|�j�}|r0tj|}t||jd�d|�n|S)Nr�rez; {!r} is not a packagerTr�)
r$r	rZr�r#r��_ERR_MSGr7r�r�r�r3rL)rT�import_r'r�
parent_moduler�r�r�rrr�_find_and_load_unlocked�s*



 r�c
Cs$t|��t||�SWdQXdS)z6Find and load the module, and release the import lock.N)ryr�)rTr�rrr�_find_and_load�s
r�cCs�t|||�|dkr1t|||�}ntj�|tjkrWt|t�Stj|}|dkr�tj�dj	|�}t
|d|��nt|�|S)a2Import 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.

    reNz(import of {} halted; None in sys.modulesrT)r�r�r|r0r	rZr��_gcd_importr}r7r�r�)rTr�r�r�r�rrrr��s	



	
r�cCst|d�r�d|krYt|�}|jd�t|d�rY|j|j�qYnx�|D]�}t||�s`dj|j|�}yt||�Wq�tk
r�}z5t	|�j
t�r�|j|kr�w`q�n�WYdd}~Xq�Xq`q`Wn|S)z�Figure 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.

    r#�*�__all__z{}.{}N)
rKr"�remover�r�r7rHr�r�r�r�_ERR_MSG_PREFIXrT)r��fromlistr�r�	from_namerfrrr�_handle_fromlist�s"


	 r�cCsN|jd�}|dkrJ|d}d|krJ|jd�d}qJn|S)z�Calculate 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'NrHr#r�re)ror$)�globalsr�rrr�_calc___package__�s
r�cCs7ttj�f}ttf}ttf}|||gS)z_Returns a list of file-based module loaders.

    Each item is a tuple (loader, suffixes).
    )rzr|�extension_suffixesr5r�r4r)�
extensions�source�bytecoderrrr	src	Cs�|dkrt|�}n6|dk	r-|ni}t|�}t|||�}|s�|dkrzt|jd�d�S|s�|St|�t|jd�d�}tj|jdt|j�|�Snt||t�SdS)a�Import a module.

    The 'globals' argument is used to infer where the import is occuring 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).

    reNr�)r�r�r�r#r	rZrHr�)	rTr��localsr�r�r��globals_r��cut_offrrr�
__import__	s#(r�cCsDtj|�}|dkr.td|��nt|�}|j�S)Nzno built-in module named )r:r>r�r�r3)rTr�r�rrr�_builtin_from_name5	s
r�cCs�|a|atjjr!tantatt�}x�tjj	�D]y\}}t
||�rC|tjkrvt}ntj
|�rCt}nqCt||�}t|�}|j|�qCqCWtjt}xIdD]A}	|	tjkr�t|	�}
n
tj|	}
t||	|
�q�Wddgfdddgff}x�|D]~\}}
td	d
�|
D��slt�|
d}|tjkr�tj|}PqAyt|�}PWqAtk
r�wAYqAXqAWtd��t|d
|�t|d|�t|ddj|
��ytd�}Wntk
r2d}YnXt|d|�td�}t|d|�|dkr�td�}t|d|�nt|dt��tjtj��|dkr�tjd�dtkr�dt_ q�ndS)z�Setup 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.

    r=r��builtinsr��posix�/�nt�\css!|]}t|�dkVqdS)r N)r#)rr�rrrr^i	sz_setup.<locals>.<genexpr>rezimportlib requires posix or ntrrrr"rfNr��winregrKrz.pywz_d.pydT)z_ioz	_warningszbuiltinszmarshal)!r|r	r�r�r�rr�rSrZ�itemsr�r�r:r�rEr$r�r+rHr�rL�allrvr�rr
r~r�r�r�r	rJrR)�
sys_module�_imp_module�module_typerTr�r�r�r��self_module�builtin_name�builtin_module�
os_details�
builtin_osrr�	os_module�
thread_module�weakref_module�
winreg_modulerrr�_setup=	sl				


!




r�cCs�t||�t�}tjjtj|�g�tjjt	�tjjt
�tjdkrttjjt
�ntjjt�dS)z2Install importlib as the implementation of import.r�N)r�rr	r�r�r�r�r�r	r:rErrHrJr�)r�r��supported_loadersrrr�_install�	s
	r�)zwinzcygwinzdarwin)\rJrr
rrrr+r-r2r3r5rFrRrUrS�__code__r�rVrrnrurcrdrxryr{r�r�rr�rr�_RAW_MAGIC_NUMBERr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rr��objectrrr$r�r9r:rErJr[r^ror5r4r~rzrr(r�r�r�r�r�r�r�r�r�r�r�r�r�r�rr�r�r�r�rrrr�<module>s�
	Dr			7
$j	?-�FG?n)+99&��
		(
 #W