Ticket #10771: contextmanager-v3.patch

File contextmanager-v3.patch, 1007 bytes (added by Oliver Beattie, 16 years ago)

Python 2.3 compatibility

  • db/transaction.py

     
    265265            leave_transaction_management()
    266266
    267267    return wraps(func)(_commit_manually)
     268
     269####################
     270# CONTEXT MANAGERS #
     271####################
     272class Transaction(object):
     273    def __enter__(cls):
     274        enter_transaction_management()
     275        managed(True)
     276    __enter__ = classmethod(__enter__)
     277   
     278    def __exit__(cls, exc_type, value, traceback):
     279        try:
     280            if exc_type is None:
     281                # Nested block executed successfully
     282                if is_dirty():
     283                    commit()
     284            else:
     285                # Some exception was raised
     286                if is_dirty():
     287                    rollback()
     288                return False # re-raises the exception
     289        finally:
     290            leave_transaction_management()
     291    __exit__ = classmethod(__exit__)
Back to Top