U e5dܚ@sdZdaddZddZiZiZGdddeZGdd d ZGd d d Z Gd d d Z ddZ ddZ ddZ ddddZddZddZddZddZGd d!d!Zddd"d#d$Zd^d%d&Zd'd(d)d*Zd+d,Zd-d.Zd/d0Zd1d2Zd3d4Zd5d6ZGd7d8d8ZGd9d:d:ZGd;d<d<Zd=d>Z d?d@Z!d_dAdBZ"dCdDZ#dEZ$e$dFZ%dGdHZ&e'Z(dIdJZ)d`dLdMZ*d'dNdOdPZ+dQdRZ,dadTdUZ-dVdWZ.dXdYZ/dZd[Z0d\d]Z1dS)baSCore implementation of import. This module is NOT meant to be directly imported! It has been designed such that it can be bootstrapped into Python as the implementation of import. As such it requires the injection of specific modules and attributes in order to work. One should use importlib as the public-facing version of this module. NcCs8dD] }t||rt||t||q|j|jdS)z/Simple substitute for functools.update_wrapper.) __module____name__ __qualname____doc__N)hasattrsetattrgetattr__dict__update)newoldreplacer ,/usr/lib64/python3.8/importlib/_bootstrap.py_wraps rcCs tt|SN)typesysnamer r r _new_module#src@s eZdZdS)_DeadlockErrorN)rrrr r r rr0src@s8eZdZdZddZddZddZdd Zd d Zd S) _ModuleLockzA recursive lock implementation which is able to detect deadlocks (e.g. thread 1 trying to take locks A then B, and thread 2 trying to take locks B then A). cCs0t|_t|_||_d|_d|_d|_dSN)_thread allocate_locklockwakeuprownercountwaitersselfrr r r__init__:s   z_ModuleLock.__init__cCs<t}|j}t|}|dkr$dS|j}||krdSqdS)NFT)r get_identr _blocking_onget)r"metidrr r r has_deadlockBs z_ModuleLock.has_deadlockc Cst}|t|<z|jn|jdks.|j|krT||_|jd7_W5QRWVdS|rhtd||j dr|j d7_ W5QRX|j |j qW5t|=XdS)z Acquire the module lock. If a potential deadlock is detected, a _DeadlockError is raised. Otherwise, the lock is always acquired and True is returned. rTzdeadlock detected by %rFN) rr$r%rrrr)rracquirer releaser"r(r r rr+Ns   z_ModuleLock.acquirec Cszt}|jb|j|kr"td|jdks0t|jd8_|jdkrld|_|jrl|jd8_|j W5QRXdS)Ncannot release un-acquired lockrr*) rr$rr RuntimeErrorrAssertionErrorr rr,r-r r rr,gs  z_ModuleLock.releasecCsd|jt|S)Nz_ModuleLock({!r}) at {}formatridr"r r r__repr__tsz_ModuleLock.__repr__N) rrrrr#r)r+r,r5r r r rr4s   rc@s0eZdZdZddZddZddZdd Zd S) _DummyModuleLockzVA simple _ModuleLock equivalent for Python builds without multi-threading support.cCs||_d|_dSr)rrr!r r rr#|sz_DummyModuleLock.__init__cCs|jd7_dS)Nr*T)rr4r r rr+sz_DummyModuleLock.acquirecCs$|jdkrtd|jd8_dS)Nrr.r*)rr/r4r r rr,s z_DummyModuleLock.releasecCsd|jt|S)Nz_DummyModuleLock({!r}) at {}r1r4r r rr5sz_DummyModuleLock.__repr__N)rrrrr#r+r,r5r r r rr6xs r6c@s$eZdZddZddZddZdS)_ModuleLockManagercCs||_d|_dSr)_name_lockr!r r rr#sz_ModuleLockManager.__init__cCst|j|_|jdSr)_get_module_lockr8r9r+r4r r r __enter__s z_ModuleLockManager.__enter__cOs|jdSr)r9r,)r"argskwargsr r r__exit__sz_ModuleLockManager.__exit__N)rrrr#r;r>r r r rr7sr7cCstzjzt|}Wntk r0d}YnX|dkrptdkrLt|}nt|}|fdd}t ||t|<W5tX|S)zGet or create the module lock for a given module name. Acquire/release internally the global import lock to protect _module_locks.NcSs0tzt||krt|=W5tXdSr)_imp acquire_lock release_lock _module_locksr&)refrr r rcbs  z_get_module_lock..cb) r?r@rArBKeyErrorrr6r_weakrefrC)rrrDr r rr:s    r:cCs6t|}z |Wntk r(Yn X|dS)zAcquires then releases the module lock for a given module name. This is used to ensure a module is completely initialized, in the event it is being imported by another thread. N)r:r+rr,)rrr r r_lock_unlock_modules  rGcOs |||S)a.remove_importlib_frames in import.c will always remove sequences of importlib frames that end with a call to this function Use it instead of a normal call in places where including the importlib frames introduces unwanted noise into the traceback (e.g. when executing module code) r )fr<kwdsr r r_call_with_frames_removedsrJr*) verbositycGs6tjj|kr2|dsd|}t|j|tjddS)z=Print the message to stderr if -v/PYTHONVERBOSE is turned on.)#zimport z# )fileN)rflagsverbose startswithprintr2stderr)messagerKr<r r r_verbose_messages  rTcsfdd}t||S)z1Decorator to verify the named module is built-in.cs&|tjkrtd||d||S)N{!r} is not a built-in moduler)rbuiltin_module_names ImportErrorr2r"fullnamefxnr r_requires_builtin_wrappers   z4_requires_builtin.._requires_builtin_wrapperr)r[r\r rZr_requires_builtins  r^csfdd}t||S)z/Decorator to verify the named module is frozen.cs&t|std||d||SNz{!r} is not a frozen moduler)r? is_frozenrWr2rXrZr r_requires_frozen_wrappers   z2_requires_frozen.._requires_frozen_wrapperr])r[rar rZr_requires_frozens  rbcCs>t||}|tjkr2tj|}t||tj|St|SdS)zLoad the specified module into sys.modules and return it. This method is deprecated. Use loader.exec_module instead. N)spec_from_loaderrmodules_exec_load)r"rYspecmoduler r r_load_module_shims      ricCst|dd}t|dr8z ||WStk r6YnXz |j}Wntk rVYnX|dk rht|Sz |j}Wntk rd}YnXz |j}Wn:tk r|dkrd |YSd ||YSYnXd ||SdS)N __loader__ module_repr? ) rrrk Exception__spec__AttributeError_module_repr_from_specr__file__r2)rhloaderrgrfilenamer r r _module_repr s.       rwc@sreZdZdZddddddZddZdd Zed d Zej d d Zed dZ eddZ e j ddZ dS) ModuleSpecaThe specification for a module, used for loading. A module's spec is the source for information about the module. For data associated with the module, including source, use the spec's loader. `name` is the absolute name of the module. `loader` is the loader to use when loading the module. `parent` is the name of the package the module is in. The parent is derived from the name. `is_package` determines if the module is considered a package or not. On modules this is reflected by the `__path__` attribute. `origin` is the specific location used by the loader from which to load the module, if that information is available. When filename is set, origin will match. `has_location` indicates that a spec's "origin" reflects a location. When this is True, `__file__` attribute of the module is set. `cached` is the location of the cached bytecode file, if any. It corresponds to the `__cached__` attribute. `submodule_search_locations` is the sequence of path entries to search when importing submodules. If set, is_package should be True--and False otherwise. Packages are simply modules that (may) have submodules. If a spec has a non-None value in `submodule_search_locations`, the import system will consider modules loaded from the spec as packages. Only finders (see importlib.abc.MetaPathFinder and importlib.abc.PathEntryFinder) should modify ModuleSpec instances. N)origin loader_state is_packagecCs6||_||_||_||_|r gnd|_d|_d|_dSNF)rruryrzsubmodule_search_locations _set_fileattr_cached)r"rruryrzr{r r rr#VszModuleSpec.__init__cCsfd|jd|jg}|jdk r4|d|j|jdk rP|d|jd|jjd|S)Nz name={!r}z loader={!r}z origin={!r}zsubmodule_search_locations={}z{}({})z, ) r2rruryappendr} __class__rjoin)r"r<r r rr5bs    zModuleSpec.__repr__cCsj|j}zH|j|jkoL|j|jkoL|j|jkoL||jkoL|j|jkoL|j|jkWStk rdYdSXdSr|)r}rrurycached has_locationrr)r"othersmslr r r__eq__ls     zModuleSpec.__eq__cCs:|jdkr4|jdk r4|jr4tdkr&tt|j|_|jSr)rryr~_bootstrap_externalNotImplementedError _get_cachedr4r r rrxs  zModuleSpec.cachedcCs ||_dSr)r)r"rr r rrscCs$|jdkr|jddS|jSdS)z The name of the module's parent.N.r)r}r rpartitionr4r r rparents zModuleSpec.parentcCs|jSr)r~r4r r rrszModuleSpec.has_locationcCst||_dSr)boolr~)r"valuer r rrs) rrrrr#r5rpropertyrsetterrrr r r rrx1s $       rxryr{cCst|drJtdkrttj}|dkr0|||dS|r8gnd}||||dS|dkrt|drz||}Wqtk rd}YqXnd}t||||dS)z5Return a module spec based on various loader methods. get_filenameN)ru)rur}r{Fr)rrrspec_from_file_locationr{rWrx)rruryr{rsearchr r rrcs$     rccCs8z |j}Wntk rYnX|dk r,|S|j}|dkrZz |j}Wntk rXYnXz |j}Wntk r|d}YnX|dkr|dkrz |j}Wqtk rd}YqXn|}z |j}Wntk rd}YnXzt|j}Wntk rd}YnXt |||d}|dkr"dnd|_ ||_ ||_ |S)NryFT) rqrrrrjrt_ORIGIN __cached__list__path__rxr~rr})rhruryrgrlocationrr}r r r_spec_from_modulesH         rFoverridecCs|st|dddkr6z |j|_Wntk r4YnX|sJt|dddkr|j}|dkr|jdk rtdkrnttj}| |}|j|_ ||_d|_ z ||_ Wntk rYnX|st|dddkrz |j |_Wntk rYnXz ||_Wntk rYnX|s"t|dddkrR|jdk rRz |j|_Wntk rPYnX|jr|srt|dddkrz |j|_ Wntk rYnX|st|dddkr|jdk rz |j|_Wntk rYnX|S)Nrrj __package__rrtr)rrrrrrur}rr_NamespaceLoader__new___pathrtrjrrrqrrryrr)rgrhrrurr r r_init_module_attrss`            rcCsRd}t|jdr|j|}nt|jdr2td|dkrDt|j}t|||S)z+Create a module based on the provided spec.N create_module exec_modulezBloaders that define exec_module() must also define create_module())rrurrWrrrrgrhr r rmodule_from_spec%s    rcCsj|jdkrdn|j}|jdkrB|jdkr2d|Sd||jSn$|jrVd||jSd|j|jSdS)z&Return the repr to use for the module.Nrlrmrnro)rryrur2r)rgrr r rrs6s   rsc Cs|j}t|tj||k r6d|}t||dzj|jdkrj|j dkrZtd|jdt ||ddn4t ||ddt |jds|j |n |j |W5tj|j}|tj|j<XW5QRX|S)zFExecute the spec's specified module in an existing module's namespace.zmodule {!r} not in sys.modulesrNmissing loaderTrr)rr7rrdr&r2rWpoprur}rr load_moduler)rgrhrmsgr r rreGs"      recCsz|j|jWn4|jtjkr@tj|j}|tj|j<YnXtj|j}|tj|j<t|dddkrz |j|_Wntk rYnXt|dddkrz(|j |_ t |ds|j dd|_ Wntk rYnXt|dddkrz ||_ Wntk rYnX|S)Nrjrrrrrq)rurrrrdrrrjrrrrrrrqrr r r_load_backward_compatiblees6      rc Cs|jdk rt|jdst|St|}d|_z|tj|j<z4|jdkr`|jdkrlt d|jdn |j |Wn2ztj|j=Wnt k rYnXYnXtj |j}|tj|j<t d|j|jW5d|_X|S)NrTFrrzimport {!r} # {!r})rurrr _initializingrrdrr}rWrrErrTrr r r_load_unlockeds.      rc Cs*t|jt|W5QRSQRXdS)zReturn a new module object, loaded by the spec's loader. The module is not added to its parent. If a module is already in sys.modules, that existing module gets clobbered. N)r7rr)rgr r rrfs rfc@seZdZdZeddZedddZedddZed d Z ed d Z ee d dZ ee ddZ ee ddZeeZdS)BuiltinImporterzMeta path import for built-in modules. All methods are either class or static methods to avoid the need to instantiate the class. cCs d|jS)sReturn repr for the module. The method is deprecated. The import machinery does the job itself. z)r2r)rhr r rrkszBuiltinImporter.module_reprNcCs,|dk r dSt|r$t||ddSdSdS)Nzbuilt-inr)r? is_builtinrcclsrYpathtargetr r r find_specs  zBuiltinImporter.find_speccCs|||}|dk r|jSdS)zFind the built-in module. If 'path' is ever specified then the search is considered a failure. This method is deprecated. Use find_spec() instead. N)rru)rrYrrgr r r find_modules zBuiltinImporter.find_modulecCs.|jtjkr"td|j|jdttj|S)zCreate a built-in modulerUr)rrrVrWr2rJr?create_builtin)r"rgr r rrs   zBuiltinImporter.create_modulecCsttj|dS)zExec a built-in moduleN)rJr? exec_builtin)r"rhr r rrszBuiltinImporter.exec_modulecCsdS)z9Return None as built-in modules do not have code objects.Nr rrYr r rget_codeszBuiltinImporter.get_codecCsdS)z8Return None as built-in modules do not have source code.Nr rr r r get_sourceszBuiltinImporter.get_sourcecCsdS)z4Return False as built-in modules are never packages.Fr rr r rr{szBuiltinImporter.is_package)NN)N)rrrr staticmethodrk classmethodrrrrr^rrr{rirr r r rrs*        rc@seZdZdZdZeddZedddZeddd Z ed d Z ed d Z eddZ ee ddZee ddZee ddZdS)FrozenImporterzMeta path import for frozen modules. All methods are either class or static methods to avoid the need to instantiate the class. frozencCsd|jtjS)rr)r2rrr)mr r rrkszFrozenImporter.module_reprNcCs"t|rt|||jdSdSdS)Nr)r?r`rcrrr r rr s zFrozenImporter.find_speccCst|r|SdS)z]Find a frozen module. This method is deprecated. Use find_spec() instead. N)r?r`)rrYrr r rr'szFrozenImporter.find_modulecCsdS)z*Use default semantics for module creation.Nr )rrgr r rr0szFrozenImporter.create_modulecCs@|jj}t|s$td||dttj|}t||j dSr_) rqrr?r`rWr2rJget_frozen_objectexecr)rhrcoder r rr4s   zFrozenImporter.exec_modulecCs t||S)z_Load a frozen module. This method is deprecated. Use exec_module() instead. )rirr r rr=szFrozenImporter.load_modulecCs t|S)z-Return the code object for the frozen module.)r?rrr r rrFszFrozenImporter.get_codecCsdS)z6Return None as frozen modules do not have source code.Nr rr r rrLszFrozenImporter.get_sourcecCs t|S)z.Return True if the frozen module is a package.)r?is_frozen_packagerr r rr{RszFrozenImporter.is_package)NN)N)rrrrrrrkrrrrrrrbrrr{r r r rr s.        rc@s eZdZdZddZddZdS)_ImportLockContextz$Context manager for the import lock.cCs tdS)zAcquire the import lock.N)r?r@r4r r rr;_sz_ImportLockContext.__enter__cCs tdS)zcsz_ImportLockContext.__exit__N)rrrrr;r>r r r rr[srcCs@|d|d}t||kr$td|d}|r= 0z__package__ not set to a stringz6attempted relative import with no known parent packagezEmpty module nameN) isinstancestr TypeErrorr2rrrWrrrr r r _sanity_checks    rzNo module named z{!r}cCsd}|dd}|r|tjkr*t|||tjkr>tj|Stj|}z |j}Wn2tk rtd||}t||ddYnXt ||}|dkrtt||dnt |}|rtj|}t ||dd||S)Nrrz; {!r} is not a packager) rrrdrJrrr_ERR_MSGr2ModuleNotFoundErrorrrr)rimport_rr parent_modulerrgrhr r r_find_and_load_unlockeds*        rc Csjt|2tj|t}|tkr6t||W5QRSW5QRX|dkr^d|}t||dt||S)zFind and load the module.Nz(import of {} halted; None in sys.modulesr) r7rrdr&_NEEDS_LOADINGrr2rrG)rrrhrSr r r_find_and_loads   rrcCs*t||||dkr t|||}t|tS)a2Import and return the module based on its name, the package the call is being made from, and the level adjustment. This function represents the greatest common denominator of functionality between import_module and __import__. This includes setting __package__ if the loader did not. r)rrr _gcd_importrr r rrs  r recursivec Cs|D]}t|tsB|r"|jd}nd}td|dt|jq|dkrl|st|drt||j|ddqt||sd |j|}zt ||Wqt k r}z*|j |krt j |td k rWYqW5d }~XYqXq|S) zFigure out what __import__ should return. The import_ parameter is a callable which takes the name of module to import. It is required to decouple the function from assuming importlib's import implementation is desired. z.__all__z ``from list''zItem in z must be str, not *__all__TrrN)rrrrrr_handle_fromlistrr2rJrrrrdr&r)rhfromlistrrxwhere from_nameexcr r rrs,      rcCs|d}|d}|dk rR|dk rN||jkrNtjd|d|jdtdd|S|dk r`|jStjd tdd|d }d |kr|d d }|S)zCalculate what __package__ should be. __package__ is not guaranteed to be defined or could be set to None to represent that its proper value is unknown. rrqNz __package__ != __spec__.parent (z != )) stacklevelzYcan't resolve package from __spec__ or __package__, falling back on __name__ and __path__rrrr)r&rrrrr)globalsrrgr r r_calc___package__s&  rr c Cs|dkrt|}n$|dk r|ni}t|}t|||}|s|dkrTt|ddS|s\|St|t|dd}tj|jdt|j|Snt|drt||tS|SdS)aImport a module. The 'globals' argument is used to infer where the import is occurring from to handle relative imports. The 'locals' argument is ignored. The 'fromlist' argument specifies what should exist as attributes on the module being imported (e.g. ``from module import ``). The 'level' argument represents the package location to import from in a relative import (e.g. ``from ..pkg import mod`` would have a 'level' of 2). rNrr) rr partitionrrrdrrr) rrlocalsrrrhglobals_rcut_offr r r __import__9s      rcCs&t|}|dkrtd|t|S)Nzno built-in module named )rrrWr)rrgr r r_builtin_from_name^s  rc Cs|a|att}tjD]H\}}t||r|tjkrs^D%   $e -H%*IO   / % %#