[Neo-report] r1810 vincent - /trunk/neo/client/Storage.py

nobody at svn.erp5.org nobody at svn.erp5.org
Mon Feb 22 10:34:06 CET 2010


Author: vincent
Date: Mon Feb 22 10:34:06 2010
New Revision: 1810

Log:
Factorize code checking for read-only status.

Modified:
    trunk/neo/client/Storage.py

Modified: trunk/neo/client/Storage.py
==============================================================================
--- trunk/neo/client/Storage.py [iso-8859-1] (original)
+++ trunk/neo/client/Storage.py [iso-8859-1] Mon Feb 22 10:34:06 2010
@@ -20,6 +20,13 @@
 from neo.client.app import Application
 from neo.client.exception import NEOStorageNotFoundError
 
+def check_read_only(func):
+    def wrapped(self, *args, **kw):
+        if self._is_read_only:
+            raise POSException.ReadOnlyError()
+        return func(self, *args, **kw)
+    return wrapped
+
 class Storage(BaseStorage.BaseStorage,
               ConflictResolution.ConflictResolvingStorage):
     """Wrapper class for neoclient."""
@@ -38,34 +45,29 @@
         except NEOStorageNotFoundError:
             raise POSException.POSKeyError(oid)
 
+    @check_read_only
     def new_oid(self):
-        if self._is_read_only:
-            raise POSException.ReadOnlyError()
         return self.app.new_oid()
 
+    @check_read_only
     def tpc_begin(self, transaction, tid=None, status=' '):
-        if self._is_read_only:
-            raise POSException.ReadOnlyError()
         return self.app.tpc_begin(transaction=transaction, tid=tid,
                 status=status)
 
+    @check_read_only
     def tpc_vote(self, transaction):
-        if self._is_read_only:
-            raise POSException.ReadOnlyError()
         return self.app.tpc_vote(transaction=transaction,
             tryToResolveConflict=self.tryToResolveConflict)
 
+    @check_read_only
     def tpc_abort(self, transaction):
-        if self._is_read_only:
-            raise POSException.ReadOnlyError()
         return self.app.tpc_abort(transaction=transaction)
 
     def tpc_finish(self, transaction, f=None):
         return self.app.tpc_finish(transaction=transaction, f=f)
 
+    @check_read_only
     def store(self, oid, serial, data, version, transaction):
-        if self._is_read_only:
-            raise POSException.ReadOnlyError()
         return self.app.store(oid=oid, serial=serial,
             data=data, version=version, transaction=transaction,
             tryToResolveConflict=self.tryToResolveConflict)
@@ -93,16 +95,14 @@
         return self.app.iterator(start, stop)
 
     # undo
+    @check_read_only
     def undo(self, transaction_id, txn):
-        if self._is_read_only:
-            raise POSException.ReadOnlyError()
         return self.app.undo(transaction_id=transaction_id, txn=txn,
             tryToResolveConflict=self.tryToResolveConflict)
 
 
+    @check_read_only
     def undoLog(self, first, last, filter=None):
-        if self._is_read_only:
-            raise POSException.ReadOnlyError()
         return self.app.undoLog(first, last, filter)
 
     def supportsUndo(self):





More information about the Neo-report mailing list