Current File : //proc/self/root/kunden/usr/lib64/python3.9/site-packages/cffi/__pycache__/verifier.cpython-39.pyc
a

(�`�+�@s�ddlZddlZddlZddlZddlZddlmZddlmZddlm	Z	ej
dkrhddlZdd�Z
nddlZd	d�Z
ej
d
kr�ejZnGdd�dej�ZGd
d�de�ZdZdd�Zdadd�Zdd�Zddd�Zdd�Zdd�ZdS)�N�)�__version_verifier_modules__)�ffiplatform)�VerificationError)�rcCstjjdd�S�N)�	importlib�	machinery�EXTENSION_SUFFIXES�rr�3/usr/lib64/python3.9/site-packages/cffi/verifier.py�_extension_suffixessr
cCsdd�t��D�S)NcSs g|]\}}}|tjkr|�qSr)�imp�C_EXTENSION)�.0�suffix�_�typerrr�
<listcomp>s
�z'_extension_suffixes.<locals>.<listcomp>)rZget_suffixesrrrrr
s�rcseZdZ�fdd�Z�ZS)�NativeIOcs(t|t�r|�d�}tt|��|�dS)N�ascii)�
isinstanceZunicode�encode�superr�write)�self�s��	__class__rrrs

zNativeIO.write)�__name__�
__module__�__qualname__r�
__classcell__rrrrrsrc@szeZdZddd�Zd dd�Zd	d
�Zdd�Zd
d�Zdd�Zdd�Z	dd�Z
dd�Zdd�Zd!dd�Z
dd�Zdd�ZdS)"�VerifierN�F�.ccKsv|jjrtd|jjf��||_||_|s4t�|�}t||�}
|
|�|_|j�	|�|	|_
|�||
�|_|rz|rxt
d��n�d�tjdd�t||g|j�}tjdkr�|�d�}tt�|ddd��d	@�}|�d
��d�}tt�|ddd��d	@�}|�d
��d�}d||jj||f}t�d}|�p0t�|_tj�|j||�|_ tj�|j||�|_!||_"d|_#d|_$dS)NzKfeature not supported with ffi.verify(), but only with ffi.set_source(): %sz)can't specify both 'modulename' and 'tag'�rrzutf-8r�l���0x�Lr�0z_cffi_%s_%s%s%sF)%Z_parserZ_uses_new_featurer�ffi�preamblerZflatten�_locate_engine_class�_vengineZpatch_extension_kwds�flags�make_relative_to�kwds�	TypeError�join�sys�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)rr,r-r?Z
modulenamerD�tag�force_generic_engineZsource_extensionr0�relative_tor2Zflattened_kwdsZ
vengine_class�keyZk1Zk2rrrr�__init__ sN��



��


�
zVerifier.__init__cCsL|jj�0|jr |dur td��|�|�Wd�n1s>0YdS)zkWrite the C source code.  It is produced in 'self.sourcefilename',
        which can be tweaked beforehand.Nzsource code already written)r,�_lockrEr�
_write_source�r�filerrr�write_sourceHs
�zVerifier.write_sourcecCsP|jj�4|jrtd��|js&|��|��Wd�n1sB0YdS)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)r,rLrFrrErM�_compile_module�rrrr�compile_moduleQs
zVerifier.compile_modulecCs^|jj�B|js4|��|js4|js,|��|��|��Wd�S1sP0YdS)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)r,rLrF�_locate_modulerErMrQ�
_load_libraryrRrrr�load_library[s
zVerifier.load_librarycCsBtj�|j�}|�dd�d}|�d�r>ttd�r>|dd�}|S)N�.rrZ_dZgettotalrefcount���)r@rA�basenamerC�split�endswith�hasattrr5)rrYrrr�get_module_nameks
zVerifier.get_module_namecCsnt��|jsD|jj�|js&|��Wd�n1s:0Yt�|j�}|��}tj	||fi|j
��Sr)rZ_hack_at_distutilsrEr,rLrMZmaybe_relative_pathrBr]�
get_extensionr2)rZ
sourcename�modnamerrrr^vs
&zVerifier.get_extensioncCs|jjSr)r/Z_gen_python_modulerRrrr�generates_python_module�sz Verifier.generates_python_modulecsz|rvtj�|�rvtj�|��|��}tjD]J}||vr*||}t|ttf�sZt	d|f���fdd�|D�}|||<q*|S)Nz&keyword '%s' should be a list or tuplecsg|]}tj��|��qSr)r@rAr4)r�fn��dirnamerrr��z-Verifier.make_relative_to.<locals>.<listcomp>)
r@rArc�copyrZLIST_OF_FILE_NAMESr�list�tupler3)rr2rIrJZlstrrbrr1�s
�
zVerifier.make_relative_tocCs�tj�|j�st|jrHzt|jdddg�}Wnty>YdS0|j}nd}|j�	|�
�|t��}|durndS||_|j��d|_
dS)N�__doc__T)r@rA�isfilerCrD�
__import__�ImportError�__path__r/�find_moduler]r=Z
collect_typesrF)r�pkgrA�filenamerrrrT�s �
zVerifier._locate_modulecCs*||j_z|j��W|j`n|j`0dSr)r/Z_fZwrite_source_to_frNrrr�_write_source_to�szVerifier._write_source_tocCs�|dur|�|�n�t�}|�|�|��}tj�|j�rvt|jd��}|��|k}Wd�qz1sj0Ynd}|r�t	|j�t|jd��}|�
|�Wd�n1s�0Yd|_dS)N�rT�w)rpr�getvaluer@rA�existsrB�open�read�_ensure_dirrrE)rrO�fZsource_data�fpZ
needs_writtenrrrrM�s
.
(zVerifier._write_sourcecCsntj�|j�}t�||���}zt�||j�}Wnt	yFd}Yn0|sdt
|j�t�||j�d|_
dS)NFT)r@rArcrBr�compiler^�samefilerC�OSErrorrw�shutil�moverF)rr?ZoutputfilenameZsamerrrrQ�s

zVerifier._compile_modulecCs0|js
J�|jdur"|j�|j�S|j��SdSr)rFr0r/rVrRrrrrU�s

zVerifier._load_library)NNNr%Fr&NN)N)N)r r!r"rKrPrSrVr]r^r`r1rTrprMrQrUrrrrr$s �
(
	



r$FcCsztrd}|sNdtjvrd}n2zddl}Wnty>d}Yn0|j|urNd}|rdddlm}|jSddlm	}|j
SdS)NTZ__pypy__r�?r)�vengine_gen)�vengine_cpy)�_FORCE_GENERIC_ENGINEr5�builtin_module_names�
_cffi_backendrkZ_backendr%r�ZVGenericEnginer�ZVCPythonEngine)r,rHr�r�r�rrrr.�s 


