Created
February 19, 2014 17:15
Revisions
-
florentx created this gist
Feb 19, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,18 @@ import re # Helper to check if the name is a valid identifier _isidentifier = re.compile(r'[a-zA-Z_]\w*').match @contextlib.contextmanager def savepoint(cr, name, quiet=False): assert _isidentifier(name) cr.execute('SAVEPOINT "%s";' % name) try: yield except Exception: cr.execute('ROLLBACK TO "%s";' % name) if not quiet: raise finally: cr.execute('RELEASE "%s";' % name)