+
    Dfj1)                        R t ^ RIHt ^ RIt^ RIt^ RIt^ RIt^ RIHtH	t	H
t
HtHt ^ RIHt ]! RRR7      t ! R R4      t ! R	 R
]4      tRR lt. ROtR# )aw  
A L{DirDBM} is a L{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.

L{DirDBM}s 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!
)annotationsN)AnyStrIterableMappingTypeVaroverload)FilePath_T)boundc                  F   ] tR t^ tRtR R ltR R ltR R ltR R	 ltR
 R lt	R R lt
R R ltR R ltR R ltR R ltR R ltR R ltR R ltR R lt]R R l4       t]R  R! l4       tR2R# R$ lltR% R& ltR' R( ltR) R* ltR+ R, ltR- R. ltR/ R0 ltR1tR"# )3DirDBMz
A 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.
c                    V ^8  d   QhRRRR/# )   namebytesreturnNone )formats   ":/usr/lib/python3/dist-packages/twisted/persisted/dirdbm.py__annotate__DirDBM.__annotate__(   s     & &U &t &    c                   \         P                  P                  V4      V n        \	        V4      V n        V P
                  P                  4       '       g   V P
                  P                  4        R# \        P                  ! V P
                  P                  R4      P                  4       F  p\         P                  ! V4       K  	  \        P                  ! V P
                  P                  R4      P                  4      pV F[  pVRR p\         P                  P                  V4      '       d   \         P                  ! V4       KE  \         P                  ! W$4       K]  	  R# )z:
@param name: Base path to use for the directory storage.
z*.newz*.rplN)ospathabspathdnamer   
_dnamePathisdircreateDirectoryglobchildremoveexistsrename)selfr   freplacementsolds   &&   r   __init__DirDBM.__init__(   s     WW__T*
"4.$$&&OO++- YYt44W=BBC		! D99T__%:%:7%C%H%HIL!f77>>#&&IIaLIIa% "r   c                    V ^8  d   QhRRRR/# r   kr   r   r   )r   s   "r   r   r   C   s     N N N5 Nr   c                n    \         P                  ! V4      P                  RR4      P                  RR4      # )z/
Encode a key so it can be used as a filename.
   
   _   /   -)base64encodebytesreplacer'   r/   s   &&r   _encodeDirDBM._encodeC   s/    
 !!!$,,UD9AA$MMr   c                    V ^8  d   QhRRRR/# r.   r   )r   s   "r   r   r   J   s     N N N5 Nr   c                n    \         P                  ! VP                  RR4      P                  RR4      4      # )z#
Decode a filename to get the key.
r2   r1   r4   r3   )r5   decodebytesr7   r8   s   &&r   _decodeDirDBM._decodeJ   s-     !!!))D%"8"@"@t"LMMr   c                    V ^8  d   QhRRRR/# )r   r   FilePath[AnyStr]r   r   r   )r   s   "r   r   r   P   s      . 5 r   c                    VP                  4       ;_uu_ 4       pVP                  4       pRRR4       V#   + '       g   i     X# ; i)zi
Read in the contents of a file.

Override in subclasses to e.g. provide transparently encrypted dirdbm.
N)openread)r'   r   r(   ss   &&  r   	_readFileDirDBM._readFileP   s3     YY[[AA  [s	   4A	c               $    V ^8  d   QhRRRRRR/# )r   r   rA   datar   r   r   r   )r   s   "r   r   r   Z   s"      / u  r   c                    VP                  R4      ;_uu_ 4       pVP                  V4       VP                  4        RRR4       R#   + '       g   i     R# ; i)z_
Write data to a file.

Override in subclasses to e.g. provide transparently encrypted dirdbm.
wN)rC   writeflush)r'   r   rI   r(   s   &&& r   
_writeFileDirDBM._writeFileZ   s3     YYs^^qGGDMGGI ^^^s   "AA	c                   V ^8  d   QhRR/# )r   r   intr   )r   s   "r   r   r   d   s     . . .r   c                H    \        V P                  P                  4       4      # )z6
@return: The number of key/value pairs in this Shelf
)lenr   listdirr'   s   &r   __len__DirDBM.__len__d   s     4??**,--r   c               $    V ^8  d   QhRRRRRR/# )r   r/   r   vr   r   r   )r   s   "r   r   r   j   s!        U  u    r   c                   \        V4      \        8X  g   \        R4      h\        V4      \        8X  g   \        R4      hV P                  V4      pV P                  P                  V4      pVP                  4       '       d   VP                  R4      pMVP                  R4      p V P                  WB4       VP                  4       '       d   VP                  4        VP                  V4       R#   \         d    TP                  4        h i ; i)z
C{dirdbm[k] = v}
Create or modify a textfile in this directory

