mò ‹ã¸Ec@s@dZeZdklZdklZdklZdk l Z dk l Z l Z dk lZlZdkZdkZd„Zd „Zeieeƒeeƒd efd „ƒYZd efd „ƒYZdZd„Zd„Zdefd„ƒYZdfd„ƒYZdefd„ƒYZdefd„ƒYZdS(sPersistent Module.(s implements(s Persistent(sGHOST(sIPersistentModuleManager(sIPersistentModuleImportRegistrysIPersistentModuleUpdateRegistry(s NameFindersconvertNcCst|iffS(N(t_unpickle_moduletmodt__name__(R((t./data/zmath/zope/lib/python/zodbcode/module.pyt_pickle_module"scCsTt|ƒ}d|jo7|idƒd}x!|D]}t||ƒ}q3Wn|S(Nt.i(t __import__tmodnameRtsplittpartstparttgetattr(RR R R((RR%s  tPersistentModulecBs,tZd„Zd„Zd„Zd„ZRS(NcCs ||_dS(N(tnametselfR(RR ((Rt__init__@scCsd|ii|ifS(Ns<%s %s>(Rt __class__R(R((Rt__repr__CscCs4|iiƒ}y |d=Wntj onX|S(Nt __builtins__(Rt__dict__tcopytdtKeyError(RR((Rt __getstate__Js  cCst|d<|ii|ƒdS(NR(t __builtin__tstateRRtupdate(RR((Rt __setstate__Rs (Rt __module__RRRR(((RR >s   tPersistentPackagecBstZd„ZRS(NcCs ||_dS(N(R RR(RR ((RR]s(RRR(((RRVst__persistent_module_registry__cCs t|ƒ}|i||ƒ|S(s3Return a manager object for a newly created module.N(tPersistentModuleManagertregistrytmgrtnewR tsource(R R R#R!((Rt newModulebs cBs‰|o|ddjo|d7}ne|_|i}e|ƒ}||e <||U|e =e|ƒ}|i |ƒ}e ||ƒdS(Niÿÿÿÿs ( R#tTruetmodulet _p_changedRtmoddictt NameFindert old_namesR Rt new_namest replacementstconvert(R&R R#R+R,R*R(((Rt compileModuleis     RcBsHtZeeƒd„Zd„Zd„Zd„Zd„Zd„Z RS(NcCs(||_d|_d|_d|_dS(N(R Rt _registrytNonet_moduleR R#(RR ((RR}s   cCs|idj otdƒ‚nd|jo|i|ƒ}nd}t|ƒ|_y|ii ||iƒWntj od|_‚nX||_y|i |ƒWn|ii |ƒ‚nX|dj o*|i dƒd}t|||iƒndS(s0Return a new module from a name and source text.smodule already existsRiÿÿÿÿN(RR1R0t ValueErrorR t _new_packagetparentR R/t setModuleRR#t delModuleRRtsetattr(RR R#R4R((RR"ƒs*    cCs#t|i|i|ƒ||_dS(N(R.RR1R/R#(RR#((RR›scCs#|ii|iiƒd|_dS(N(RR/R6R1RR0(R((Rtremove¡scCsW|i|ƒ}|idƒd}|djo||_dSnt|ƒ|_|SdS(NRiÿÿÿÿR( Rt _get_parentR R4RRR1R0R (RR RR4((RR3¥s  cCs|idƒd }d}xãtt|ƒƒD]Ï}||djotdƒ‚ndi ||d ƒ}|i i |ƒ}|djoHt|ƒ}|i i||ƒ|dj ot||||ƒqõn%t|tƒptd|ƒ‚n|}q,W|S(NRiÿÿÿÿRs__init__ can not be a packageis %s is module(R RR R0R4trangetlentiR2tjointpnameRR/t findModuletpackageRR5R7t isinstance(RR R4R@R<R R>((RR9¯s"    ( RRt implementstIPersistentModuleManagerRR"RR8R3R9(((RRys      tPersistentModuleImportercBsStZdZeZd„Zd„Zd„Zd„Zhhgd„Z d„Z RS(sbAn import hook that loads persistent modules. The importer cooperates with other objects to make sure imports of persistent modules work correctly. The default importer depends on finding a persistent module registry in the globals passed to __import__(). It looks for the name __persistent_module_registry__. A PersistentModuleManager places its registry in the globals used to exec module source. It is important that the registry be activated before it is used to handle imports. If a ghost registry is used for importing, a circular import occurs. The second import occurs when the machinery searches for the class of the registry. It will re-use the registry and fail, because the registry will be marked as changed but not yet have its state loaded. XXX There ought to be a way to deal with this. cCs<|idj otdƒ‚nti|_|it_dS(NsAlready installed!(Rt _saved_importR0t TypeErrorRR(R((Rtinstallßs cCs9|idjotdƒ‚n|it_d|_dS(NsNot installed!(RRER0RFRR(R((Rt uninstallås c Cs3d}|dj o:d||f}|i|ƒ}|djo d}qMn|djo|i|ƒ}n|djodSn|o/t|t ƒo|i |||ƒn|Snx|i dƒ}|djo|Sn|| }|od||f}n|i|ƒ}|dj ptd|‚|SdS(Ns%s.%sRiÿÿÿÿsNo package for module %s(R0RR4R tfullnameR R?tfromlistRARRt_import_fromlisttfindR<ttoptAssertionError( RR R R4RJR<RIRMR((Rt_importës.      cCsRxK|D]C}t||ƒp-d|i|f}|i||dgƒqqWdS(Ns%s.%s( RJR thasattrRRRIRROR R0(RR RRJR RI((RRKs cCsl|itƒ}|dj o:|i|||i|ƒ|ƒ}|dj o|SqVn|i ||||ƒS(N( tglobalstgetRR R0RROR R9RJRREtlocals(RR RQRSRJR R((RR s    cCsH|idƒ}|djp d|jodSn|idƒ}|| S(NRR(RQRRR R0trfindR<(RRQR<R ((RR9s ( RRt__doc__R0RERGRHRORKRR9(((RRDÃs       tPersistentModuleRegistrycBsHtZdZeeeƒd„Zd„Zd„Zd„Z d„Z RS(sÎA collection of persistent modules. The registry is similar in purpose to sys.modules. A persistent module manager stores its modules in a registry, and the importer looks for them there. cCs h|_dS(N(Rt_modules(R((RR&scCs'|idj pt‚|ii|ƒS(N(RR'R0RNRWRRR (RR ((RR?)scCs:||ijot|ƒ‚nt|_||i|