o ]Lb+@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|WStyB|sd|}|ddd}|ddddd}||kr4|||g|Ri|YSw)Nzhgext_%s.rr__name__) ImportErrorsplitget) importfuncnameglobalsargskwargs hgextnamenameroot contextrootr@/usr/lib/python3/dist-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__cC|jd|dS)z%add to the list of submodules to loadN)rappendrr rrr_extendMsz_demandmod._extendcCr#)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 sB|jstd|jd|j\}}}}}}tt|||d|}||ur=|j}|r,||us4Jd||f WddSfdd|D]}||qE|rj|||ur[|||<n||d|urj|||d<|D]} tj| d} | rt | |d|urt | ||qlt |d|WddS1swYdSdS)Nzdemandimport %srz%s, %sc sn|d}}d|vr|dd\}}t||ttur)t||t||j|jdddS|r5t|||dSdSNrrr)r getattrnothingsetattrr__dict__)modphtsubloadrrr6us z!_demandmod._load..subloadr1r) rrlogrr _origimportr sysmodulesr-r/rr) rrr rr!rmodrefsr1xmodnamemodrefrr5r_load\s6       "z_demandmod._loadcCs"|jr d|jdSd|jdS)Nzrz)rrrrrr__repr__sz_demandmod.__repr__cOstdt|)Nz%s object is not callable) TypeErrorrepr)rrrrrr__call__sz_demandmod.__call__cCs|t|j|SN)r?r-r)rattrrrr __getattr__s z_demandmod.__getattr__cCs|t|j||dSrE)r?r/r)rrFvalrrrrsz_demandmod.__setattr__cC||jjSrE)r?rr0r@rrrr0z_demandmod.__dict__cCrIrE)r?r__doc__r@rrrrKrJz_demandmod.__doc__N)r __module__ __qualname__rKr"r'r*r?rArDrGrpropertyr0rrrrr:s  8 r__pypy__c sdus |tvs |dkrtt||||S|sRd|vrK|dd\}}|r5|dd|kr5t||||S|vrKt|trG|||St|||S|dfdd}dd}|d kr|rwtt|||d } || |} n;tr} t j | } t | d t t ur| ddd } t j | } |dkr| d|dd } t j | } n tt|||d } |D]} || | q| Stt||} || |} |D]} || | q| S) N)*rrrcst||t}t|dttu}|tur5|rdSd|j|f}|tvr$t}nt}|||jdd}t|||rCt|trE| dSdSdS)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.rignoresr8rr0r/ isinstancer*)r1rFsymbolnonpkgmnr  globalnamerrrprocessfromitems  z&_demandimport..processfromitemcSs|}|dddD]3}t||t}|tur(t||j|jdd}t|||n|jd|tjvr.chainmodulesrr,rR)rSrr8r r rTrr'_pypyr9r:r-r.rsplit) r r rfromlistrbaser rZr^r[r1rWr<rrXr _demandimportsT          rccCs|adSrE)rS) ignoresetrrrinit(srecCs tjtkSrE)builtins __import__rcrrrr isenabled-s rhcC tt_dS)z'enable global demand-loading of modulesN)rcrfrgrrrrenable1 rjcCri)z(disable global demand-loading of modulesN)r8rfrgrrrrdisable6rkrlccs<t}|r tz dVW|rtdSdS|rtww)z;context manager for disabling demandimport in 'with' blocksN)rhrlrj) demandenabledrrr deactivated;s rn)NNNrP)rK __future__r __builtin__rf contextlibr9rrcontextmanagerrgr8rr.rrbuiltin_module_namesr_rcrrSrerhrjrlrnrrrrs(   u s