Your IP : 216.73.216.213


Current Path : /opt/alt/python34/lib64/python3.4/test/test_importlib/__pycache__/
Upload File :
Current File : //opt/alt/python34/lib64/python3.4/test/test_importlib/__pycache__/util.cpython-34.pyc

�
g f��@suddlmZddlmZmZddlZddlmZddl	Z	ddl
Z
ddlZdd�Zdd�Z
d	Ze
jdkr�ej�Zeekr�ej�Znejje�s�dZq�nd
d�Zddd�Zedd��Zeddddd��Zedd��ZGdd�d�ZGdd�de�ZGdd�de�ZdS) �)�contextmanager)�util�invalidate_cachesN)�supportcCsLd|krdnf}tj|�}tj|d|dd�}||fS)zAImport a module from importlib both w/ and w/o _frozen_importlib.�.�	importlib�freshZblocked�_frozen_importlib)z	importlib)z_frozen_importlib)rZimport_fresh_module)Zmodule_namer�frozen�source�r�=/opt/alt/python34/lib64/python3.4/test/test_importlib/util.py�import_importlib
s
	rcKs�tjd|j|tjf�}tjd|j|tjf�}|j|_|_x@|j�D]2\}\}}t|||�t|||�qdW||fS)NZFrozen_ZSource_)�types�	new_class�__name__�unittestZTestCase�
__module__�items�setattr)Z
test_class�kwargsZfrozen_testsZsource_tests�attrZfrozen_valueZsource_valuerrr
�	test_bothsrT�win32�cygwinFcCstjtd�|�S)zRClass decorator that nullifies tests requiring a case-insensitive
    file system.z&requires a case-insensitive filesystem)rZskipIf�CASE_INSENSITIVE_FS)�testrrr
�case_insensitive_tests*s
r�c	CsTtjj||d�}t|d��}|j|�WdQXdj||�|fS)Nz.py�wz{}.{})�os�path�join�open�write�format)�parent�nameZpkg_dir�contentr!Zsubfilerrr
�	submodule1sr)cgs�xU|D]M}|dkr1tdj|���nytj|=Wqtk
rSYqXqWz	dVWdx1|D])}ytj|=Wqktk
r�YqkXqkWXdS)z�Uncache a module from sys.modules.

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

    �sys�marshal�impzcannot uncache {0}N)zsyszmarshalr,)�
ValueErrorr%r*�modules�KeyError)�namesr'rrr
�uncache8s

		

r1�pkgc#s�fdd�tjD�}tjd���}t�|���tj|���t�tjj	|��}|r�tjj	|d�}tj
��n|d}|dkr�d}n|dk	r�t|d��}|j|�WdQXn|VWdQXWdQXWdQXdS)Ncs/g|]%}|jd�d�kr|�qS)rr)�	partition)�.0�n)r'rr
�
<listcomp>Ts	ztemp_module.<locals>.<listcomp>z__init__.pyz.pyrr)
r*r.rZtemp_cwdr1Z
DirsOnSysPathrr r!r"�mkdirr#r$)r'r(r2Z	conflicts�cwd�locationZmodpathZmodfiler)r'r
�temp_moduleRs 
	r:cks�i}z�x�dgfdgfdgfdiffD]U\}}tt|�||<||krs||}||=n|}tt||�q4Wt|�r�tdj|j����ndVWdx*|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)�getattrr*r�lenr-r%�keysr)rZ	originalsr�defaultZ	new_value�valuerrr
�import_statejs"
	

	rCc@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|_n||j|<||kr|||j|<qqWdS)Nz	.__init__r�rz<mock __file__>z<mock __path__>)r.rE�endswithr?�rsplitr�
ModuleType�
__loader__�__file__�__package__r�__path__)�selfrEr0r'Zimport_name�package�modulerrr
�__init__�s*		
						
z_ImporterMock.__init__cCs|j|S)N)r.)rNr'rrr
�__getitem__�sz_ImporterMock.__getitem__cCs)t|jj��|_|jj�|S)N)r1r.r@�_uncache�	__enter__)rNrrr
rT�s
z_ImporterMock.__enter__cGs|jjddd�dS)N)rS�__exit__)rN�exc_inforrr
rU�sz_ImporterMock.__exit__N)rr�__qualname__�__doc__rQrRrTrUrrrr
rD�s
rDc@s1eZdZdZddd�Zdd�ZdS)�mock_modulesz!Importer mock using PEP 302 APIs.NcCs||jkrdS|SdS)N)r.)rN�fullnamer!rrr
�find_module�szmock_modules.find_modulecCs�||jkrt�ne|j|tj|<||jkrry|j|�Wqrtk
rntj|=�YqrXn|j|SdS)N)r.�ImportErrorr*rE�	Exception)rNrZrrr
�load_module�s	

zmock_modules.load_module)rrrWrXr[r^rrrr
rY�srYc@s@eZdZdZdddd�Zdd�Zdd�ZdS)	�	mock_specz!Importer mock using PEP 451 APIs.NcCsjy|j|}Wntk
r)dSYnXt|d�}tj||jd|dt|dd��}|S)NrM�loader�submodule_search_locations)r.r/�hasattrr�spec_from_file_locationrKr>)rNrZr!r&rP�
is_package�specrrr
�	find_spec�s
	zmock_spec.find_speccCs)|j|jkrt�n|j|jS)N)r'r.r\)rNrerrr
�
create_module�s	zmock_spec.create_modulecCs1y|j|jj�Wntk
r,YnXdS)N)rE�__spec__r'r/)rNrPrrr
�exec_module�s
zmock_spec.exec_module)rrrWrXrfrgrirrrr
r_�sr_)zwin32zcygwin)�
contextlibrrrrZos.pathr rrrr*rrrr�platformrK�upperZchanged_name�lowerr!�existsrr)r1r:rCrDrYr_rrrr
�<module>s0	)