[r7423]: sandbox / transactions / transaction.py Maximize Restore History

Download this file

transaction.py    26 lines (23 with data), 912 Bytes

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
class TransactionMiddleware(object):
def __init__(self, app, start, commit, rollback, style='REST'):
self.app = app
self.start = start
self.commit = commit
self.rollback = rollback
self.style = style
def REST_handler(self, environ, start_response):
if environ['REQUEST_METHOD'] != 'GET':
if environ['REQUEST_METHOD'] != 'HEAD':
try:
self.start()
result = self.app(environ, start_response)
self.commit()
return result
except:
self.rollback()
raise
else:
return self.app(environ, start_response)
def __call__(self, environ, start_response):
handler = getattr(self, self.style + '_handler')
return handler(environ, start_response)