Your IP : 216.73.216.213


Current Path : /opt/alt/python35/lib64/python3.5/test/test_importlib/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/test/test_importlib/__pycache__/util.cpython-35.opt-1.pyc



��Yf�0�@s�ddlZddlZddlZddlZddlZddlmZmZmZddlZddl	Zddl
mZddlZddl
Z
ddlZddlZej�Zde_de_de
jkr�de_de
jkr�de_ej�adt_dt_dt_dt_dt_dd�Ze�d	d
�Zddd�Zdd
d�Zddd�ZdZ e
j!d3kr�e"j#�Z$e$e"kr�e"j%�Z$ejj&e$�s�dZ ed�dZ'de(ej)�de(e'j)�iZ)dd�Z*ddd�Z+ej,dd��Z-ej,ddddd ��Z.ej,d!d"��Z/Gd#d$�d$�Z0Gd%d&�d&e0�Z1Gd'd(�d(e0�Z2d)d*�Z3d+d,�Z4ej,d-d.��Z5d/d0�Z6Gd1d2�d2�Z7dS)4�N)�	machinery�util�invalidate_caches)�support�errno�	importlibZ	_testcapicCs�x�tjD]v}xmtjD]b}tj|}tjj||�}tjj|�r|t_|t_	|t_
|t_dSqWq
WdS)N)�sys�pathr�EXTENSION_SUFFIXES�
EXTENSIONS�name�os�join�exists�ext�filename�	file_path)r	rrr�r�=/opt/alt/python35/lib64/python3.5/test/test_importlib/util.py�_extension_detailss
				rcCsRd|krd	nf}tj|�}tj|d|dd
�}d|d|iS)zAImport a module from importlib both w/ and w/o _frozen_importlib.�.r�freshZblocked�_frozen_importlib�_frozen_importlib_external�Frozen�Source)r)rr)rZimport_fresh_module)Zmodule_namer�frozen�sourcerrr�import_importlib/s
	rc
Ks�|dkrtj}nt|t�s1||}dj||j�}||f}tj||�}|j|_|j|_	||_
x4|j�D]&\}}||}	t|||	�q�W|S)Nz{}_{})
�unittestZTestCase�
isinstance�type�format�__name__�types�	new_class�
__module__Z_NAMEZ_KIND�items�setattr)
�clsZkind�base�kwargsr�basesZspecialized�attr�values�valuerrr�specialize_class8s
	
r0cKs4t|d||�}t|d||�}||fS)Nrr)r0)r)r*r+rrrrr�split_frozenKsr1cKst|||�S)N)r1)Z
test_classr*r+rrr�	test_bothQsr2T�win32�cygwinFrrcCstjtd�|�S)zRClass decorator that nullifies tests requiring a case-insensitive
    file system.z&requires a case-insensitive filesystem)rZskipIf�CASE_INSENSITIVE_FS)�testrrr�case_insensitive_testsds
r7�c
CsUtjj||d�}t|d��}|j|�WdQRXdj||�|fS)Nz.py�wz{}.{})r
r	r�open�writer")�parentrZpkg_dir�contentr	Zsubfilerrr�	submoduleksr>cgs�xR|D]J}|dkr.tdj|���ytj|=Wqtk
rPYqXqWz	dVWdx1|D])}ytj|=Wqhtk
r�YqhXqhWXdS)z�Uncache a module from sys.modules.

    A basic sanity check is performed to prevent uncaching modules that either
    cannot/shouldn't be uncached.

    r�marshal�impzcannot uncache {0}N)rr?r@)�
ValueErrorr"r�modules�KeyError)�namesrrrr�uncachers

		

rE�pkgc#s�fdd�tjD�}tjd���}t�|���tj|���t�tjj	|��}|r�tjj	|d�}tj
��n|d}|dkr�d}|dk	r�t|d��}|j|�WdQRX|VWdQRXWdQRXWdQRXdS)Ncs/g|]%}|jd�d�kr|�qS)rr)�	partition)�.0�n)rrr�
<listcomp>�s	ztemp_module.<locals>.<listcomp>z__init__.pyz.pyr8r9)
rrBrZtemp_cwdrEZ
DirsOnSysPathrr
r	r�mkdirr:r;)rr=rFZ	conflicts�cwd�locationZmodpathZmodfiler)rr�temp_module�s 
rNcks�i}z�x�dgfdgfdgfdiffD]U\}}tt|�||<||krs||}||=n|}tt||�q4Wt|�r�tdj|j����dVWdx*|j�D]\}}tt||�q�WXdS)a,Context manager to manage the various importers and stored state in the
    sys module.

    The 'modules' attribute is not supported as the interpreter state stores a
    pointer to the dict that the interpreter uses internally;
    reassigning to sys.modules does not have the desired effect.

    �	meta_pathr	�
path_hooks�path_importer_cachezunrecognized arguments: {0}N)�getattrrr(�lenrAr"�keysr')r+Z	originalsr-�defaultZ	new_valuer/rrr�import_state�s"
	

	rVc@sLeZdZdZdidd�Zdd�Zdd�Zd	d
�ZdS)�
_ImporterMockz0Base class to help with creating importer mocks.�module_codecGsi|_i|_x�|D]�}|jd�s7|}n|dtd��}d|krcd}n+||kr�|jdd�d}n|}tj|�}||_d|_||_	||_
||kr�dg|_||j|<||kr|||j|<qWdS)Nz	.__init__r�rz<mock __file__>z<mock __path__>)rBrX�endswithrS�rsplitr$�
ModuleType�
__loader__�__file__�__package__r-�__path__)�selfrXrDr�import_name�package�modulerrr�__init__�s*		
						
