Ticket #10771: contextmanager-v2.patch

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

Second patch with support for <Python 2.5

  • db/transaction.py

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