/usr/share/pyshared/ZODB/dbmStorage.py is in python-zodb 1:3.9.7-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | ##############################################################################
#
# Copyright (c) 2001, 2002 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################
"""Very Simple dbm-based ZODB storage
This storage provides for use of dbm files as storages that
don't support versions or Undo. This may be useful when implementing
objects like hit counters that don't need or want to participate
in undo or versions.
"""
from ZODB.utils import z64
from MappingStorage import MappingStorage
from BaseStorage import BaseStorage
import anydbm, os
class anydbmStorage(MappingStorage):
def __init__(self, filename, flag='r', mode=0666):
BaseStorage.__init__(self, filename)
self._index=anydbm.open(filename, flag, mode)
self._tindex=[]
keys=self._index.keys()
if keys: self._oid=max(keys)
def getSize(self):
# This is a little iffy, since we aren't entirely sure what the file is
self._lock_acquire()
try:
try:
return (os.stat(self.__name__+'.data')[6] +
os.stat(self.__name__+'.dir')[6]
)
except:
try: return os.stat(self.__name__)[6]
except: return 0
finally: self._lock_release()
class gdbmStorage(anydbmStorage):
def __init__(self, filename, flag='r', mode=0666):
BaseStorage.__init__(self, filename)
import gdbm
self._index=index=gdbm.open(filename, flag[:1]+'f', mode)
self._tindex=[]
m=z64
oid=index.firstkey()
while oid != None:
m=max(m, oid)
oid=index.nextkey(oid)
self._oid=m
def getSize(self):
self._lock_acquire()
try: return os.stat(self.__name__)[6]
finally: self._lock_release()
def pack(self, t, referencesf):
self._lock_acquire()
try:
# Build an index of *only* those objects reachable
# from the root.
index=self._index
rootl=[z64]
pop=rootl.pop
pindex={}
referenced=pindex.has_key
while rootl:
oid=pop()
if referenced(oid): continue
# Scan non-version pickle for references
r=index[oid]
pindex[oid]=r
p=r[8:]
referencesf(p, rootl)
# Now delete any unreferenced entries:
deleted=[]
oid=index.firstkey()
while oid != None:
if not referenced(oid): deleted.append(oid)
oid=index.nextkey(oid)
pindex=referenced=None
for oid in deleted: del index[oid]
index.sync()
index.reorganize()
finally: self._lock_release()
def _finish(self, tid, user, desc, ext):
index=self._index
for oid, p in self._tindex: index[oid]=p
index.sync()
|