Your IP : 216.73.216.60


Current Path : /opt/alt/python35/lib64/python3.5/site-packages/cffi/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/site-packages/cffi/__pycache__/verifier.cpython-35.pyc



.�W�,�@sRddlZddlZddlZddlZddlZddlmZddlmZejdkr�ddl	Z
dd�ZnddlZdd�Zejdkr�ej
ZnGd	d
�d
ej�Zdd�ZGd
d�de�ZdZdd�Zdadd�Zdd�Zdddd�Zdd�Zdd�ZdS)�N�)�__version_verifier_modules__)�ffiplatform�cCstjjdd�S)N)�	importlib�	machinery�EXTENSION_SUFFIXES�r	r	�@/opt/alt/python35/lib64/python3.5/site-packages/cffi/verifier.py�_extension_suffixes
srcCsdd�tj�D�S)NcSs.g|]$\}}}|tjkr|�qSr	)�imp�C_EXTENSION)�.0�suffix�_�typer	r	r
�
<listcomp>s	z'_extension_suffixes.<locals>.<listcomp>)r�get_suffixesr	r	r	r
rscs"eZdZ�fdd�Z�S)�NativeIOcs8t|t�r|jd�}tt|�j|�dS)N�ascii)�
isinstance�unicode�encode�superr�write)�self�s)�	__class__r	r
rszNativeIO.write)�__name__�
__module__�__qualname__rr	r	)rr
rsrcCs8tjdkr4yddl}Wntk
r3YnXdS)N�win32r)�sys�platform�
setuptools�ImportError)r$r	r	r
�_hack_at_distutilss

r&c
@s�eZdZdddddddddd�Zddd�Zd	d
�Zdd�Zd
d�Zdd�Zdd�Z	dd�Z
dd�Zdd�Zddd�Z
dd�Zdd�ZdS)�VerifierN�Fz.ccKs|jjr(tjd|jjf��||_||_|sOtj|�}t||�}
|
|�|_|jj	|�|	|_
|j||
�|_|r�|r�t
d��n�djtjdd�t||g|j�}tjdkr|jd�}ttj|ddd��d@�}|jd	�jd
�}ttj|ddd��d@�}|jd�jd
�}d
||jj||f}t�d}|p�t�|_tjj|j||�|_ tjj|j||�|_!||_"d|_#d|_$dS)NzKfeature not supported with ffi.verify(), but only with ffi.set_source(): %sz)can't specify both 'modulename' and 'tag'�rzutf-8r�l���0x�Lr�0z_cffi_%s_%s%s%sF)r)%�_parserZ_uses_new_featurer�VerificationError�ffi�preamble�flatten�_locate_engine_class�_vengineZpatch_extension_kwds�flags�make_relative_to�kwds�	TypeError�joinr"�versionrZ_cdefsources�version_infor�hex�binascii�crc32�lstrip�rstripZ
_class_key�_get_so_suffixes�_caller_dir_pycache�tmpdir�os�path�sourcefilename�modulefilename�ext_package�_has_source�_has_module)rr0r1rCZ
modulenamerH�tag�force_generic_engineZsource_extensionr5�relative_tor7Zflattened_kwdsZ
vengine_class�keyZk1Zk2rr	r	r
�__init__)sD				
&&

		zVerifier.__init__c	CsI|jj�6|jr1|dkr1tjd��|j|�WdQRXdS)zkWrite the C source code.  It is produced in 'self.sourcefilename',
        which can be tweaked beforehand.Nzsource code already written)r0�_lockrIrr/�
_write_source)r�filer	r	r
�write_sourceQs

	zVerifier.write_sourcec	CsM|jj�:|jr%tjd��|js8|j�|j�WdQRXdS)z�Write the C source code (if not done already) and compile it.
        This produces a dynamic link library in 'self.modulefilename'.zmodule already compiledN)r0rPrJrr/rIrQ�_compile_module)rr	r	r
�compile_moduleZs
		
zVerifier.compile_modulec	Cs[|jj�H|jsF|j�|jsF|js<|j�|j�|j�SWdQRXdS)a"Get a C module from this Verifier instance.
        Returns an instance of a FFILibrary class that behaves like the
        objects returned by ffi.dlopen(), but that delegates all
        operations to the C module.  If necessary, the C code is written
        and compiled first.
        N)r0rPrJ�_locate_modulerIrQrT�
_load_library)rr	r	r
�load_libraryds
	
		

