Ñò PhEc@s¤ddkZddkZddkZddkZddkZddkZddkTddkl Z ddk Tddk Z dddddd d d d d ddg Z d„Z ddd„ƒYZd dd„ƒYZdefd„ƒYZddd„ƒYZdefd„ƒYZd efd„ƒYZdefd„ƒYZd efd„ƒYZdefd„ƒYZeZeZd efd„ƒYZd efd„ƒYZdS(iÿÿÿÿN(t*(t exceptiontNamespaceContexttContainerContextt ContainertMemoryContainert DBMContainertNamespaceManagertMemoryNamespaceManagertDBMNamespaceManagert FileContainertFileNamespaceManagertCreationAbortedErrortcontainer_registrycCsm|idƒo0|d}d|}tt|ƒi|ƒ}ntit}ti|ƒ|}t||ƒS(Nsext:is myghty.ext.( t startswithtgetattrt __import__texttsystmodulest__name__tstringt capitalize(tnamet classtypetmodnametmodtcname((s4/usr/lib/python2.6/site-packages/myghty/container.pyR s   cBs&eZdZdd„Zdd„ZRS(s-initial context supplied to NamespaceManagerscCs ||_dS(N(tlog_file(tselfR((s4/usr/lib/python2.6/site-packages/myghty/container.pyt__init__%scCsn|idj oZ|dj o&d|ii|i|i|f}nd|i|f}|ii|ƒndS(Ns[%s:%s:%s] %s s[%s] %s (RtNonet __class__Rt namespacetkeytwrite(Rtmessagetnsmt container((s4/usr/lib/python2.6/site-packages/myghty/container.pytdebug(s  &N(Rt __module__t__doc__RRR'(((s4/usr/lib/python2.6/site-packages/myghty/container.pyR"s cBsãeZdZd„Zd„Zd„Zed„Zd„Zd„Z d„Z d„Z d „Z d „Z d „Zd „Zd „Zd„Zd„Zd„Zed„Zd„Zed„Zed„Zd„Zdd„ZRS(sˆhandles dictionary operations and locking for a namespace of values. the implementation for setting and retrieving the namespace data is handled by subclasses. acts as a service for a Container, which stores and retreives a particular key from the namespace, coupled with a "stored time" setting. NamespaceManager may be used alone, or may be privately managed by one or more Container objects. Container objects provide per-key services like automatic expiration and recreation of individual keys and can manange many types of NamespaceManagers for one or more particular namespaces simultaneously. the class supports locking relative to its name. many namespacemanagers within multiple threads or across multiple processes must read/write synchronize their access to the actual dictionary of data referenced by the name. cKs.||_||_d|_tiƒ|_dS(Ni(tcontextR!topenerst _threadingtLocktmutex(RR*R!tparams((s4/usr/lib/python2.6/site-packages/myghty/container.pyRFs   cCs tƒ‚dS(N(tNotImplementedError(R((s4/usr/lib/python2.6/site-packages/myghty/container.pytdo_acquire_read_lockPscCs tƒ‚dS(N(R0(R((s4/usr/lib/python2.6/site-packages/myghty/container.pytdo_release_read_lockQscCs tƒ‚dS(N(R0(Rtwait((s4/usr/lib/python2.6/site-packages/myghty/container.pytdo_acquire_write_lockRscCs tƒ‚dS(N(R0(R((s4/usr/lib/python2.6/site-packages/myghty/container.pytdo_release_write_lockSscCs tƒ‚dS(N(R0(Rtflags((s4/usr/lib/python2.6/site-packages/myghty/container.pytdo_openUscCs tƒ‚dS(N(R0(R((s4/usr/lib/python2.6/site-packages/myghty/container.pytdo_closeVscCs tƒ‚dS(s1removes this namespace from wherever it is storedN(R0(R((s4/usr/lib/python2.6/site-packages/myghty/container.pyt do_removeXscCs |i|ƒS(N(t __contains__(RR"((s4/usr/lib/python2.6/site-packages/myghty/container.pythas_key\scCs tƒ‚dS(N(R0(RR"((s4/usr/lib/python2.6/site-packages/myghty/container.pyt __getitem___scCs tƒ‚dS(N(R0(RR"tvalue((s4/usr/lib/python2.6/site-packages/myghty/container.pyt __setitem__bscCs tƒ‚dS(N(R0(RR"((s4/usr/lib/python2.6/site-packages/myghty/container.pyR:escCs tƒ‚dS(N(R0(RR"((s4/usr/lib/python2.6/site-packages/myghty/container.pyt __delitem__hscCs tƒ‚dS(N(R0(R((s4/usr/lib/python2.6/site-packages/myghty/container.pytkeyskscCs!|iƒ|iddtƒdS(sØacquires a read lock for this namespace, and insures that the datasource has been opened for reading if it is not already opened. acquire/release supports reentrant/nested operation.trt checkcountN(R1topentTrue(R((s4/usr/lib/python2.6/site-packages/myghty/container.pytacquire_read_lockns cCs|idtƒ|iƒdS(såreleases the read lock for this namespace, and possibly closes the datasource, if it was opened as a product of the read lock's acquire/release block. acquire/release supports reentrant/nested operation.RBN(tcloseRDR2(R((s4/usr/lib/python2.6/site-packages/myghty/container.pytrelease_read_lockxscCs8|i|ƒ}|p|o|iddtƒn|S(sÑacquires a write lock for this namespace, and insures that the datasource has been opened for writing if it is not already opened. acquire/release supports reentrant/nested operation.tcRB(R4RCRD(RR3RA((s4/usr/lib/python2.6/site-packages/myghty/container.pytacquire_write_lock‚scCs|idtƒ|iƒdS(sçreleases the write lock for this namespace, and possibly closes the datasource, if it was opened as a product of the write lock's acquire/release block. acquire/release supports reentrant/nested operation.RBN(RFRDR5(R((s4/usr/lib/python2.6/site-packages/myghty/container.pytrelease_write_lockscCsw|iiƒzU|o4|idjo|i|ƒn|id7_n|i|ƒd|_Wd|iiƒXdS(säopens the datasource for this namespace. the checkcount flag indicates an "opened" counter should be checked for zero before performing the open operation, which is incremented by one regardless.iiN(R.tacquireR+R7trelease(RR6RB((s4/usr/lib/python2.6/site-packages/myghty/container.pyRC—s   cCs…|iiƒzc|o1|id8_|idjo|iƒqon(|idjo|iƒnd|_Wd|iiƒXdS(såcloses the datasource for this namespace. the checkcount flag indicates an "opened" counter should be checked for zero before performing the close operation, which is otherwise decremented by one.iiN(R.RKR+R8RL(RRB((s4/usr/lib/python2.6/site-packages/myghty/container.pyRF©s  cCs:|iƒz|idtƒ|iƒWd|iƒXdS(NRB(R4RFtFalseR9R5(R((s4/usr/lib/python2.6/site-packages/myghty/container.pytremove½s  cCs|ii|||ƒdS(N(R*R'(RR$R&((s4/usr/lib/python2.6/site-packages/myghty/container.pyR'ÅsN(RR(R)RR1R2RDR4R5R7R8R9R;R<R>R:R?R@RERGRIRJRMRCRFRNRR'(((s4/usr/lib/python2.6/site-packages/myghty/container.pyR2s.                cBs,eZdZdd„Zd„Zd„ZRS(sïinitial context supplied to Containers. Keeps track of namespacemangers keyed off of namespace names and container types. also keeps namespacemanagers thread local for nsm instances that arent threadsafe (i.e. gdbm) cCsti||ƒh|_dS(N(RRtregistry(RR((s4/usr/lib/python2.6/site-packages/myghty/container.pyRÓscKspttiƒƒd|iid|}y|i|SWn2tj o&|ii||i|||ƒSXdS(Nt|( tstrt_threadt get_identR RROtKeyErrort setdefaultt create_nsm(RR!R&R/R"((s4/usr/lib/python2.6/site-packages/myghty/container.pytget_namespace_manager×s (cKs|id|d||}|S(NR*R!(tdo_create_namespace_manager(RR!R&R/R%((s4/usr/lib/python2.6/site-packages/myghty/container.pyRVàsN(RR(R)RRRWRV(((s4/usr/lib/python2.6/site-packages/myghty/container.pyRÊs  cBsìeZdZdddd„Zd„Zd„Zed„Zd„Z d„Z d„Z d„Z d „Z d „Zd „Zd „Zed „Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„ZRS(slrepresents a value, its stored time, and a value creation function corresponding to a particular key in a particular namespace. handles storage and retrieval of its value via a single NamespaceManager, as well as handling expiration times and an optional creation function that can create or recreate its value when needed. the Container performs locking operations on the NamespaceManager, including a pretty intricate one for get_value with a creation function, so its best not to pass a NamespaceManager that has been externally locked or open, as it stands currently (i hope to improve on this). Managing multiple Containers for a set of keys within a certain namespace allows management of multiple namespace implementations, expiration properties, and thread/process synchronization, on a per-key basis. cKsV||_||_||_||_d|_|i||||_|i|dS(srcreate a container that stores one cached object. createfunc - a function that will create the value. this function is called when value is None or expired. the createfunc call is also synchronized against any other threads or processes calling this cache. expiretime - time in seconds that the item expires. iÿÿÿÿN(R"t createfunct expiretimet starttimet storedtimeRWtnamespacemanagertdo_init(RR"R*R!RYRZR[R/((s4/usr/lib/python2.6/site-packages/myghty/container.pyRøs     cCs|iiƒdS(N(R]RE(R((s4/usr/lib/python2.6/site-packages/myghty/container.pyRE scCs|iiƒdS(N(R]RG(R((s4/usr/lib/python2.6/site-packages/myghty/container.pyRGscCs|ii|ƒS(N(R]RI(RR3((s4/usr/lib/python2.6/site-packages/myghty/container.pyRIscCs|iiƒdS(N(R]RJ(R((s4/usr/lib/python2.6/site-packages/myghty/container.pyRJscCs|ii||ƒdS(N(R]R'(RR$((s4/usr/lib/python2.6/site-packages/myghty/container.pyR'scKs tƒ‚dS(scsubclasses should return a newly created instance of their corresponding NamespaceManager.N(R0(RR*R!R/((s4/usr/lib/python2.6/site-packages/myghty/container.pyRXscKsdS(sYsubclasses can perform general initialization. optional template method.N((RR/((s4/usr/lib/python2.6/site-packages/myghty/container.pyR^scCs|i|iS(sªretrieves the native stored value of this container, regardless of if its expired, or raise KeyError if no value is defined. optionally a template method.(R]R"(R((s4/usr/lib/python2.6/site-packages/myghty/container.pyt do_get_value%scCs||i|iÙs( RRt SynchronizerR!RMtlockRt namespacestgett dictionary(RR*R!R/((s4/usr/lib/python2.6/site-packages/myghty/container.pyRÔscCs|iiƒdS(N(RwRE(R((s4/usr/lib/python2.6/site-packages/myghty/container.pyR1ÛscCs|iiƒdS(N(RwRG(R((s4/usr/lib/python2.6/site-packages/myghty/container.pyR2ÜscCs|ii|ƒS(N(RwRI(RR3((s4/usr/lib/python2.6/site-packages/myghty/container.pyR4ÝscCs|iiƒdS(N(RwRJ(R((s4/usr/lib/python2.6/site-packages/myghty/container.pyR5ÞscOsdS(N((RtargsR/((s4/usr/lib/python2.6/site-packages/myghty/container.pyRCâscOsdS(N((RR{R/((s4/usr/lib/python2.6/site-packages/myghty/container.pyRFãscCs |i|S(N(Rz(RR"((s4/usr/lib/python2.6/site-packages/myghty/container.pyR<åscCs|ii|ƒS(N(RzR:(RR"((s4/usr/lib/python2.6/site-packages/myghty/container.pyR:çscCs|ii|ƒS(N(RzR:(RR"((s4/usr/lib/python2.6/site-packages/myghty/container.pyR;êscCs||i|íscCs|i|=dS(N(Rz(RR"((s4/usr/lib/python2.6/site-packages/myghty/container.pyR?ïscCs|iiƒdS(N(Rztclear(R((s4/usr/lib/python2.6/site-packages/myghty/container.pyR9òscCs |iiƒS(N(RzR@(R((s4/usr/lib/python2.6/site-packages/myghty/container.pyR@õs(RR(tSyncDictR,R-RxRR1R2RDR4R5RCRFR<R:R;R>R?R9R@(((s4/usr/lib/python2.6/site-packages/myghty/container.pyRÑs             cBs/eZd„Zd„Zed„Zd„ZRS(cKs d|_dS(N(Rtfunclock(RR/((s4/usr/lib/python2.6/site-packages/myghty/container.pyR^ûscKst|||S(N(R(RR*R!R/((s4/usr/lib/python2.6/site-packages/myghty/container.pyRXþscCsO|idjo/tdd|ii|ifdtƒ|_n|ii|ƒS(NRssmemorycontainer/funclock/%s/%st reentrant(R~RtNameLockR]R!R"RDRK(RR3((s4/usr/lib/python2.6/site-packages/myghty/container.pyRcs/cCs|iiƒdS(N(R~RL(R((s4/usr/lib/python2.6/site-packages/myghty/container.pyRds(RR(R^RXRDRcRd(((s4/usr/lib/python2.6/site-packages/myghty/container.pyRùs   cBsªeZdddded„Zd„Zd„Zd„Zd„Zd„Z ed„Z d„Z d„Z d „Z d „Zd „Zd „Zd „Zd„Zd„ZRS(c Kslti|||||dj o ||_n%|djo d‚n|d|_|dj o ||_n%|djo d‚n|d|_|djoddk} | |_n ||_t|iƒt|iƒd|_t d|i dt d|id |ƒ|_ t d |id |i gd |d dƒ|_|ii|_|id|iƒ|iƒdS(Nsdata_dir or dbm_dir is requireds/container_dbms data_dir or lock_dir is requireds/container_dbm_lockiÿÿÿÿRsRttlock_dirtdigest_filenamestroott identifierstdigestt extensions.dbms data file %s(RRRtdbm_dirRtanydbmt dbmmoduletverify_directorytdbmRvR!RDRwt EncodedPathtencpathtpathtfileR't _checkfile( RR*R!R‰tdata_dirR‡RR‚R/Rˆ((s4/usr/lib/python2.6/site-packages/myghty/container.pyR s.                 *-cCsVti|tiƒotSx4dD],}ti|ti|tiƒotSq"WtS(Ntdbtdattpagtdir(R’R“R”sdir(tostaccesstF_OKRDtextsepRM(RRR((s4/usr/lib/python2.6/site-packages/myghty/container.pyt file_exists0s! cCs=|i|iƒp&|ii|idƒ}|iƒndS(NRH(RšRR‰RCRF(Rtg((s4/usr/lib/python2.6/site-packages/myghty/container.pyR9scCs‹g}ti|itiƒo|i|iƒnxQdD]I}ti|iti|tiƒo|i|iti|ƒq:q:W|S(NR”R•R’R“(spagsdirsdbsdat(R–R—RR˜tappendR™(RtlistR((s4/usr/lib/python2.6/site-packages/myghty/container.pyt get_filenames>s$#cCs|iiƒdS(N(RwRE(R((s4/usr/lib/python2.6/site-packages/myghty/container.pyR1IscCs|iiƒdS(N(RwRG(R((s4/usr/lib/python2.6/site-packages/myghty/container.pyR2LscCs|ii|ƒS(N(RwRI(RR3((s4/usr/lib/python2.6/site-packages/myghty/container.pyR4OscCs|iiƒdS(N(RwRJ(R((s4/usr/lib/python2.6/site-packages/myghty/container.pyR5RscCss|id|iƒy|ii|i|ƒ|_Wn9|iiƒ|iƒ|ii|i|ƒ|_nXdS(Nsopening dbm file %s(R'RR‰RCR‹RRŠR(RR6((s4/usr/lib/python2.6/site-packages/myghty/container.pyR7Us  cCs9|idj o%|id|iƒ|iiƒndS(Nsclosing dbm file %s(R‹RR'RRF(R((s4/usr/lib/python2.6/site-packages/myghty/container.pyR8dscCs(x!|iƒD]}ti|ƒq WdS(N(RžR–RN(Rtf((s4/usr/lib/python2.6/site-packages/myghty/container.pyR9is cCsti|i|ƒS(N(tcPickletloadsR‹(RR"((s4/usr/lib/python2.6/site-packages/myghty/container.pyR<mscCs|ii|ƒS(N(R‹R;(RR"((s4/usr/lib/python2.6/site-packages/myghty/container.pyR:pscCs ti|tiƒ|i|sscCs|i|=dS(N(R‹(RR"((s4/usr/lib/python2.6/site-packages/myghty/container.pyR?vscCs |iiƒS(N(R‹R@(R((s4/usr/lib/python2.6/site-packages/myghty/container.pyR@ysN(RR(RRDRRšRRžR1R2R4R5R7R8R9R<R:R>R?R@(((s4/usr/lib/python2.6/site-packages/myghty/container.pyR s $            cBs/eZd„Zd„Zed„Zd„ZRS(cKs d|_dS(N(RR~(RR/((s4/usr/lib/python2.6/site-packages/myghty/container.pyR^€scKst|||S(N(R (RR*R!R/((s4/usr/lib/python2.6/site-packages/myghty/container.pyRXƒscCsR|idjo2tdd|iidtd|iiƒ|_n|ii|ƒS(NRssdbmcontainer/funclock/%sRtR(R~RRvR]R!RDRRI(RR3((s4/usr/lib/python2.6/site-packages/myghty/container.pyRc†s2cCs|iiƒdS(N(R~RJ(R((s4/usr/lib/python2.6/site-packages/myghty/container.pyRdŒs(RR(R^RXRDRcRd(((s4/usr/lib/python2.6/site-packages/myghty/container.pyR~s   cBs•eZddded„Zd„Zd„Zd„Zed„Zd„Z d„Z d„Z d„Z d „Z d „Zd „Zd „Zd „ZRS(c Ks'ti|||||dj o ||_n%|djo d‚n|d|_|dj o ||_n%|djo d‚n|d|_t|iƒt|iƒtd|idtd|id|ƒ|_ t d |id |igd |d d ƒi |_ h|_ |id|i ƒdS(Ns data_dir or file_dir is requireds/container_files data_dir or lock_dir is requireds/container_file_lockRsRtRR‚RƒR„R…R†s.caches data file %s(RRRtfile_dirRRŠRvR!RDRwRŒRŽRthashR'(RR*R!R‘R¤RR‚R/((s4/usr/lib/python2.6/site-packages/myghty/container.pyR”s"            *0 cCs#ti|tiƒotStSdS(N(R–R—R˜RDRM(RR((s4/usr/lib/python2.6/site-packages/myghty/container.pyRš®scCs|iiƒdS(N(RwRE(R((s4/usr/lib/python2.6/site-packages/myghty/container.pyR1³scCs|iiƒdS(N(RwRG(R((s4/usr/lib/python2.6/site-packages/myghty/container.pyR2¶scCs|ii|ƒS(N(RwRI(RR3((s4/usr/lib/python2.6/site-packages/myghty/container.pyR4¹scCs|iiƒdS(N(RwRJ(R((s4/usr/lib/python2.6/site-packages/myghty/container.pyR5¼scCsR|i|iƒo2t|idƒ}ti|ƒ|_|iƒn||_dS(NRA(RšRRCR tloadR¥RFR6(RR6tfh((s4/usr/lib/python2.6/site-packages/myghty/container.pyR7¿s cCsv|idj oY|idjp|idjo9t|idƒ}ti|i|tiƒ|iƒnd|_dS(NRHtw( R6RRCRR tdumpR¥R£RF(RR§((s4/usr/lib/python2.6/site-packages/myghty/container.pyR8Æs 0cCsti|iƒh|_dS(N(R–RNRR¥(R((s4/usr/lib/python2.6/site-packages/myghty/container.pyR9ÎscCs |i|S(N(R¥(RR"((s4/usr/lib/python2.6/site-packages/myghty/container.pyR<ÒscCs|ii|ƒS(N(R¥R;(RR"((s4/usr/lib/python2.6/site-packages/myghty/container.pyR:ÕscCs||i|ØscCs|i|=dS(N(R¥(RR"((s4/usr/lib/python2.6/site-packages/myghty/container.pyR?ÛscCs |iiƒS(N(R¥R@(R((s4/usr/lib/python2.6/site-packages/myghty/container.pyR@ÞsN(RR(RRDRRšR1R2R4R5R7R8R9R<R:R>R?R@(((s4/usr/lib/python2.6/site-packages/myghty/container.pyR ’s            cBs/eZd„Zd„Zed„Zd„ZRS(cKs d|_dS(N(RR~(RR/((s4/usr/lib/python2.6/site-packages/myghty/container.pyR^åscKst|||S(N(R (RR*R!R/((s4/usr/lib/python2.6/site-packages/myghty/container.pyRXèscCsR|idjo2tdd|iidtd|iiƒ|_n|ii|ƒS(NRssfilecontainer/funclock/%sRtR(R~RRvR]R!RDRRI(RR3((s4/usr/lib/python2.6/site-packages/myghty/container.pyRcës2cCs|iiƒdS(N(R~RJ(R((s4/usr/lib/python2.6/site-packages/myghty/container.pyRdñs(RR(R^RXRDRcRd(((s4/usr/lib/python2.6/site-packages/myghty/container.pyR ãs   ((((tos.pathR–treRRltweakrefRt myghty.utiltmyghtyRtmyghty.synchronizationR t__all__R RRRRt ExceptionR RRR RtDbmNamespaceManagert DbmContainerR R (((s4/usr/lib/python2.6/site-packages/myghty/container.pyt s*H     ˜á (tQ