-
Notifications
You must be signed in to change notification settings - Fork 249
/
Copy pathsasl_compat.py
47 lines (39 loc) · 1.25 KB
/
sasl_compat.py
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
45
46
47
from puresasl.client import SASLClient, SASLError
from contextlib import contextmanager
@contextmanager
def error_catcher(self, Exc = Exception):
try:
self.error = None
yield
except Exc as e:
self.error = str(e)
class PureSASLClient(SASLClient):
def __init__(self, *args, **kwargs):
self.error = None
super(PureSASLClient, self).__init__(*args, **kwargs)
def start(self, mechanism):
with error_catcher(self, SASLError):
if isinstance(mechanism, list):
self.choose_mechanism(mechanism)
else:
self.choose_mechanism([mechanism])
return True, self.mechanism, self.process()
# else
return False, mechanism, None
def encode(self, incoming):
with error_catcher(self):
return True, self.unwrap(incoming)
# else
return False, None
def decode(self, outgoing):
with error_catcher(self):
return True, self.wrap(outgoing)
# else
return False, None
def step(self, challenge):
with error_catcher(self):
return True, self.process(challenge)
# else
return False, None
def getError(self):
return self.error