a %0_@sdZddlmZddlZddlZddlZddlmZda ej dddkZ Gd d d ej j ZGd d d eZead dZddZddZddZejddZdS)aLazy loading for Python 3.6 and above. This uses the new importlib finder/loader functionality available in Python 3.5 and up. The code reuses most of the mechanics implemented inside importlib.util, but with a few additions: * Allow excluding certain modules from lazy imports. * Expose an interface that's substantially the same as demandimport for Python 2. This also has some limitations compared to the Python 2 implementation: * Much of the logic is per-package, not per-module, so any packages loaded before demandimport is enabled will not be lazily imported in the future. In practice, we only expect builtins to be loaded before demandimport is enabled. )absolute_importN)tracingF)cs eZdZdZfddZZS) _lazyloaderexzaThis is a LazyLoader except it also follows the _deactivated global and the ignore list. csXtd|8ts|jtvr*|j|n t|Wdn1sJ0YdS)zMake the module load lazily.zdemandimport %sN)rlog _deactivated__name__ignoresloader exec_modulesuper)selfmodule __class__@/usr/lib/python3/dist-packages/hgdemandimport/demandimportpy3.pyr1sz_lazyloaderex.exec_module)r __module__ __qualname____doc__r __classcell__rrrrr,src@sReZdZdZdZddZddZddZeZd d Z d d Z d dZ dddZ dS) LazyFindera2A wrapper around a ``MetaPathFinder`` that makes loaders lazy. ``sys.meta_path`` finders have their ``find_spec()`` called to locate a module. This returns a ``ModuleSpec`` if found or ``None``. The ``ModuleSpec`` has a ``loader`` attribute, which is called to actually load a module. Our class wraps an existing finder and overloads its ``find_spec()`` to replace the ``loader`` with our lazy loader proxy. We have to use __getattribute__ to proxy the instance because some meta path finders don't support monkeypatching. )_findercCst|d|dSNr)object __setattr__)rfinderrrr__init__KszLazyFinder.__init__cCsdt|dS)Nzr)r__getattribute__rrrr__repr__NszLazyFinder.__repr__cCstt|dSr)boolrr!r"rrr __nonzero__SszLazyFinder.__nonzero__cCs&|dvrt||Stt|d|S)N)r find_specr)rr!getattrrnamerrrr!Xs zLazyFinder.__getattribute__cCstt|dSr)delattrrr!r(rrr __delattr__^szLazyFinder.__delattr__cCstt|d||Sr)setattrrr!)rr)valuerrrraszLazyFinder.__setattr__NcCst|d}z |j}Wn:tyP|||}|dur>d}ntj||}Yn0||||}|dur|jdurt |jddrt |j|_|S)Nrr) rr!r&AttributeError find_module importlibutilspec_from_loaderr r'r)rfullnamepathtargetrr&r specrrrr&ds"       zLazyFinder.find_spec)N) r rrr __slots__r r#r%__bool__r!r+rr&rrrrr:srcCs|adSN)r )Z ignoresetrrrinitsr:cCst otddtjDS)Ncss|]}t|tVqdSr9) isinstancer).0rrrr szisenabled..)r anysys meta_pathrrrr isenabledsrAcCs<g}tjD]}|t|tr"|jn|q |tjdd<dSr9)r?r@appendr;rrZ new_findersrrrrdisables  rDcCsFtsdSg}tjD] }|t|ts,t|n|q|tjdd<dSr9) _supportedr?r@rBr;rrCrrrenables rFccs0t}|rdazdVW|r,dan |r*da0dS)NTF)rAr )Z demandenabledrrr deactivatedsrG)rZ __future__r contextlibimportlib.utilr0r?rr version_inforEr1 LazyLoaderrrrsetr r:rArDrFcontextmanagerrGrrrrs   B