Your IP : 172.28.240.42


Current Path : /usr/lib/python2.7/dist-packages/twisted/persisted/
Upload File :
Current File : //usr/lib/python2.7/dist-packages/twisted/persisted/dirdbm.pyc


[XMc@sdZddlZddlZddlZddlZyddlZWnek
reddlZnXyeWne	k
re
ZnXdfdYZdefdYZe
e
dZ
dddgZdS(	s
DBM-style interface to a directory.

Each key is stored as a single file.  This is not expected to be very fast or
efficient, but it's good for easy debugging.

DirDBMs are *not* thread-safe, they should only be accessed by one thread at
a time.

No files should be placed in the working directory of a DirDBM save those
created by the DirDBM itself!

Maintainer: Itamar Shtull-Trauring
iNtDirDBMcBseZdZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZ
dZd
ZdZddZdZdZdZdZdZdZRS(sA directory with a DBM interface.
    
    This class presents a hash-like interface to a directory of small,
    flat files. It can only use strings as keys or values.
    cCstjj||_tjj|js=tj|jnx6tjtjj|jdD]}tj|q_Wtjtjj|jd}xJ|D]B}|d }tjj	|rtj|qtj
||qWdS(sb
        @type name: str
        @param name: Base path to use for the directory storage.
        s*.news*.rpliN(tostpathtabspathtdnametisdirtmkdirtglobtjointremovetexiststrename(tselftnametftreplacementstold((s</usr/lib/python2.7/dist-packages/twisted/persisted/dirdbm.pyt__init__/s
(!

cCs%tj|jddjddS(s6Encode a key so it can be used as a filename.
        s
t_t/t-(tbase64tencodestringtreplace(Rtk((s</usr/lib/python2.7/dist-packages/twisted/persisted/dirdbm.pyt_encodeJscCs%tj|jddjddS(s*Decode a filename to get the key.
        Rs
RR(RtdecodestringR(RR((s</usr/lib/python2.7/dist-packages/twisted/persisted/dirdbm.pyt_decodePscCs)t|d}|j}|j|S(sRead in the contents of a file.
        
        Override in subclasses to e.g. provide transparently encrypted dirdbm.
        trb(t_opentreadtclose(RRRts((s</usr/lib/python2.7/dist-packages/twisted/persisted/dirdbm.pyt	_readFileUs
cCs4t|d}|j||j|jdS(svWrite data to a file.
        
        Override in subclasses to e.g. provide transparently encrypted dirdbm.
        twbN(RtwritetflushR(RRtdataR((s</usr/lib/python2.7/dist-packages/twisted/persisted/dirdbm.pyt
_writeFile_s

cCsttj|jS(sF
        @return: The number of key/value pairs in this Shelf
        (tlenRtlistdirR(R((s</usr/lib/python2.7/dist-packages/twisted/persisted/dirdbm.pyt__len__iscCst|tjks!tdt|tjksBtd|j|}tjj|j|}tjj	|r|d}n
|d}y|j
||Wntj|n3Xtjj	|rtj|ntj||dS(s
        C{dirdbm[k] = v}
        Create or modify a textfile in this directory

        @type k: str
        @param k: key to set
        
        @type v: str
        @param v: value to associate with C{k}
        sDirDBM key must be a stringsDirDBM value must be a strings.rpls.newN(
ttypettypest
StringTypetAssertionErrorRRRRRR
R&R	R(RRtvRtnew((s</usr/lib/python2.7/dist-packages/twisted/persisted/dirdbm.pyt__setitem__os!!


cCsjt|tjks!tdtjj|j|j|}y|j	|SWnt
|nXdS(s
        C{dirdbm[k]}
        Get the contents of a file in this directory as a string.
        
        @type k: str
        @param k: key to lookup
        
        @return: The value associated with C{k}
        @raise KeyError: Raised when there is no such key
        sDirDBM key must be a stringN(R*R+R,R-RRRRRR!tKeyError(RRR((s</usr/lib/python2.7/dist-packages/twisted/persisted/dirdbm.pyt__getitem__s!!cCst|tjks!td|j|}y#tjtjj|j	|Wn,t
tfk
rt|j
|nXdS(s
        C{del dirdbm[foo]}
        Delete a file in this directory.
        
        @type k: str
        @param k: key to delete
        
        @raise KeyError: Raised when there is no such key
        sDirDBM key must be a stringN(R*R+R,R-RRR	RRRtOSErrortIOErrorR1R(RR((s</usr/lib/python2.7/dist-packages/twisted/persisted/dirdbm.pyt__delitem__s
!#cCst|jtj|jS(s9
        @return: a C{list} of filenames (keys).
        (tmapRRR(R(R((s</usr/lib/python2.7/dist-packages/twisted/persisted/dirdbm.pytkeysscCs8g}|j}x|D]}|j||qW|S(s?
        @return: a C{list} of file-contents (values).
        (R7tappend(RtvalsR7tkey((s</usr/lib/python2.7/dist-packages/twisted/persisted/dirdbm.pytvaluess

cCs>g}|j}x%|D]}|j|||fqW|S(sL
        @return: a C{list} of 2-tuples containing key/value pairs.
        (R7R8(RtitemsR7R:((s</usr/lib/python2.7/dist-packages/twisted/persisted/dirdbm.pyR<s

cCsRt|tjks!td|j|}tjjtjj|j	|S(s
        @type key: str
        @param key: The key to test
        
        @return: A true value if this dirdbm has the specified key, a faluse
        value otherwise.
        sDirDBM key must be a string(
R*R+R,R-RRRtisfileRR(RR:((s</usr/lib/python2.7/dist-packages/twisted/persisted/dirdbm.pythas_keys!cCs%|j|s|||<|S||S(s
        @type key: str
        @param key: The key to lookup
        
        @param value: The value to associate with key if key is not already
        associated with a value.
        (R>(RR:tvalue((s</usr/lib/python2.7/dist-packages/twisted/persisted/dirdbm.pyt
setdefaults
cCs|j|r||S|SdS(s
        @type key: str
        @param key: The key to lookup
        
        @param default: The value to return if the given key does not exist
        
        @return: The value associated with C{key} or C{default} if not
        C{self.has_key(key)}
        N(R>(RR:tdefault((s</usr/lib/python2.7/dist-packages/twisted/persisted/dirdbm.pytgets
cCsRt|tjks!td|j|}tjjtjj|j	|S(s
        C{key in dirdbm}

        @type key: str
        @param key: The key to test
                
        @return: A true value if C{self.has_key(key)}, a false value otherwise.
        sDirDBM key must be a string(
R*R+R,R-RRRR=RR(RR:((s</usr/lib/python2.7/dist-packages/twisted/persisted/dirdbm.pyt__contains__s	!cCs+x$|jD]\}}|||<q
WdS(s
        Add all the key/value pairs in C{dict} to this dirdbm.  Any conflicting
        keys will be overwritten with the values from C{dict}.

        @type dict: mapping
        @param dict: A mapping of key/value pairs to add to this dirdbm.
        N(R<(RtdictR:tval((s</usr/lib/python2.7/dist-packages/twisted/persisted/dirdbm.pytupdatescCsitjj|}||jks't|j|}|jx"|jD]}||||<qMW|S(sL
        Copy the contents of this dirdbm to the dirdbm at C{path}.
        
        @type path: C{str}
        @param path: The path of the dirdbm to copy to.  If a dirdbm
        exists at the destination path, it is cleared first.
        
        @rtype: C{DirDBM}
        @return: The dirdbm this dirdbm was copied to.
        (RRRRR-t	__class__tclearR7(RRtdR((s</usr/lib/python2.7/dist-packages/twisted/persisted/dirdbm.pytcopyTo	s
cCs"x|jD]
}||=q
WdS(s<
        Delete all key/value pairs in this dirdbm.
        N(R7(RR((s</usr/lib/python2.7/dist-packages/twisted/persisted/dirdbm.pyRHscCsdS(sL
        Close this dbm: no-op, for dbm-style interface compliance.
        N((R((s</usr/lib/python2.7/dist-packages/twisted/persisted/dirdbm.pyR$scCsqt|tjks!tdtjj|j|j|}tjj	|rdtjj
|St|dS(s
        Returns modification time of an entry.
        
        @return: Last modification date (seconds since epoch) of entry C{key}
        @raise KeyError: Raised when there is no such key
        sDirDBM key must be a stringN(R*R+R,R-RRRRRR=tgetmtimeR1(RR:R((s</usr/lib/python2.7/dist-packages/twisted/persisted/dirdbm.pytgetModificationTime)s
!!N(t__name__t
__module__t__doc__RRRR!R&R)R0R2R5R7R;R<R>R@tNoneRBRCRFRJRHRRL(((s</usr/lib/python2.7/dist-packages/twisted/persisted/dirdbm.pyR(s,				
	
						
	
		
	
				tShelfcBs eZdZdZdZRS(sA directory with a DBM shelf interface.
    
    This class presents a hash-like interface to a directory of small,
    flat files. Keys must be strings, but values can be any given object.
    cCs&tj|}tj|||dS(s
        C{shelf[foo] = bar}
        Create or modify a textfile in this directory.

        @type k: str
        @param k: The key to set

        @param v: The value to associate with C{key}
        N(tpickletdumpsRR0(RRR.((s</usr/lib/python2.7/dist-packages/twisted/persisted/dirdbm.pyR0?s
cCstjtj||S(s'
        C{dirdbm[foo]}
        Get and unpickle the contents of a file in this directory.
        
        @type k: str
        @param k: The key to lookup
        
        @return: The value associated with the given key
        @raise KeyError: Raised if the given key does not exist
        (RRtloadsRR2(RR((s</usr/lib/python2.7/dist-packages/twisted/persisted/dirdbm.pyR2Ls(RMRNROR0R2(((s</usr/lib/python2.7/dist-packages/twisted/persisted/dirdbm.pyRQ8s	
cCs
t|S(s
    This is for 'anydbm' compatibility.
    
    @param file: The parameter to pass to the DirDBM constructor.

    @param flag: ignored
    @param mode: ignored
    (R(tfiletflagtmode((s</usr/lib/python2.7/dist-packages/twisted/persisted/dirdbm.pytopenZs	RX(RORR+RRtcPickleRRtImportErrorRt	NameErrorRXRRQRPt__all__(((s</usr/lib/python2.7/dist-packages/twisted/persisted/dirdbm.pyt<module>s"


"