~allenap/storm/blocked-references

« back to all changes in this revision

Viewing changes to storm/database.py

  • Committer: Gavin Panella
  • Date: 2011-05-04 14:44:18 UTC
  • Revision ID: gavin@gromper.net-20110504144418-y946anf33vyf80g2
Make it possible to block Reference gets that hit the database.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
supported in modules in L{storm.databases}.
26
26
"""
27
27
 
 
28
from contextlib import contextmanager
 
29
 
28
30
from storm.expr import Expr, State, compile
29
31
from storm.tracer import trace
30
32
from storm.variables import Variable
204
206
        """Unblock access to the connection."""
205
207
        self._blocked = False
206
208
 
 
209
    @contextmanager
 
210
    def blocked(self):
 
211
        old_blocked = self._blocked
 
212
        try:
 
213
            self._blocked = True
 
214
            yield
 
215
        finally:
 
216
            self._blocked = old_blocked
 
217
 
 
218
    @contextmanager
 
219
    def unblocked(self):
 
220
        old_blocked = self._blocked
 
221
        try:
 
222
            self._blocked = False
 
223
            yield
 
224
        finally:
 
225
            self._blocked = old_blocked
 
226
 
207
227
    def execute(self, statement, params=None, noresult=False):
208
228
        """Execute a statement with the given parameters.
209
229