z_ImporterMock.__init__cCs|j|S)N)rB)rarrrr�__getitem__�sz_ImporterMock.__getitem__cCs)t|jj��|_|jj�|S)N)rErBrT�_uncache�	__enter__)rarrrrh�s
z_ImporterMock.__enter__cGs|jjddd�dS)N)rg�__exit__)ra�exc_inforrrri�sz_ImporterMock.__exit__N)r#r&�__qualname__�__doc__rerfrhrirrrrrW�s
rWc@s1eZdZdZddd�Zdd�ZdS)�mock_modulesz!Importer mock using PEP 302 APIs.NcCs||jkrdS|SdS)N)rB)ra�fullnamer	rrr�find_module�szmock_modules.find_modulecCs~||jkrt�nb|j|tj|<||jkroy|j|�Wntk
rntj|=�YnX|j|SdS)N)rB�ImportErrorrrX�	Exception)rarnrrr�load_module�s	

zmock_modules.load_module)r#r&rkrlrorrrrrrrm�srmc@s@eZdZdZdddd�Zdd�Zdd�ZdS)	�	mock_specz!Importer mock using PEP 451 APIs.NcCs[y|j|}Wntk
r)dSYnXtj||jd|dt|dd��}|S)N�loader�submodule_search_locationsr`)rBrCr�spec_from_file_locationr^rR)rarnr	r<rd�specrrr�	find_specs
	zmock_spec.find_speccCs&|j|jkrt�|j|jS)N)rrBrp)rarwrrr�
create_moduleszmock_spec.create_modulecCs1y|j|jj�Wntk
r,YnXdS)N)rX�__spec__rrC)rardrrr�exec_modules
zmock_spec.exec_module)r#r&rkrlrxryr{rrrrrss
rscs8tjrdd�Stj���fdd��}|S)ztDecorator to protect sys.dont_write_bytecode from mutation and to skip
    tests that require it to be set to False.c_sdS)Nr)�argsr+rrr�<lambda>"sz'writes_bytecode_files.<locals>.<lambda>cs6tj}dt_z�||�}Wd|t_X|S)NF)r�dont_write_bytecode)r|r+ZoriginalZ	to_return)�fxnrr�wrapper#s		
z&writes_bytecode_files.<locals>.wrapper)rr~�	functools�wraps)rr�r)rr�writes_bytecode_filess	
!	r�cCs^ytjtjj|��Wn:tk
rY}z|jtjkrG�WYdd}~XnXdS)z�Ensure that the __pycache__ directory for PEP 3147 pyc file exists.

    :param bytecode_path: File system path to PEP 3147 pyc file.
    N)r
rKr	�dirname�OSErrorrZEEXIST)�
bytecode_path�errorrrr�ensure_bytecode_path/s
r�cgsd}g}i}d}d}z�tj�}||d<t�}x7|D]/}|jd�se|}	n|dtd��}	|j|	�|	tjkr�tj|	=|jd�}
|}xY|
dd�D]G}t	j
j||�}t	j
j|�s�t	j
|�|j|�q�Wt	j
j||
dd�}t|d	��}
|
j|j|��WdQRX|j|�|||<qGWt|�}|j�td
|g�}|j�|VWd|dk	r�|jddd�|dk	r�|jddd�tj|�XdS)
aRTemporarily create each named module with an attribute (named 'attr')
    that contains the name passed into the context manager that caused the
    creation of the module.

    All files are created in a temporary directory returned by
    tempfile.mkdtemp(). This directory is inserted at the beginning of
    sys.path. When the context manager exits all created files (source and
    bytecode) are explicitly deleted.

    No magic is performed when creating packages! This means that if you create
    a module within a package you must also create the package's __init__ as
    well.

    zattr = {0!r}Nz.rootrez	.__init__rrYz.pyr9r	���r�)�tempfileZmkdtemp�setrZrS�addrrB�splitr
r	rrrK�appendr:r;r"rErhrVrirZrmtree)rDrZ
created_paths�mappingZ
state_managerZuncache_managerZtemp_dirZimport_namesrrbZ
name_partsrZ	directory�filerrr�create_modules;sL
	
	





	r�cs��fdd�}|S)zA mock sys.path_hooks entry.cs|�krt��S)N)rp)�entry)�entries�importerrr�hookwszmock_path_hook.<locals>.hookr)r�r�r�r)r�r�r�mock_path_hookusr�c@seZdZdd�ZdS)�CASEOKTestBasecs<d}t�fdd�|D��|kr8�jd�dS)N�PYTHONCASEOK�PYTHONCASEOKc3s'|]}|�jjjjkVqdS)N)r�_bootstrap_external�_os�environ)rH�x)rarr�	<genexpr>�sz4CASEOKTestBase.caseok_env_changed.<locals>.<genexpr>z/os.environ changes not reflected in _os.environ)r�r�)�anyZskipTest)raZshould_existZ
possibilitiesr)rar�caseok_env_changed�sz!CASEOKTestBase.caseok_env_changedN)r#r&rkr�rrrrr�~sr�)r3r4)8�builtins�
contextlibrr�rrrrr
Zos.pathr6rrrr�r$�SimpleNamespaceZBUILTINSZ	good_nameZbad_name�builtin_module_namesrr	rrrrrrr0r1r2r5�platformr^�upperZchanged_name�lowerrZsource_importlib�staticmethod�
__import__r7r>�contextmanagerrErNrVrWrmrsr�r�r�r�r�rrrr�<module>sn									
	):