forked from lega911/sqlmapper
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbase_engine.py
More file actions
44 lines (37 loc) · 1.18 KB
/
base_engine.py
File metadata and controls
44 lines (37 loc) · 1.18 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
class MultiException(Exception):
def __init__(self, e):
super(MultiException, self).__init__()
self.exceptions = e
class BaseEngine(object):
def __init__(self):
if not hasattr(self, 'local'):
self.local = type('local', (object,), {})()
self.thread_init()
def thread_init(self):
if hasattr(self.local, 'tables'):
return
self.local.tables = {}
self.local.commit = []
self.local.rollback = []
def fire_event(self, success):
self.thread_init()
fnlist = self.local.commit if success else self.local.rollback
self.local.commit = []
self.local.rollback = []
exceptions = []
for fn in fnlist:
try:
fn()
except Exception as e:
exceptions.append(e)
if exceptions:
if len(exceptions) == 1:
raise exceptions[0]
else:
raise MultiException(exceptions)
def on_commit(self, fn):
self.thread_init()
self.local.commit.append(fn)
def on_rollback(self, fn):
self.thread_init()
self.local.rollback.append(fn)