zmc
2023-12-22 9fdbf60165db0400c2e8e6be2dc6e88138ac719a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
U
L±d(-ã@sêddlZddlZddlZddlZddlZddlmZddlmZddlm    Z    ej
dkrhddl Z dd„Z nddlZd    d„Z ej
d
krŠejZnGd d „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©r r úDd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\cffi/verifier.pyÚ_extension_suffixes sr cCsdd„t ¡DƒS)NcSs g|]\}}}|tjkr|‘qSr )ÚimpÚ C_EXTENSION)Ú.0ÚsuffixÚ_Útyper r r Ú
<listcomp>s
ÿz'_extension_suffixes.<locals>.<listcomp>)rZ get_suffixesr r r r r s©rcseZdZ‡fdd„Z‡ZS)ÚNativeIOcs(t|tƒr| d¡}tt|ƒ |¡dS)NÚascii)Ú
isinstanceÚunicodeÚencodeÚsuperrÚwrite)ÚselfÚs©Ú    __class__r r rs
 
zNativeIO.write)Ú__name__Ú
__module__Ú __qualname__rÚ __classcell__r r rr rsrc@szeZdZddd„Zd dd„Zd    d
„Zd d „Zd d„Zdd„Zdd„Z    dd„Z
dd„Z dd„Z d!dd„Z dd„Zdd„ZdS)"ÚVerifierNÚFú.cc Ksz|jjrtd|jjfƒ‚||_||_|s4t | ¡} t||ƒ} | |ƒ|_|j     | ¡|    |_
|  | |
¡|_ |rz|rxt dƒ‚n¦d dtjdd…t|| g|j¡}tjdkr´| d¡}tt |ddd…¡d    @ƒ}| d
¡ d ¡}tt |d dd…¡d    @ƒ}| d ¡ d ¡}d||jj||f}tƒd}|p4tƒ|_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'úz%d.%dérzutf-8rlÿÿÚ0xÚLrÚ0z_cffi_%s_%s%s%sF)$Ú_parserZ_uses_new_featurerÚffiÚpreamblerÚflattenÚ_locate_engine_classÚ_vengineZpatch_extension_kwdsÚflagsÚmake_relative_toÚkwdsÚ    TypeErrorÚjoinÚsysÚ version_inforZ _cdefsourcesrÚ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/rAÚ
modulenamerFÚtagÚforce_generic_engineZsource_extensionr3Ú relative_tor5Zflattened_kwdsZ vengine_classÚkeyZk1Zk2rr r r Ú__init__ sTÿÿ
 
 
 
þý
 
 
ÿ
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.Ú_lockrGrÚ _write_source©rÚfiler r r Ú write_sourceIs 
ÿzVerifier.write_sourcec    Cs<|jj*|jrtdƒ‚|js&| ¡| ¡W5QRXdS)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.rOrHrrGrPÚ_compile_module©rr r r Úcompile_moduleRs 
zVerifier.compile_modulec
CsR|jj@|js4| ¡|js4|js,| ¡| ¡| ¡W5QR£SQRXdS)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.rOrHÚ_locate_modulerGrPrTÚ _load_libraryrUr r r Ú load_library\s
zVerifier.load_librarycCsBtj |j¡}| dd¡d}| d¡r>ttdƒr>|dd…}|S)NÚ.rrZ_dÚgettotalrefcountéþÿÿÿ)rBrCÚbasenamerEÚsplitÚendswithÚhasattrr8)rr]r r r Úget_module_namels
 zVerifier.get_module_namec    CsVt ¡|js0|jj|js&| ¡W5QRXt |j¡}| ¡}tj    ||f|j
ŽSr) rZ_hack_at_distutilsrGr.rOrPZmaybe_relative_pathrDraÚ get_extensionr5)rZ
sourcenameÚmodnamer r r rbws
 zVerifier.get_extensioncCs|jjSr)r2Z_gen_python_modulerUr r r Úgenerates_python_modulesz Verifier.generates_python_modulecsz|rvtj |¡rvtj |¡‰| ¡}tjD]J}||kr*||}t|ttfƒsZt    d|fƒ‚‡fdd„|Dƒ}|||<q*|S)Nz&keyword '%s' should be a list or tuplecsg|]}tj ˆ|¡‘qSr )rBrCr7)rÚfn©Údirnamer r rŽsz-Verifier.make_relative_to.<locals>.<listcomp>)