@type k: bytes
@param k: key to set

@type v: bytes
@param v: value to associate with C{k}
DirDBM key must be byteszDirDBM value must be bytesz.rplz.newN)typer   	TypeErrorr9   r   r#   r%   siblingExtensionrN   r$   moveToBaseException)r'   r/   rY   r*   news   &&&  r   __setitem__DirDBM.__setitem__j   s     Aw%677Aw%899LLO oo##A&::<<&&v.C&&v.C	OOC#
 zz||

JJsO  	JJL	s   %C/ /Dc                    V ^8  d   QhRRRR/# r.   r   )r   s   "r   r   r      s      U u r   c                    \        V4      \        8X  g   \        R4      hV P                  P	                  V P                  V4      4      p V P                  V4      #   \         d    \        T4      hi ; i)z
C{dirdbm[k]} Get the contents of a file in this directory as a string.

@param k: key to lookup

@return: The value associated with C{k}

@raise KeyError: Raised when there is no such key
r[   )	r\   r   r]   r   r#   r9   rF   OSErrorKeyError)r'   r/   r   s   && r   __getitem__DirDBM.__getitem__   se     Aw%677$$T\\!_5	>>$'' 	1+	s   A A3c                    V ^8  d   QhRRRR/# )r   r/   r   r   r   r   )r   s   "r   r   r      s     , ,U ,t ,r   c                   \        V4      \        8X  g   \        R4      hV P                  V4      p V P                  P                  V4      P                  4        R#   \         d    \        T P                  T4      4      hi ; i)z
C{del dirdbm[foo]}
Delete a file in this directory.

@type k: bytes
@param k: key to delete

@raise KeyError: Raised when there is no such key
r[   N)
r\   r   r]   r9   r   r#   r$   rf   rg   r>   r8   s   &&r   __delitem__DirDBM.__delitem__   sk     Aw%677LLO	,OO!!!$++- 	,4<<?++	,s   )A &Bc                   V ^8  d   QhRR/# r   r   zIterable[bytes]r   )r   s   "r   r   r      s     P Po Pr   c                    \        \        V P                  V P                  P	                  4       P                  4       4      4      # )z)
@return: a L{list} of filenames (keys).
)listmapr>   r   asBytesModerT   rU   s   &r   keysDirDBM.keys   s0     Cdoo&A&A&C&K&K&MNOOr   c                   V ^8  d   QhRR/# ro   r   )r   s   "r   r   r      s       r   c                j    . pV P                  4       pV F  pVP                  W,          4       K  	  V# )z/
@return: a L{list} of file-contents (values).
rt   append)r'   valsrt   keys   &   r   valuesDirDBM.values   s1     yy{CKK	" r   c                   V ^8  d   QhRR/# )r   r   zIterable[tuple[bytes, bytes]]r   )r   s   "r   r   r      s      4 r   c                n    . pV P                  4       pV F  pVP                  W0V,          34       K  	  V# )z<
@return: a L{list} of 2-tuples containing key/value pairs.
rx   )r'   itemsrt   r{   s   &   r   r   DirDBM.items   s6     yy{CLL#Cy)* r   c                    V ^8  d   QhRRRR/# r   r{   r   r   boolr   )r   s   "r   r   r      s     3 35 3T 3r   c                    \        V4      \        8X  g   \        R4      hV P                  V4      pV P                  P                  V4      P                  4       # )z
@type key: bytes
@param key: The key to test

@return: A true value if this dirdbm has the specified key, a false
value otherwise.
r[   )r\   r   r]   r9   r   r#   isfiler'   r{   s   &&r   has_keyDirDBM.has_key   sH     CyE!677ll3$$S)0022r   c               $    V ^8  d   QhRRRRRR/# )r   r{   r   valuer   r   )r   s   "r   r   r      s!      e E e r   c                *    W9  d   W V&   V# W,          # )z
@type key: bytes
@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{   r   s   &&&r   
setdefaultDirDBM.setdefault   s     ?ILyr   c                    V ^8  d   QhRRRR/# )r   r{   r   r   r   )r   s   "r   r   r      s      u  r   c                	    R # Nr   r   s   &&r   get
DirDBM.get       r   c               $    V ^8  d   QhRRRRRR/# )r   r{   r   defaultr	   r   z
bytes | _Tr   )r   s   "r   r   r      s!      u r j r   c                	    R # r   r   r'   r{   r   s   &&&r   r   r      r   r   Nc               $    V ^8  d   QhRRRRRR/# )r   r{   r   r   z	_T | Noner   zbytes | _T | Noner   )r   s   "r   r   r      s"      u y <M r   c                "    W9   d	   W,          # V# )z
@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
    L{DirDBM.has_key(key)}