r.cCsHtrtStj�d�}|r|St�d�jj}tj�	tj�
tj�|�d��S)NZCFFI_TMPDIRr(�__pycache__)�_TMPDIRr@�environ�getr5�	_getframe�f_code�co_filenamerA�abspathr4rc)�resultrorrrr>�s�r>cCs|adS)z:Set the temporary directory to use instead of __pycache__.N)r�rbrrr�
set_tmpdirsr�c	Cs|pt�}zt�|�}Wnty,YdS0|r8d}nt�d��}|D]Z}|���d�rJ|���|�sx|���d�rJzt�tj	�
||��WqJty�YqJ0qJtj	�
|d�g}|D]^}zDt�|�D]4}tj	�
||�}tj	�|�r�|�|�q�t�|�q�Wq�t�yYq�0q�dS)z}Clean up the temporary directory by removing all files in it
    called `_cffi_*.{c,so}` as well as the `build` subdirectory.Nr&rZ_cffi_Zbuild)
r>r@�listdirr|r=�lower�
startswithr[�unlinkrAr4�isdir�append)r?Zkeep_soZfilelistrraZ	clean_dir�dirrrr�cleanup_tmpdirs8
��r�cCs&t�}|s"tjdkrdg}ndg}|S)N�win32z.pydz.so)r
r5�platform)�suffixesrrrr=$s
r=cCs*tj�|�}|r&tj�|�s&t�|�dSr)r@rArcr��makedirs)rorcrrrrw/srw)NF)r5r@r9r}�ior%rr�errorrr7Zimportlib.machineryrr
r�StringIOr�BytesIO�objectr$r�r.r�r>r�r�r=rwrrrr�<module>s*(


?