rBrCrgÚcopyrZLIST_OF_FILE_NAMESrÚlistÚtupler6)rr5rLrMÚlstr rfr r4„s 
ÿ
zVerifier.make_relative_tocCsŠtj |j¡sv|jrJzt|jdddgƒ}Wntk
r@YdSX|j}nd}|j     | 
¡|t ƒ¡}|dkrpdS||_|j  ¡d|_ dS)NÚ__doc__T)rBrCÚisfilerErFÚ
__import__Ú ImportErrorÚ__path__r2Ú find_modulerar?Z collect_typesrH)rÚpkgrCÚfilenamer r r rW”s ÿ
zVerifier._locate_modulecCs$||j_z|j ¡W5|j`XdSr)r2Z_fZwrite_source_to_frQr r r Ú_write_source_to§szVerifier._write_source_toc    Cs |dk    r| |¡nˆtƒ}| |¡| ¡}tj |j¡rbt|jdƒ}| ¡|k }W5QRXnd}|r–t    |jƒt|jdƒ}| 
|¡W5QRXd|_ dS)NÚrTÚw) rtrÚgetvaluerBrCÚexistsrDÚopenÚreadÚ _ensure_dirrrG)rrRÚfZ source_dataÚfpZ needs_writtenr r r rP®s 
 
zVerifier._write_sourcecCsptj |j¡}t || ¡¡}zt ||j¡}Wnt    k
rHd}YnX|sft
|jƒt   ||j¡d|_ dS)NFT)rBrCrgrDrÚcompilerbÚsamefilerEÚOSErrorr{ÚshutilÚmoverH)rrAZoutputfilenameZsamer r r rTÇs
 
zVerifier._compile_modulecCs0|js
t‚|jdk    r"|j |j¡S|j ¡SdSr)rHÚAssertionErrorr3r2rYrUr r r rXÔs
 
zVerifier._load_library)NNNr&Fr'NN)N)N)r!r"r#rNrSrVrYrarbrdr4rWrtrPrTrXr r r r 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_ENGINEr8Úbuiltin_module_namesÚ _cffi_backendroZ_backendr&r…ZVGenericEnginer†ZVCPythonEngine)r.rKr‰r…r†r r r r1ßs 
 
 
  r1cCsHtrtStj d¡}|r|St d¡jj}tj     tj 
tj  |¡d¡¡S)NZ CFFI_TMPDIRr)Ú __pycache__) Ú_TMPDIRrBÚenvironÚgetr8Ú    _getframeÚf_codeÚ co_filenamerCÚabspathr7rg)Úresultrsr r r r@÷s ÿr@cCs|adS)z:Set the temporary directory to use instead of __pycache__.N)r‹rfr r r Ú
set_tmpdirsr“c    Cs$|ptƒ}zt |¡}Wntk
r.YdSX|r:d}ntƒd ¡}|D]\}| ¡ d¡rL| ¡ |¡sz| ¡ d¡rLzt tj     
||¡¡WqLtk
r¦YqLXqLtj     
|d¡g}|D]`}zDt |¡D]4}tj     
||¡}tj      |¡rø|  |¡qÎt |¡qÎWq¾tk
rYq¾Xq¾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_Úbuild) r@rBÚlistdirr€r?ÚlowerÚ
startswithr_ÚunlinkrCr7ÚisdirÚappend)rAZkeep_soÚfilelistrreZ    clean_dirÚdirr r r Úcleanup_tmpdirs8
 ÿ ÿ  rcCs&tƒ}|s"tjdkrdg}ndg}|S)NÚwin32z.pydz.so)r r8Úplatform)Úsuffixesr r r r?%s 
r?cCs*tj |¡}|r&tj |¡s&t |¡dSr)rBrCrgr™Úmakedirs)rsrgr r r r{0s r{)NF)r8rBr;rÚior&rrÚerrorrr9Zimportlib.machineryrr rÚStringIOrÚBytesIOÚobjectr%r‡r1r‹r@r“rr?r{r r r r Ú<module>s*(   
 
 
@