r   r   s   &&&r   r   r      s     ;9Nr   c                    V ^8  d   QhRRRR/# r   r   )r   s   "r   r   r      s     ! ! !$ !r   c                $    V P                  V4      # )z
@see: L{DirDBM.has_key}
)r   r   s   &&r   __contains__DirDBM.__contains__   s     ||C  r   c                    V ^8  d   QhRRRR/# )r   otherzMapping[bytes, bytes]r   r   r   )r   s   "r   r   r      s      1 d r   c                @    VP                  4        F	  w  r#W0V&   K  	  R# )z
Add all the key/value pairs in L{dict} to this dirdbm.  Any conflicting
keys will be overwritten with the values from L{dict}.

@param dict: A mapping of key/value pairs to add to this dirdbm.
N)r   )r'   r   r{   vals   &&  r   updateDirDBM.update   s     HCI &r   c                    V ^8  d   QhRRRR/# )r   r   r   r   r   r   )r   s   "r   r   r   
  s      5 V r   c                    \        V4      pW P                  8w  g   Q hV P                  VP                  4      pVP	                  4        V P                  4        F  pW,          W4&   K  	  V# )z
Copy the contents of this dirdbm to the dirdbm at C{path}.

@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.
)r   r   	__class__r   clearrt   )r'   r   fpathdr/   s   &&   r   copyToDirDBM.copyTo
  sV     '''NN5::&		A7AD r   c                   V ^8  d   QhRR/# r   r   r   r   )r   s   "r   r   r     s      t r   c                8    V P                  4        F  pW K  	  R# )z,
Delete all key/value pairs in this dirdbm.
N)rt   r8   s   & r   r   DirDBM.clear  s     A r   c                   V ^8  d   QhRR/# r   r   )r   s   "r   r   r   $  s      t r   c                    R# )z<
Close this dbm: no-op, for dbm-style interface compliance.
Nr   rU   s   &r   closeDirDBM.close$  s    r   c                    V ^8  d   QhRRRR/# )r   r{   r   r   floatr   )r   s   "r   r   r   )  s        u    r   c                    \        V4      \        8X  g   \        R4      hV P                  P	                  V P                  V4      4      pVP                  4       '       d   VP                  4       # \        V4      h)z
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
r[   )	r\   r   r]   r   r#   r9   r   getModificationTimerg   )r'   r{   r   s   && r   r   DirDBM.getModificationTime)  s]     CyE!677$$T\\#%67;;==++--3-r   )r   r   r   )__name__
__module____qualname____firstlineno____doc__r+   r9   r>   rF   rN   rV   rb   rh   rl   rt   r|   r   r   r   r   r   r   r   r   r   r   r   __static_attributes__r   r   r   r   r       s    &6NN. D$,$P3    !&
   r   r   c                  &    ] tR tRtRtR tR tRtR# )Shelfi9  z
A 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.
c                ^    \         P                  ! V4      p\        P                  WV4       R# )z
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)pickledumpsr   rb   )r'   r/   rY   s   &&&r   rb   Shelf.__setitem__A  s!     LLO4A&r   c                T    \         P                  ! \        P                  W4      4      # )z
C{dirdbm[foo]}
Get and unpickle the contents of a file in this directory.

@type k: bytes
@param k: The key to lookup

@return: The value associated with the given key
@raise KeyError: Raised if the given key does not exist
)r   loadsr   rh   r8   s   &&r   rh   Shelf.__getitem__N  s     ||F..t788r   r   N)r   r   r   r   r   rb   rh   r   r   r   r   r   r   9  s    '9r   r   c                    \        V 4      # )z
This is for 'anydbm' compatibility.

@param file: The parameter to pass to the DirDBM constructor.

@param flag: ignored
@param mode: ignored
)r   )fileflagmodes   &&&r   rC   rC   \  s     $<r   )NN)rC   r   r   )r   
__future__r   r5   r"   r   r   typingr   r   r   r   r   twisted.python.filepathr   r	   r   r   rC   __all__r   r   r   <module>r      sV    #   	  ? ? ,TV  V r 9F  9F	 &r   