Commit 96def86d authored by Hanno Schlichting's avatar Hanno Schlichting

Use `storage._lock` as a context manager, also PEP8/cleanup.

parent 125359ad
......@@ -4,6 +4,8 @@ Changelog
3.1 - unreleased
----------------
- Use `storage._lock` as a context manager.
- Declare PyPy compatibility.
3.0 - 2016-04-03
......
......@@ -129,8 +129,7 @@ class TemporaryStorage(BaseStorage, ConflictResolvingStorage):
"""
def load(self, oid, version=''):
self._lock_acquire()
try:
with self._lock:
try:
s = self._index[oid]
p = self._opickle[oid]
......@@ -148,8 +147,6 @@ class TemporaryStorage(BaseStorage, ConflictResolvingStorage):
raise POSException.ConflictError(oid=oid)
else:
raise
finally:
self._lock_release()
# Apparently loadEx is required to use this as a ZEO storage for
# ZODB 3.3. The tests don't make it totally clear what it's meant
......@@ -170,8 +167,7 @@ class TemporaryStorage(BaseStorage, ConflictResolvingStorage):
It does not actually implement all the semantics that a revisioning
storage needs!
"""
self._lock_acquire()
try:
with self._lock:
data = self._conflict_cache.get((oid, serial), marker)
if data is marker:
# XXX Need 2 serialnos to pass them to ConflictError--
......@@ -179,8 +175,6 @@ class TemporaryStorage(BaseStorage, ConflictResolvingStorage):
raise POSException.ConflictError(oid=oid)
else:
return data[0] # data here is actually (data, t)
finally:
self._lock_release()
def loadBefore(self, oid, tid):
""" Return most recent revision of oid before tid committed.
......@@ -188,13 +182,12 @@ class TemporaryStorage(BaseStorage, ConflictResolvingStorage):
Needed for MVCC.
"""
# implementation stolen from ZODB.test_storage.MinimalMemoryStorage
self._lock_acquire()
try:
with self._lock:
tids = [stid for soid, stid in self._conflict_cache if soid == oid]
if not tids:
raise KeyError(oid)
tids.sort()
i = bisect.bisect_left(tids, tid) -1
i = bisect.bisect_left(tids, tid) - 1
if i == -1:
return None
start_tid = tids[i]
......@@ -205,16 +198,13 @@ class TemporaryStorage(BaseStorage, ConflictResolvingStorage):
end_tid = tids[j]
data = self.loadSerial(oid, start_tid)
return data, start_tid, end_tid
finally:
self._lock_release()
def store(self, oid, serial, data, version, transaction):
if transaction is not self._transaction:
raise POSException.StorageTransactionError(self, transaction)
assert not version
self._lock_acquire()
try:
with self._lock:
if oid in self._index:
oserial = self._index[oid]
if serial != oserial:
......@@ -232,8 +222,6 @@ class TemporaryStorage(BaseStorage, ConflictResolvingStorage):
newserial = self._tid
self._tmp.append((oid, data))
return serial == oserial and newserial or ResolvedSerial
finally:
self._lock_release()
def _finish(self, tid, u, d, e):
zeros = {}
......@@ -259,7 +247,6 @@ class TemporaryStorage(BaseStorage, ConflictResolvingStorage):
# doesn't already exist
if referenceCount_get(oid) is None:
referenceCount[oid] = 0
#zeros[oid]=1
# update references that are already associated with this
# object
......@@ -276,7 +263,7 @@ class TemporaryStorage(BaseStorage, ConflictResolvingStorage):
oreferences[oid].remove(roid)
# decrement refcnt:
rc = referenceCount_get(roid, 1)
rc = rc-1
rc = rc - 1
if rc < 0:
# This should never happen
raise ReferenceCountError(
......@@ -357,7 +344,6 @@ class TemporaryStorage(BaseStorage, ConflictResolvingStorage):
(ReferenceCountError.__doc__, roid, rc))
else:
# DM 2005-01-07: decremented *before* the test! see above
#referenceCount[roid] = rc - 1
referenceCount[roid] = rc
try:
del self._oreferences[oid]
......@@ -365,8 +351,7 @@ class TemporaryStorage(BaseStorage, ConflictResolvingStorage):
pass
def pack(self, t, referencesf):
self._lock_acquire()
try:
with self._lock:
rindex = {}
rootl = ['\0\0\0\0\0\0\0\0']
......@@ -381,7 +366,5 @@ class TemporaryStorage(BaseStorage, ConflictResolvingStorage):
# sweep unreferenced objects
for oid in self._index.keys():
if not oid in rindex:
if oid not in rindex:
self._takeOutGarbage(oid)
finally:
self._lock_release()
......@@ -25,8 +25,7 @@ class ZODBProtocolTests(StorageTestBase.StorageTestBase,
BasicStorage.BasicStorage,
Synchronization.SynchronizedStorage,
ConflictResolution.ConflictResolvingStorage,
MTStorage.MTStorage,
):
MTStorage.MTStorage):
def setUp(self):
StorageTestBase.StorageTestBase.setUp(self)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment