Files
Automaaval/build/zacatraz/localpycs/pyimod02_importers.pyc
T

248 lines
30 KiB
Plaintext
Raw Normal View History

2026-03-14 21:48:05 +00:00
Ë
ãó
dZddlZddlZddlZddlZddlZddlZejjrejrdZ
ndZ
dZ da ej«ZdadZej"j%ej&«ZdZej,dk(rHej/d «r7d
Zej"j1ej"j3e«d «Zd ZGd
d«ZGdd«ZGdd«ZdZdZ y)z8
PEP-302 and PEP-451 importers for frozen applications.
éNcó†tjj||z«tjjd«y)
)ÚsysÚstderrÚwrite)ÚmsgÚas ú(PyInstaller\loader\pyimod02_importers.pyÚtracer s*Ü
×ј˜q™Ô
×јÕócóy))rr s r
r r $sØ r cóÐddlm}tj|«j}||«}tj
dd¬«}|j
|j
|d««S)a
Decode bytes representing source code and return the string. Universal newline support is used in the decoding.
Based on CPython's implementation of the same functionality:
https://github.com/python/cpython/blob/3.9/Lib/importlib/_bootstrap_external.py#L679-L688
r)Údetect_encodingNT)ÚdecoderÚ translate)ÚtokenizerÚioÚBytesIOÚreadlineÚIncrementalNewlineDecoderÚdecode)Ú source_bytesrÚsource_bytes_readlineÚencodingÚnewline_decoders r
Ú_decode_sourcer(sYõŸJ™J |ÓÙÐ5€HÜ×2¸4È4ÔP€OØ × ! ,×"5Ñ"5°h¸q±kÓ"BÓ Cr cópt5ttt«atcddd«S#1swYyxYw)N)Ú_pyz_tree_lockÚ _pyz_treeÚ_build_pyz_prefix_treeÚ pyz_archiverr r
Úget_pyz_toc_treer#@s/ô
ñÜ Ð Ü.¬{Ó;ˆIÜ÷÷òús,¬5darwinzContents/FrameworksTÚ ResourcescóNt«}|jj«D]}\}}|jd«}|d}|}|tj
tj hvr|D]}|j|i«}ŒŒZ|ddD]}|j|i«}Œd||d<Œ|S).réÿÿÿÿÚ)ÚdictÚtocÚitemsÚsplitÚpyimod01_archiveÚ PYZ_ITEM_PKGÚPYZ_ITEM_NSPKGÚ
setdefault)r"ÚtreeÚ
entry_nameÚ
entry_dataÚname_componentsÚtypecodeÚcurrentÚname_components r
r!r!WÜ 6€DØ"-§/¡/×"7Ñ"7Ó"9ò ˆ
*¨3ÓØ˜a‘=ˆØˆØ Ô5Ô7G×7VÑ7VÐ Wà"1ò
AØ,¨^¸RÓ@‘ñ
Að#2°#°2Ð"6ò
AØ,¨^¸RÓ@‘ð
Aà+-ˆGO    €Kr cóÎeZdZdZdZed«Zed«ZdZ dZ
e d«Z dZ
d „Zdd Zej"d
d d
krdZdZdZdZ dZdZdZdZdZdZdZy
)ÚPyiFrozenImporteraW
PyInstaller's frozen module importer (finder + loader) for specific search path.
Per-path instances allow us to properly translate the given module name ("fullname") into full PYZ entry name.
For example, with search path being `sys._MEIPASS`, the module "mypackage.mod" would translate to "mypackage.mod"
in the PYZ archive. However, if search path was `sys._MEIPASS/myotherpackage/_vendored` (for example, if
`myotherpacakge` added this path to `sys.path`), then "mypackage.mod" would need to translate to
"myotherpackage._vendored.mypackage.mod" in the PYZ archive.
cóN|jjd|jdS)))Ú __class__Ú__name__Ú_path)Úselfs r
Ú__repr__zPyiFrozenImporter.__repr__ss$Ø—..×*¨!¨D¯J©J¨<°qÐ9r cóŠtd|« ||«}td«|S#t$r}td|«d}~wwxYw)Nz0PyInstaller: running path finder hook for path: zPyInstaller: hook succeededzPyInstaller: hook failed: )r Ú Exception)ÚclsÚpathÚfinderÚes r
Ú path_hookzPyiFrozenImporter.path_hookvsQä
ÐÀÐ Ù˜“YˆFÜ Ð ˆMøÜò Ü Ð.¨q¨cÐ ûð ús%¥ A®=½Acóº tjj||«}|j d«r t d«|S#t$r}t d«|d}~wwxYw)Nz/Path outside of top-level application directoryz..)ÚosrFÚrelpathÚ
ValueErrorÚ ImportErrorÚ
startswith)rFÚ top_levelÚ
relative_pathrHs r
Ú_compute_relative_pathz(PyiFrozenImporter._compute_relative_pathsað XÜŸG™GŸO™O¨D°)Ó<ˆ × #  Ð Ðøô
ò XÜÐPÐVWÐ Wûð Xús AÁ AÁ AÁAcóÖ||_t|_tjj |«} |j
|t«}tjj|«r td«|dk(rd|_
ydj|jtjj ««|_
y#t$r!tr|j
|t«}nYŒžwxYw)Nzonly directories are supportedr'r))r@r"Ú _pyz_archiverKrFÚrealpathrRÚ_RESOLVED_TOP_LEVEL_DIRECTORYrDÚ_is_macos_app_bundleÚ _ALTERNATIVE_TOP_LEVEL_DIRECTORYÚisfilerNÚ_pyz_entry_prefixÚjoinr-Úsep)rArFÚ
resolved_pathrQs r
Ú__init__zPyiFrozenImporter.__init__؈Œ
ÜÔôŸ×Ó
ð Ø ×7¸
ÔGdÓeˆ 7‰7>‰>˜ ÜÐ ˜ Ø%'ˆ "à%(§X¡X¨m×.AÑ.AÄ"Ç'Á'Ç+Á+Ó.NÓ%Oˆ "øôò Ý#Ø $× ;Ñ ;¸MÔKkÓ l
àñð ús³B>Â>'C(Ã'C(cój|jd«d}|jr|jdz|zS|S)zz
Convert module fullname into PYZ entry name, subject to the prefix implied by this finder's search path.
r'é)Ú
rpartitionrZ)rAÚfullnameÚ tail_modules r
Ú_compute_pyz_entry_namez)PyiFrozenImporter._compute_pyz_entry_name¨s>ð×)¨#Ó.¨qÑ à × ×)¨CÑ/°+Ñ Ð r có.t|d«r |jSd}d|_ttj«D]>\}}||j
k(rd}Œ|sŒ ||j «|_|jS|jS#t$rYŒXwxYw)aB
Opportunistically create a *fallback finder* using `sys.path_hooks` entries that are located *after* our hook.
The main goal of this exercise is to obtain an instance of python's FileFinder, but in theory any other hook
that comes after ours is eligible to be a fallback.
Having this fallback allows our finder to "cooperate" with python's FileFinder, as if the two were a single
finder, which allows us to work around the python's PathFinder permitting only one finder instance per path
without subclassing FileFinder.
Ú_fallback_finderFNT)ÚhasattrrfÚ enumeraterÚ
path_hooksrIr@rN)rAÚour_hook_foundÚidxÚhooks r
Úfallback_finderz!PyiFrozenImporter.fallback_finder³ô  × ˆà $ˆÔÜ"¤3§>¡>Ó ‰IˆCØt—~‘~Ò%Ø!%Øáð
Ù(,¨T¯Z©ZÓ(8Ôð× ð×$øôò
Ùð
úsÁBÂ BÂBcó–t|d«s|j«|_|jy|jj||«S)a@
Attempt to find the spec using fallback finder, which is opportunistically created here. Typically, this would
be python's FileFinder, which can discover specs for on-filesystem modules, such as extension modules and
modules that are collected only as source .py files.
Having this fallback allows our finder to "cooperate" with python's FileFinder, as if the two were a single
finder, which allows us to work around the python's PathFinder permitting only one finder instance per path
without subclassing FileFinder.
rfN)rgÚ_get_fallback_finderrfÚ find_spec)rArbÚtargets r
Ú_find_fallback_specz%PyiFrozenImporter._find_fallback_specÕsHô0Ø$(×$=Ñ$=Ó$?ˆ × Ñ Ð à×.¨x¸Ó@r có^t|dd«}|t|d«r|j«yyy)a<
A method which, when called, should invalidate any internal cache used by the finder. Used by
importlib.invalidate_caches() when invalidating the caches of all finders on sys.meta_path.
https://docs.python.org/3/library/importlib.html#importlib.abc.MetaPathFinder.invalidate_caches
rfinvalidate_caches)Úgetattrrgrt)rArms r
rtz#PyiFrozenImporter.invalidate_cachesés:ô" $Ð(:¸AˆØ Ð Ð(;Ô× 'r Nc ó¢t|d|d|«|j|«}|jjj |«}|€vt|d|d«|j
Jt|d|j
d«|j
j
||«}t|d|d«|St|d «y|d
}t|d |d |d
|«|tjk(rttj|d«}tjjtj|j!dtjj"««g|_|S|j'|«}|tj(k(} tj||| |¬«}d|_| r%tjj-|«g|_|S)
A method for finding a spec for the specified module. The finder will search for the module only within the
path entry to which it is assigned. If a spec cannot be found, None is returned. When passed in, target is a
module object that the finder may use to make a more educated guess about what spec to return.
https://docs.python.org/3/library/importlib.html#importlib.abc.PathEntryFinder.find_spec
z": find_spec: called with fullname=z , target=Nz
: find_spec: z not found in PYZ...z6: find_spec: attempting resolve using fallback finder r'z,: find_spec: fallback finder returned spec: z.: find_spec: fallback finder is not available.rz: find_spec: found z in PYZ as z , typecode=)Ú
is_packageÚoriginT)r rdrTr+Úgetrmrpr.r0Ú_frozen_importlibÚ
ModuleSpecrKrFr[rÚ_MEIPASSÚreplacer\Úsubmodule_search_locationsÚ get_filenamer/Ú has_locationÚdirname)
rArbrqÚpyz_entry_namer4Ú
fallback_specr6Úspecrxrws
r
rpzPyiFrozenImporter.find_specøô и ÀIÈhÈ\Ð×5°hÓ?ˆð×&×*×.¨~Ó>ˆ
Ø Ð ô
TF˜ |Ð3GРט˜ÐTÐUY×UiÑUiÐTlÐlmÐoØ $× 4Ñ 4× >Ñ >¸Ó P
ܘ˜ÐJÈ=ÐJ[Ð[\И˜Ðð˜a‘=ˆÜ
Ð)¨(¨°[ÀÐ@RÐR]Ð^fÐ]gÐ Ô'× %׸$Ó?ˆDô œSŸ\™\¨>×+AÑ+AÀ#ÄrÇwÁwÇ{Á{Ó+SÓ/ˆ
ˆ×" ,ˆØÔ!1×!>Ñ!>Ñ>ˆ
ä × Ø Øô 
ˆðÔñ Ü/1¯w©w¯©¸vÓ/FÐ.Gˆ ˆ r r`)éé cóh|j|«}|dgfS|j|jxsgfS)a×
A legacy method for finding a loader for the specified module. Returns a 2-tuple of (loader, portion) where
portion is a sequence of file system locations contributing to part of a namespace package. The loader may
be None while specifying portion to signify the contribution of the file system locations to a namespace
package. An empty list can be used for portion to signify the loader is not part of a namespace package. If
loader is None and portion is the empty list then no loader or location for a namespace package were found
(i.e. failure to find anything for the module).
Deprecated since python 3.4, removed in 3.12.
N)rpÚloaderr~)rArbr„s r
Ú find_loaderzPyiFrozenImporter.find_loaderBs:ð—>> +ˆˆ˜RxØ—;‘; × ?Ñ ?Ò EÀ2Ð Er có.|j|«\}}|S)
A concrete implementation of Finder.find_module() which is equivalent to self.find_loader(fullname)[0].
Deprecated since python 3.4, removed in 3.12.
)r‰)rArbrˆÚportionss r
Ú find_modulezPyiFrozenImporter.find_moduleTsð $×Ó ˆFˆMr cóy)a 
A method that returns the module object to use when importing a module. This method may return None, indicating
that default module creation semantics should take place.
https://docs.python.org/3/library/importlib.html#importlib.abc.Loader.create_module
Nr)rAr„s r
Ú
create_modulezPyiFrozenImporter.create_modulecsðr có
|j}|j|j«}|td|jd«t |d«sJ|j
|j
|_t||j«y)a[
A method that executes the module in its own namespace when a module is imported or reloaded. The module
should already be initialized when exec_module() is called. When this method exists, create_module()
must be defined.
https://docs.python.org/3/library/importlib.html#importlib.abc.Loader.exec_module
Nz Failed to retrieve bytecode for ú__file__) Ú__spec__Úget_codeÚnameÚ RuntimeErrorrgr~Ú__path__ÚexecÚ__dict__)rAÚmoduler„Úbytecodes r
Ú exec_modulezPyiFrozenImporter.exec_modulelsyðˆØ—=‘= §¡ÓØ Ð ÜÐ!AÀ$Ç)Á)ÀÈaÐ v˜zÔ × "×=ˆFŒOä ˆXv—Õ'r có2ddlm}|j||«S)aK
A legacy method for loading a module. If the module cannot be loaded, ImportError is raised, otherwise the
loaded module is returned.
Deprecated since python 3.4, slated for removal in 3.12 (but still present in python's own FileLoader in
both v3.12.4 and v3.13.0rc1).
rN)Úimportlib._bootstrapÚ
_bootstrapÚ_load_module_shim)rArbs r
Ú load_modulezPyiFrozenImporter.load_module‡sõ
×°hÓ ?r cóN|j|«}|jjj|«}|t d|d|d«|d}|t
j k(rWtjjtj|jdtjj«d«S|t
jk(rYtjjtj|jdtjj«dz«Sy) a 
A method that is to return the value of __file__ for the specified module. If no path is available, ImportError
is raised.
If source code is available, then the method should return the path to the source file, regardless of whether a
bytecode was used to load the module.
https://docs.python.org/3/library/importlib.html#importlib.abc.ExecutionLoader.get_filename
Module ú! not found in PYZ archive (entry ú).rr'z __init__.pycú.pyc)rdrTr+ryrNr.r/rKrFr[rr|r}r\ÚPYZ_ITEM_MODULE)rArbrr4r6s r
rzPyiFrozenImporter.get_filenameð×5°hÓ?ˆð×&×*×.¨~Ó>ˆ
Ø Ð Ü ¨ |Ð3TÐUcÐTfÐfhÐ ˜a=ˆð Ô'× —77—<§ ¡ ¨n×.DÑ.DÀSÌ"Ï'É'Ï+É+Ó.VÐXfÓ
Ô)×
—77—<§ ¡ ¨n×.DÑ.DÀSÌ"Ï'É'Ï+É+Ó.VÐY_Ñ._Ó r cóÌ|j|«}|jjj|«}|t d|d|d«|jj |«S)aL
Return the code object for a module, or None if the module does not have a code object (as would be the case,
for example, for a built-in module). Raise an ImportError if loader cannot find the requested module.
https://docs.python.org/3/library/importlib.html#importlib.abc.InspectLoader.get_code
)rdrTr+ryrNÚextract)rArbrr4s r
r“zPyiFrozenImporter.get_codeµsmð×5°hÓ?ˆð×&×*×.¨~Ó>ˆ
Ø Ð Ü ¨ |Ð3TÐUcÐTfÐfhÐ × Ñ ×Ó8r cóÆ|j|«}|dd} t|d«5}|j«}ddd«t«S#1swYŒxYw#t$rYywxYw)
A method to return the source of a module. It is returned as a text string using universal newlines, translating
all recognized line separators into '
' characters. Returns None if no source is available (e.g. a built-in
module). Raises ImportError if the loader cannot find the module specified.
https://docs.python.org/3/library/importlib.html#importlib.abc.InspectLoader.get_source
Nr(Úrb)rÚopenÚreadrÚFileNotFoundError)rArbÚfilenameÚfprs r
Ú
get_sourcezPyiFrozenImporter.get_sourceÆsuð×$ XÓð
˜C˜Rð äÓ
Ø!Ÿw™wy ÷
!  

)ûô Ø ðð  ús'˜ A¤AµAÁAÁ
AÁ A ÁA cóÆ|j|«}|jjj|«}|t d|d|d«|d}|t
j k(S)a 
A method to return a true value if the module is a package, a false value otherwise. ImportError is raised if
the loader cannot find the module.
https://docs.python.org/3/library/importlib.html#importlib.abc.InspectLoader.is_package
r)rdrTr+ryrNr.r/)rArbrr4r6s r
rwzPyiFrozenImporter.is_packageâssð×5°hÓ?ˆð×&×*×.¨~Ó>ˆ
Ø Ð Ü ¨ |Ð3TÐUcÐTfÐfhÐ ˜a‘=ˆðÔ8r cóft|d«5}|j«cddd«S#1swYyxYw)u

A method to return the bytes for the data located at path. Loaders that have a file-like storage back-end that
allows storing arbitrary data can implement this abstract method to give direct access to the data stored.
OSError is to be raised if the path cannot be found. The path is expected to be constructed using a module’s
__file__ attribute or an item from a package’s __path__.
https://docs.python.org/3/library/importlib.html#importlib.abc.ResourceLoader.get_data
N))rArFs r
Úget_datazPyiFrozenImporter.get_dataøs.ô$˜Ó
ð  Ø—7‘7“9÷ ÷ ò ús'§0có<|j|«}t||«S)zO
Return resource reader compatible with `importlib.resources`.
)rdÚPyiFrozenResourceReader)rArbrs r
Úget_resource_readerz%PyiFrozenImporter.get_resource_readers!ð
×5°hÓ?ˆä& t¨^Ó<r )N)r?Ú
__module__Ú __qualname__Ú__doc__rBÚ classmethodrIÚ staticmethodrRr^rdÚpropertyrmrrrtrprÚ version_infor‰rr rr“rwrr r
r:r:iñòñóððñ óð òPò6 ðñð%òBAò(
DðP ×ј˜Ð˜gÒ Fò$ òò(ð2 ò @òò>9ò"ò89ò, ó=r r:có4eZdZdZdZdZdZdZdZdZ y) rµ
Resource reader for importlib.resources / importlib_resources support.
Supports only on-disk resources, which should cover the typical use cases, i.e., the access to data files;
PyInstaller collects data files onto filesystem, and as of v6.0.0, the embedded PYZ archive is guaranteed
to contain only .pyc modules.
When listing resources, source .py files will not be listed as they are not collected by default. Similarly,
sub-directories that contained only .py files are not reconstructed on filesystem, so they will not be listed,
either. If access to .py files is required for whatever reason, they need to be explicitly collected as data files
anyway, which will place them on filesystem and make them appear as resources.
For on-disk resources, we *must* return path compatible with pathlib.Path() in order to avoid copy to a temporary
file, which might break under some circumstances, e.g., metpy with importlib_resources back-port, due to:
https://github.com/Unidata/MetPy/blob/a3424de66a44bf3a92b0dcacf4dff82ad7b86712/src/metpy/plots/wx_symbols.py#L24-L25
(importlib_resources tries to use 'fonts/wx_symbols.ttf' as a temporary filename suffix, which fails as it contains
a separator).
Furthermore, some packages expect files() to return either pathlib.Path or zipfile.Path, e.g.,
https://github.com/tensorflow/datasets/blob/master/tensorflow_datasets/core/utils/resource_utils.py#L81-L97
This makes implementation of mixed support for on-disk and embedded resources using importlib.abc.Traversable
protocol rather difficult.