[Zope-Checkins] CVS: Zope3/lib/python/ZODB - DB.py:1.47
Jeremy Hylton
jeremy@zope.com
Tue, 16 Jul 2002 19:24:08 -0400
Update of /cvs-repository/Zope3/lib/python/ZODB
In directory cvs.zope.org:/tmp/cvs-serv17269/ZODB
Modified Files:
DB.py
Log Message:
Cleanup some code.
Add newlines all over,
and use nested scopes instead of default args.
=== Zope3/lib/python/ZODB/DB.py 1.46 => 1.47 ===
Organized by class."""
- detail={}
- def f(con,detail=detail,have_detail=detail.has_key):
+ detail = {}
+ def f(con):
for oid, ob in con._cache.items():
module = getattr(ob.__class__, '__module__', '')
module = module and '%s.' % module or ''
- c="%s%s" % (module, ob.__class__.__name__)
- if have_detail(c): detail[c]=detail[c]+1
- else: detail[c]=1
+ c = "%s%s" % (module, ob.__class__.__name__)
+ detail[c] = detail.get(c, 0) + 1
self._connectionMap(f)
- detail=detail.items()
+ detail = detail.items()
detail.sort()
return detail
def cacheExtremeDetail(self):
- detail=[]
+ detail = []
conn_no = [0] # A mutable reference to a counter
- def f(con, detail=detail, rc=sys.getrefcount, conn_no=conn_no):
+ def f(con, rc=sys.getrefcount, conn_no=conn_no):
conn_no[0] = conn_no[0] + 1
cn = conn_no[0]
for oid, ob in con._cache.items():
- id=''
- if hasattr(ob,'__dict__'):
- d=ob.__dict__
- if d.has_key('id'):
- id=d['id']
- elif d.has_key('__name__'):
- id=d['__name__']
+ id = ''
+ if hasattr(ob, '__dict__'):
+ d = ob.__dict__
+ id = d.get("id", "")
+ if id is None:
+ id = d.get("__name__", "")
module = getattr(ob.__class__, '__module__', '')
module = module and '%s.' % module or ''
@@ -196,36 +194,38 @@
return detail
def cacheFullSweep(self, value):
- # XXX Persistence.Cache doesn't expect an argument
-## self._connectionMap(lambda c: c._cache.full_sweep(value))
self._connectionMap(lambda c: c._cache.full_sweep())
def cacheLastGCTime(self):
- m=[0]
- def f(con, m=m):
- t=con._cache.cache_last_gc_time
- if t > m[0]: m[0]=t
-
+ L = []
+ def f(con):
+ L.append(con._cache.cache_last_gc_time)
+
self._connectionMap(f)
- return m[0]
+ return max(L)
def cacheMinimize(self, value):
- # XXX Persistence.Cache doesn't expect an argument
self._connectionMap(lambda c, v=value: c._cache.minimize())
- def cacheMeanAge(self): return self._cacheMean('cache_mean_age')
- def cacheMeanDeac(self): return self._cacheMean('cache_mean_deac')
- def cacheMeanDeal(self): return self._cacheMean('cache_mean_deal')
+ def cacheMeanAge(self):
+ return self._cacheMean('cache_mean_age')
+
+ def cacheMeanDeac(self):
+ return self._cacheMean('cache_mean_deac')
+
+ def cacheMeanDeal(self):
+ return self._cacheMean('cache_mean_deal')
def cacheSize(self):
- m=[0]
- def f(con, m=m):
- m[0]=m[0]+len(con._cache)
+ L = []
+ def f(con):
+ L.append(len(con._cache))
self._connectionMap(f)
- return m[0]
+ return reduce(int.__add__, L)
- def close(self): self._storage.close()
+ def close(self):
+ self._storage.close()
def commitVersion(self, source, destination=''):
CommitVersion(self, source, destination)
@@ -233,20 +233,29 @@
def exportFile(self, oid, file=None):
raise 'Not yet implemented'
- def getCacheDeactivateAfter(self): return self._cache_deactivate_after
- def getCacheSize(self): return self._cache_size
+ def getCacheDeactivateAfter(self):
+ return self._cache_deactivate_after
+
+ def getCacheSize(self):
+ return self._cache_size
- def getName(self): return self._storage.getName()
+ def getName(self):
+ return self._storage.getName()
- def getPoolSize(self): return self._pool_size
+ def getPoolSize(self):
+ return self._pool_size
- def getSize(self): return self._storage.getSize()
+ def getSize(self):
+ return self._storage.getSize()
def getVersionCacheDeactivateAfter(self):
return self._version_cache_deactivate_after
- def getVersionCacheSize(self): return self._version_cache_size
+
+ def getVersionCacheSize(self):
+ return self._version_cache_size
- def getVersionPoolSize(self): return self._version_pool_size
+ def getVersionPoolSize(self):
+ return self._version_pool_size
def importFile(self, file):
raise 'Not yet implemented'
@@ -352,12 +361,12 @@
if transaction is not None:
connections=transaction._connections
if connections:
- if connections.has_key(version) and not temporary:
- return connections[version]
+ v = connections.get(version)
+ if not (v is None or temporary):
+ v
else:
- transaction._connections=connections={}
- transaction=transaction._connections
-
+ transaction._connections = connections = {}
+ transaction = transaction._connections
if temporary:
# This is a temporary connection.
@@ -402,11 +411,9 @@
if pools.has_key(version):
pool, allocated, pool_lock = pools[version]
else:
- pool, allocated, pool_lock = pools[version] = (
- [], [], Lock())
+ pool, allocated, pool_lock = pools[version] = ([], [], Lock())
pooll.append((pool, allocated))
pool_lock.acquire()
-
if not pool:
c=None