Viewing File: /opt/alt/python38/lib64/python3.8/site-packages/cffi/__pycache__/verifier.cpython-38.pyc

U

ل=^+@sddlZddlZddlZddlZddlZddlmZddlmZddlm	Z	ej
dkrhddlZddZ
nddlZd	dZ
ej
d
krejZnGdddejZGd
ddeZdZddZdaddZddZdddZddZddZdS)N)__version_verifier_modules__)ffiplatform)VerificationError)rcCstjjddSN)	importlib	machineryEXTENSION_SUFFIXESrr/verifier.py_extension_suffixessr
cCsddtDS)NcSs g|]\}}}|tjkr|qSr)impZC_EXTENSION).0suffix_typerrr
<listcomp>s
z'_extension_suffixes.<locals>.<listcomp>)rZget_suffixesrrrrr
srcseZdZfddZZS)NativeIOcs(t|tr|d}tt||dS)Nascii)
isinstanceZunicodeencodesuperrwrite)selfs	__class__rrrs

zNativeIO.write)__name__
__module____qualname__r
__classcell__rrrrrsrc@szeZdZdddZd ddZd	d
ZddZd
dZddZddZ	ddZ
ddZddZd!ddZ
ddZddZdS)"VerifierNF.ccKsv|jjrtd|jjf||_||_|s4t|}t||}
|
||_|j	||	|_
|||
|_|rz|rxt
dndtjddt||g|j}tjdkr|d}tt|dddd	@}|d
d}tt|dddd	@}|d
d}d||jj||f}td}|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-8rlZ0xLr0z_cffi_%s_%s%s%sF)%Z_parserZ_uses_new_featurerffipreamblerZflatten_locate_engine_class_vengineZpatch_extension_kwdsflagsmake_relative_tokwds	TypeErrorjoinsysversionrZ_cdefsourcesversion_inforhexbinasciiZcrc32lstriprstripZ
_class_key_get_so_suffixes_caller_dir_pycachetmpdirospathsourcefilenamemodulefilenameext_package_has_source_has_module)rr*r+r<Z
modulenamerAtagforce_generic_engineZsource_extensionr.relative_tor0Zflattened_kwdsZ
vengine_classkeyZk1Zk2rrrr__init__ sR







zVerifier.__init__c	Cs8|jj&|jr |dkr td||W5QRXdS)zkWrite the C source code.  It is produced in 'self.sourcefilename',
        which can be tweaked beforehand.Nzsource code already written)r*_lockrBr
_write_sourcerfilerrrwrite_sourceHs
zVerifier.write_sourcec	Cs<|jj*|jrtd|js&||W5QRXdS)zWrite the C source code (if not done already) and compile it.
        This produces a dynamic link library in 'self.modulefilename'.zmodule already compiledN)r*rIrCrrBrJ_compile_modulerrrrcompile_moduleQs
zVerifier.compile_modulec
CsR|jj@|js4||js4|js,|||W5QRSQRXdS)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*rIrC_locate_modulerBrJrN
_load_libraryrOrrrload_library[s
zVerifier.load_librarycCsBtj|j}|ddd}|dr>ttdr>|dd}|S)N.rrZ_dZgettotalrefcount)r=r>basenamer@splitendswithhasattrr3)rrVrrrget_module_nameks
zVerifier.get_module_namec	CsVt|js0|jj|js&|W5QRXt|j}|}tj	||f|j
Sr)rZ_hack_at_distutilsrBr*rIrJZmaybe_relative_pathr?rZ
get_extensionr0)rZ
sourcenamemodnamerrrr[vs
zVerifier.get_extensioncCs|jjSr)r-Z_gen_python_modulerOrrrgenerates_python_modulesz Verifier.generates_python_modulecsz|rvtj|rvtj||}tjD]J}||kr*||}t|ttfsZt	d|ffdd|D}|||<q*|S)Nz&keyword '%s' should be a list or tuplecsg|]}tj|qSr)r=r>r2)rfndirnamerrrsz-Verifier.make_relative_to.<locals>.<listcomp>)
r=r>r`copyrZLIST_OF_FILE_NAMESrlisttupler1)rr0rFrGZlstrr_rr/s

zVerifier.make_relative_tocCstj|jsv|jrJzt|jdddg}Wntk
r@YdSX|j}nd}|j	|
|t}|dkrpdS||_|jd|_
dS)N__doc__T)r=r>isfiler@rA
__import__ImportError__path__r-find_modulerZr:Z
collect_typesrC)rZpkgr>filenamerrrrQs 
zVerifier._locate_modulecCs$||j_z|jW5|j`XdSr)r-Z_fZwrite_source_to_frKrrr_write_source_toszVerifier._write_source_toc	Cs|dk	r||nt}|||}tj|jrbt|jd}||k}W5QRXnd}|rt	|jt|jd}|
|W5QRXd|_dS)NrTw)rkrgetvaluer=r>existsr?openread_ensure_dirrrB)rrLfZsource_datafpZ
needs_writtenrrrrJs

zVerifier._write_sourcecCsptj|j}t||}zt||j}Wnt	k
rHd}YnX|sft
|jt||jd|_
dS)NFT)r=r>r`r?rcompiler[samefiler@OSErrorrrshutilZmoverC)rr<ZoutputfilenameZsamerrrrNs

zVerifier._compile_modulecCs0|js
t|jdk	r"|j|jS|jSdSr)rCAssertionErrorr.r-rSrOrrrrRs

zVerifier._load_library)NNNr$Fr%NN)N)N)rr r!rHrMrPrSrZr[r]r/rQrkrJrNrRrrrrr#s(
(
	



r#FcCs|trd}|sPdtjkrd}n4zddl}Wntk
r@d}YnX|j|k	rPd}|rfddlm}|jSddlm	}|j
SdS)NTZ__pypy__r?r)vengine_gen)vengine_cpy)_FORCE_GENERIC_ENGINEr3builtin_module_names
_cffi_backendrgZ_backendr$r{ZVGenericEnginer|ZVCPythonEngine)r*rErr{r|rrrr,s 


r,cCsHtrtStjd}|r|Stdjj}tj	tj
tj|dS)NZCFFI_TMPDIRr'__pycache__)_TMPDIRr=environgetr3	_getframef_codeco_filenamer>abspathr2r`)resultrjrrrr;sr;cCs|adS)z:Set the temporary directory to use instead of __pycache__.N)rr_rrr
set_tmpdirsrc	Cs$|pt}zt|}Wntk
r.YdSX|r:d}ntd}|D]\}|drL||sz|drLzttj	
||WqLtk
rYqLXqLtj	
|dg}|D]`}zDt|D]4}tj	
||}tj	|r||qt|qWqtk
rYqXqdS)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=listdirrwr:lower
startswithrXunlinkr>r2isdirappend)r<Zkeep_soZfilelistrr^Z	clean_dirdirrrrcleanup_tmpdirs8
rcCs&t}|s"tjdkrdg}ndg}|S)NZwin32z.pydz.so)r
r3platform)suffixesrrrr:$s
r:cCs*tj|}|r&tj|s&t|dSr)r=r>r`rmakedirs)rjr`rrrrr/srr)NF)r3r=r7rxior$rrerrorrr5Zimportlib.machineryrr
rStringIOrBytesIOobjectr#r}r,rr;rrr:rrrrrr<module>s*(


?


Back to Directory File Manager