diff options
author | ianb <devnull@localhost> | 2006-03-13 03:36:35 +0000 |
---|---|---|
committer | ianb <devnull@localhost> | 2006-03-13 03:36:35 +0000 |
commit | 2f73592d856d62d69ac1787db29f01ca94ccdfdb (patch) | |
tree | 3124b471d329b2cc9bf62b2437188649d5b9d839 /paste/transaction.py | |
parent | dc01a06001c07131c58204650b453ccf07165b57 (diff) | |
download | paste-2f73592d856d62d69ac1787db29f01ca94ccdfdb.tar.gz |
Added a get_cookie_headers function; added a dictionary-like object that dynamically reads headers from the WSGI environment; altered request object to cache a little less (still more to remove); made urlvars a request value
Diffstat (limited to 'paste/transaction.py')
-rw-r--r-- | paste/transaction.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/paste/transaction.py b/paste/transaction.py index 4f3591b..755d101 100644 --- a/paste/transaction.py +++ b/paste/transaction.py @@ -14,6 +14,40 @@ two-phase commit goodness that I don't need. from paste.httpexceptions import HTTPException from wsgilib import catch_errors +class TransactionManagerMiddleware(object): + + def __init__(self, application): + self.application = application + + def __call__(self, environ, start_response): + environ['paste.transaction_manager'] = manager = Manager() + # This makes sure nothing else traps unexpected exceptions: + environ['paste.throw_errors'] = True + return wsgilib.catch_errors(application, environ, start_response, + error_callback=manager.error, + ok_callback=manager.finish) + +class Manager(object): + + def __init__(self): + self.aborted = False + self.transactions = [] + + def abort(self): + self.aborted = True + + def error(self, exc_info): + self.aborted = True + self.finish() + + def finish(self): + for trans in self.transactions: + if self.aborted: + trans.rollback() + else: + trans.commit() + + class ConnectionFactory(object): """ Provides a callable interface for connecting to ADBAPI databases in |