new undo_modification context manager on select nodes

authorSylvain Thénault <sylvain.thenault@logilab.fr>
changeset9d0f53bac016
branchstable
phasepublic
hiddenno
parent revision#23ae480e4e43 closes #70264: buggy remove_group_var
child revision#1a9f3c52176b closes #70416: add 'having' list into variable's stinfo and properly update variable graph
files modified by this revision
stmts.py
# HG changeset patch
# User Sylvain Thénault <sylvain.thenault@logilab.fr>
# Date 1309527006 -7200
# Fri Jul 01 15:30:06 2011 +0200
# Branch stable
# Node ID 9d0f53bac0165ce21384aeed1b11e72f0dfee9c1
# Parent 23ae480e4e43ad803b6203b70f35fa01e0ef57e8
new undo_modification context manager on select nodes

diff --git a/stmts.py b/stmts.py
@@ -46,10 +46,17 @@
1      for vref in varrefs:
2          if not refs.has_key(id(vref)):
3              raise AssertionError('vref %r is not referenced (%r)' % (vref, vref.stmt))
4      return True
5 
6 +class undo_modification(object):
7 +    def __init__(self, select):
8 +        self.select = select
9 +    def __enter__(self):
10 +        self.select.save_state()
11 +    def __exit__(self):
12 +        self.select.recover()
13 
14  class ScopeNode(BaseNode):
15      solutions = ()   # list of possibles solutions for used variables
16      _varmaker = None # variable names generator, built when necessary
17      where = None     # where clause node
@@ -353,10 +360,13 @@
18 
19      @property
20      def should_register_op(self):
21          return self.memorizing and not self.undoing
22 
23 +    def undo_modification(self):
24 +        return undo_modification(self)
25 +
26      def save_state(self):
27          """save the current tree"""
28          self.undo_manager.push_state()
29          self.memorizing += 1
30