a +b+@sdZddlmZddlZddlZddlZddlmZej Z e Z e Z ddZGdd d e Zd ejvZdd d ZeaddZddZddZddZe ddZdS)aU demandimport - automatic demandloading of modules To enable this module, do: import demandimport; demandimport.enable() Imports of the following forms will be demand-loaded: import a, b.c import a.b as c from a import b,c # a will be loaded immediately These imports will not be delayed: from a import * b = __import__(a) )absolute_importN)tracingcOsz|||g|Ri|WSty|s.d|}|ddd}|ddddd}||krh|||g|Ri|YS0dS)Nzhgext_%s.rr__name__) ImportErrorsplitget) importfuncnameglobalsargskwargsZ hgextnameZnamerootZ contextrootrD/usr/lib64/python3.9/site-packages/hgdemandimport/demandimportpy2.py _hgextimport*s rc@sheZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ e ddZ e ddZdS) _demandmodzxmodule demand-loader and proxy Specify 1 as 'level' argument at construction, to import module relatively. c CsVd|vr |dd\}}|g}n|}g}t|d|||||tft|dddS)Nrr_data_module)r object __setattr__set)selfr r localslevelheadrestafterrrr__init__Asz_demandmod.__init__cCs|jd|dS)z%add to the list of submodules to loadN)rappendrr rrr_extendMsz_demandmod._extendcCs|jd|dS)aRecord that the named module ``name`` imports this module. References to this proxy class having the name of this module will be replaced at module load time. We assume the symbol inside the importing module is identical to the "head" name of this module. We don't actually know if "as X" syntax is being used to change the symbol name because this information isn't exposed to __import__. N)raddr"rrr_addrefQs z_demandmod._addrefc s@|js.subloadr-r) rrlogrr _origimportr sysmodulesr)r+rr) rrr rrrZmodrefsr-xmodnameZmodrefrr1r_load\s.      z_demandmod._loadcCs"|jrd|jdSd|jdS)Nzrz)rrrrrr__repr__sz_demandmod.__repr__cOstdt|dS)Nz%s object is not callable) TypeErrorrepr)rrrrrr__call__sz_demandmod.__call__cCs|t|j|SN)r9r)r)rattrrrr __getattr__sz_demandmod.__getattr__cCs|t|j||dSr?)r9r+r)rr@valrrrrsz_demandmod.__setattr__cCs||jjSr?)r9rr,r:rrrr,sz_demandmod.__dict__cCs||jjSr?)r9r__doc__r:rrrrCsz_demandmod.__doc__N)r __module__ __qualname__rCrr#r&r9r;r>rArpropertyr,rrrrr:s  8 rZ__pypy__c sdus|tvs|dkr*tt||||S|sd|vr|dd\}}|rj|dd|krjt||||S|vrt|tr|||St|||S|dfdd}dd}|d kr|rtt|||d } || |} n|trZ} t j | } t | d t t ur0| ddd } t j | } |dkrl| d|dd } t j | } ntt|||d } |D]} || | qp| Stt||} || |} |D]} || | q| SdS) N)*rrrcst||t}t|dttu}|turj|r,dSd|j|f}|tvrHt}nt}|||jdd}t|||rt|tr| dS)aProcess an imported symbol in the import statement. If the symbol doesn't exist in the parent module, and if the parent module is a package, it must be a module. We set missing modules up as _demandmod instances. __path__Nz%s.%srr() r)r*rignoresr4rr,r+ isinstancer&)r-r@symbolZnonpkgmnr Z globalnamerrrprocessfromitems  z&_demandimport..processfromitemcSs|}|dddD]f}t||t}|turPt||j|jdd}t|||n(|jd|tjvrxtj|jd|}|}q|Sr') r r)r*rr,r+rr5r6)rootmodr8r-compobjrrr chainmoduless z#_demandimport..chainmodulesrr(rI)rJrr4r r rKrr#_pypyr5r6r)r*rsplit) r r rfromlistrbaserrOrSrPr-rMr7rrNr _demandimportsR          rXcCs|adSr?)rJ)Z ignoresetrrrinit(srYcCs tjtkSr?)builtins __import__rXrrrr isenabled-sr\cCs tt_dS)z'enable global demand-loading of modulesN)rXrZr[rrrrenable1sr]cCs tt_dS)z(disable global demand-loading of modulesN)r4rZr[rrrrdisable6sr^ccs6t}|rtzdVW|r2tn |r0t0dS)z;context manager for disabling demandimport in 'with' blocksN)r\r^r])Z demandenabledrrr deactivated;sr_)NNNrG)rCZ __future__rZ __builtin__rZ contextlibr5rrcontextmanagerr[r4rr*rrbuiltin_module_namesrTrXrrJrYr\r]r^r_rrrrs&  u  s