관리-도구
편집 파일: verifier.cpython-39.pyc
a ����(�`�+����������������������@���s����d�dl�Z�d�dlZd�dlZd�dlZd�dlZddlmZ�ddlmZ�ddlm Z �e�j dkrhd�dlZdd��Z nd�dlZd d��Z e�j d kr�ejZnG�dd��dej�ZG�d d��de�ZdZdd��Zdadd��Zdd��Zddd�Zdd��Zdd��ZdS�)�����N����)�__version_verifier_modules__)�ffiplatform)�VerificationError)����r���c�������������������C���s���t�jjd�d���S��N)� importlib� machinery�EXTENSION_SUFFIXES��r���r����3/usr/lib64/python3.9/site-packages/cffi/verifier.py�_extension_suffixes���s����r ���c�������������������C���s���dd��t����D��S�)Nc�����������������S���s ���g�|�]\}}}|t�jkr|�qS�r���)�imp�C_EXTENSION)�.0�suffix�_�typer���r���r���� <listcomp>���s��� �z'_extension_suffixes.<locals>.<listcomp>)r���Zget_suffixesr���r���r���r���r ������s�����r���c�����������������������s���e�Zd�Z��fdd�Z���ZS�)�NativeIOc��������������������s(���t�|t�r|�d�}tt|���|��d�S�)N�ascii)� isinstanceZunicode�encode�superr����write)�self�s�� __class__r���r���r������s���� zNativeIO.write)�__name__� __module__�__qualname__r���� __classcell__r���r���r���r���r������s���r���c�������������������@���sz���e�Zd�Zddd�Zd dd�Zd d ��Zdd��Zd d��Zdd��Zdd��Z dd��Z dd��Zdd��Zd!dd�Z dd��Zdd��ZdS�)"�VerifierN��F�.cc�����������������K���sv��|j�jrtd|j�jf���||�_||�_|s4t�|�}t||�} | |��|�_|�j� |��| |�_ |��|| �|�_|rz|rxt d��n�d�tjd�d��t||g|j��}tjdkr�|�d�}tt�|dd�d���d @��}|�d ��d�}tt�|dd�d���d @��}|�d ��d�}d||�jj||f�}t��d�}|�p0t��|�_tj�|�j||��|�_ tj�|�j||��|�_!||�_"d|�_#d|�_$d�S�)NzKfeature not supported with ffi.verify(), but only with ffi.set_source(): %sz)can't specify both 'modulename' and 'tag'��r���r���zutf-8r�������l�������0x�Lr����0z_cffi_%s_%s%s%sF)%Z_parserZ_uses_new_featurer����ffi�preambler���Zflatten�_locate_engine_class�_vengineZpatch_extension_kwds�flags�make_relative_to�kwds� TypeError�join�sys�versionr���Z_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)r���r,���r-���r?���Z modulenamerD����tag�force_generic_engineZsource_extensionr0����relative_tor2���Zflattened_kwdsZ vengine_class�keyZk1Zk2r���r���r���r����__init__ ���sN������ �� � zVerifier.__init__c�����������������C���sL���|�j�j�0�|�jr |du�r td��|��|��W�d����n1�s>0����Y��dS�)zkWrite the C source code. It is produced in 'self.sourcefilename', which can be tweaked beforehand.Nzsource code already written)r,����_lockrE���r���� _write_source�r����filer���r���r����write_sourceH���s���� �zVerifier.write_sourcec�����������������C���sP���|�j�j�4�|�jrtd��|�js&|�����|�����W�d����n1�sB0����Y��dS�)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,���rL���rF���r���rE���rM����_compile_module�r���r���r���r����compile_moduleQ���s���� zVerifier.compile_modulec�����������������C���s^���|�j�j�B�|�js4|�����|�js4|�js,|�����|�����|����W��d����S�1�sP0����Y��dS�)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,���rL���rF����_locate_modulerE���rM���rQ���� _load_libraryrR���r���r���r����load_library[���s���� zVerifier.load_libraryc�����������������C���sB���t�j�|�j�}|�dd�d�}|�d�r>ttd�r>|d�d��}|S�)N�.r���r���Z_dZgettotalrefcount���)r@���rA����basenamerC����split�endswith�hasattrr5���)r���rY���r���r���r����get_module_namek���s ����zVerifier.get_module_namec�����������������C���sn���t�����|�jsD|�jj��|�js&|�����W�d�����n1�s:0����Y��t��|�j�}|����}t�j ||fi�|�j ��S�r���)r���Z_hack_at_distutilsrE���r,���rL���rM���Zmaybe_relative_pathrB���r]���� get_extensionr2���)r���Z sourcename�modnamer���r���r���r^���v���s���� &zVerifier.get_extensionc�����������������C���s���|�j�jS�r���)r/���Z_gen_python_modulerR���r���r���r����generates_python_module����s����z Verifier.generates_python_modulec��������������������sz���|rvt�j�|�rvt�j�|���|���}tjD�]J}||v�r*||�}t|ttf�sZt d|f�����fdd�|D��}|||<�q*|S�)Nz&keyword '%s' should be a list or tuplec��������������������s���g�|�]}t�j���|��qS�r���)r@���rA���r4���)r����fn��dirnamer���r���r������������z-Verifier.make_relative_to.<locals>.<listcomp>) r@���rA���rc����copyr���ZLIST_OF_FILE_NAMESr����list�tupler3���)r���r2���rI���rJ���Zlstr���rb���r���r1�������s���� � zVerifier.make_relative_toc�����������������C���s����t�j�|�j�st|�jrHzt|�jd�d�dg�}W�n�ty>���Y�d�S�0�|j}nd�}|�j� |�� ��|t���}|d�u�rnd�S�||�_|�j����d|�_ d�S�)N�__doc__T)r@���rA����isfilerC���rD���� __import__�ImportError�__path__r/����find_moduler]���r=���Z collect_typesrF���)r����pkgrA����filenamer���r���r���rT�������s ����� zVerifier._locate_modulec�����������������C���s*���||�j�_z|�j�����W�|�j�`n|�j�`0�d�S�r���)r/���Z_fZwrite_source_to_frN���r���r���r����_write_source_to����s����zVerifier._write_source_toc�����������������C���s����|d�ur|���|��n�t��}|���|��|���}tj�|�j�rvt|�jd��}|���|k�}W�d�����qz1�sj0����Y��nd}|r�t |�j��t|�jd��}|� |��W�d�����n1�s�0����Y��d|�_d�S�)N�rT�w)rp���r����getvaluer@���rA����existsrB����open�read�_ensure_dirr���rE���)r���rO����fZsource_data�fpZ needs_writtenr���r���r���rM�������s���� . (zVerifier._write_sourcec�����������������C���sn���t�j�|�j�}t�||�����}zt�||�j�}W�n�t yF���d}Y�n0�|sdt |�j��t�||�j��d|�_ d�S�)NFT)r@���rA���rc���rB���r����compiler^����samefilerC����OSErrorrw����shutil�moverF���)r���r?���ZoutputfilenameZsamer���r���r���rQ�������s���� zVerifier._compile_modulec�����������������C���s0���|�j�s J��|�jd�ur"|�j�|�j�S�|�j���S�d�S�r���)rF���r0���r/���rV���rR���r���r���r���rU�������s���� zVerifier._load_library)NNNr%���Fr&���NN)N)N)r ���r!���r"���rK���rP���rS���rV���r]���r^���r`���r1���rT���rp���rM���rQ���rU���r���r���r���r���r$������s ������� ( r$���Fc�����������������C���sz���t�rd}|sNdtjv�rd}n2zdd�l}W�n�ty>���d}Y�n0�|�j|urNd}|rdddlm}�|jS�ddlm }�|j S�d�S�)NTZ__pypy__r����?r���)�vengine_gen)�vengine_cpy)�_FORCE_GENERIC_ENGINEr5����builtin_module_names� _cffi_backendrk���Z_backendr%���r����ZVGenericEnginer����ZVCPythonEngine)r,���rH���r����r����r����r���r���r���r.�������s ���� r.���c������������������C���sH���t�rt�S�tj�d�}�|�r|�S�t�d�jj}tj� tj� tj�|�d��S�)NZCFFI_TMPDIRr(����__pycache__)�_TMPDIRr@����environ�getr5���� _getframe�f_code�co_filenamerA����abspathr4���rc���)�resultro���r���r���r���r>�������s�����r>���c�����������������C���s���|�a�dS�)z:Set the temporary directory to use instead of __pycache__.N)r����rb���r���r���r���� set_tmpdir���s����r����c�������������� ���C���s��|�pt���}�zt�|��}W�n�ty,���Y�dS�0�|r8d}nt��d����}|D�]Z}|����d�rJ|����|�sx|����d�rJzt�tj � |�|���W�qJ�ty����Y�qJ0�qJtj � |�d�g}|D�]^}zDt�|�D�]4}tj � ||�}tj �|�r�|�|��q�t�|��q�W�q��t�y���Y�q�0�q�dS�)z}Clean up the temporary directory by removing all files in it called `_cffi_*.{c,so}` as well as the `build` subdirectory.Nr&���r���Z_cffi_Zbuild) r>���r@����listdirr|���r=����lower� startswithr[����unlinkrA���r4����isdir�append)r?���Zkeep_soZfilelistr���ra���Z clean_dir�dirr���r���r����cleanup_tmpdir��s8���� ��r����c������������������C���s&���t���}�|�s"tjdkrdg}�ndg}�|�S�)N�win32z.pydz.so)r ���r5����platform)�suffixesr���r���r���r=���$��s���� r=���c�����������������C���s*���t�j�|��}|r&t�j�|�s&t��|��d�S�r���)r@���rA���rc���r�����makedirs)ro���rc���r���r���r���rw���/��s����rw���)NF)r5���r@���r9���r}����ior%���r���r����errorr���r7���Zimportlib.machineryr���r ���r����StringIOr����BytesIO�objectr$���r����r.���r����r>���r����r����r=���rw���r���r���r���r����<module>���s*���( �?