zVerifier.load_librarycCs]tjj|j�}|jdd�d}|jd�rYttd�rY|dd�}|S)N�.rrZ_d�gettotalrefcountr*���)rDrE�basenamerG�split�endswith�hasattrr")rr\r	r	r
�get_module_namets
zVerifier.get_module_namecCskt�|js7|jj�|js0|j�WdQRXtj|j�}|j�}tj	|||j
�S)N)r&rIr0rPrQrZmaybe_relative_pathrFr`�
get_extensionr7)rZ
sourcename�modnamer	r	r
ras	
	zVerifier.get_extensioncCs
|jjS)N)r4Z_gen_python_module)rr	r	r
�generates_python_module�sz Verifier.generates_python_modulecs�|r�tjj|�r�tjj|��|j�}xrtjD]g}||kr@||}t|ttf�s�t	d|f���fdd�|D�}|||<q@W|S)Nz&keyword '%s' should be a list or tuplecs%g|]}tjj�|��qSr	)rDrEr9)r�fn)�dirnamer	r
r�s	z-Verifier.make_relative_to.<locals>.<listcomp>)
rDrEre�copyrZLIST_OF_FILE_NAMESr�list�tupler8)rr7rMrN�lstr	)rer
r6�s

zVerifier.make_relative_tocCs�tjj|j�s�|jrbyt|jdddg�}Wntk
rUdSYnX|j}nd}|jj	|j
�|t��}|dkr�dS||_|jj�d|_
dS)N�__doc__T)rDrE�isfilerGrH�
__import__r%�__path__r4�find_moduler`rAZ
collect_typesrJ)r�pkgrE�filenamer	r	r
rV�s	
		
zVerifier._locate_modulec
Cs.||j_z|jj�Wd|j`XdS)N)r4Z_fZwrite_source_to_f)rrRr	r	r
�_write_source_to�szVerifier._write_source_tocCs�|dk	r|j|�n�t�}|j|�|j�}tjj|j�r�t|jd��}|j�|k}WdQRXnd}|r�t	|j�t|jd��}|j
|�WdQRXd|_dS)N�rT�w)rqr�getvaluerDrE�existsrF�open�read�_ensure_dirrrI)rrR�fZsource_data�fpZ
needs_writtenr	r	r
rQ�s	

zVerifier._write_sourcecCs�tjj|j�}tj||j��}ytj||j�}Wnt	k
r`d}YnX|s�t
|j�tj||j�d|_
dS)NFT)rDrErerFr�compilera�samefilerG�OSErrorrx�shutil�moverJ)rrCZoutputfilenameZsamer	r	r
rT�s

zVerifier._compile_modulecCsB|jst�|jdk	r1|jj|j�S|jj�SdS)N)rJ�AssertionErrorr5r4rX)rr	r	r
rW�szVerifier._load_library)rrr rOrSrUrXr`rarcr6rVrqrQrTrWr	r	r	r
r''s	&	


r'FcCs�trd}|sjdtjkr*d}n@yddl}Wntk
rTd}YnX|j|k	rjd}|r�ddlm}|jSddlm	}|j
SdS)NTZ__pypy__r�?r)�vengine_gen)�vengine_cpy)�_FORCE_GENERIC_ENGINEr"�builtin_module_names�
_cffi_backendr%Z_backendr(r�ZVGenericEnginer�ZVCPythonEngine)r0rLr�r�r�r	r	r
r3�s 	
r3cCsftr
tStjjd�}|r&|Stjd�jj}tjj	tjj
tjj|�d��S)NZCFFI_TMPDIRr*�__pycache__)�_TMPDIRrD�environ�getr"�	_getframe�f_code�co_filenamerE�abspathr9re)�resultrpr	r	r
rB�s!rBcCs
|adS)z:Set the temporary directory to use instead of __pycache__.N)r�)rer	r	r
�
set_tmpdir	sr�cCs�|pt�}ytj|�}Wntk
r:dSYnX|rJd}nt�dj�}x�|D]z}|j�jd�rd|j�j|�s�|j�jd�rdy tjtj	j
||��Wqdtk
r�YqdXqdWtj	j
|d�g}x�|D]}}ybx[tj|�D]J}tj	j
||�}tj	j|�rW|j|�qtj|�qWWqtk
r}YqXqWdS)z}Clean up the temporary directory by removing all files in it
    called `_cffi_*.{c,so}` as well as the `build` subdirectory.Nz.crZ_cffi_�build)
rBrD�listdirr}rA�lower�
startswithr^�unlinkrEr9�isdir�append)rCZkeep_so�filelistrrdZ	clean_dir�dirr	r	r
�cleanup_tmpdirs2
		
* 
	

r�cCs7t�}|s3tjdkr*dg}n	dg}|S)Nr!z.pydz.so)rr"r#)�suffixesr	r	r
rA-s		rAcCs6ytjtjj|��Wntk
r1YnXdS)N)rD�makedirsrErer})rpr	r	r
rx8s
rx)rr)r)r"rDr=r~�ior(rrr;�importlib.machineryrrr�StringIOr�BytesIOr&�objectr'r�r3r�rBr�r�rArxr	r	r	r
�<module>s(<