Report the original stream:error stanza to clients.
[punjab-krb5-preauth] / punjab / patches.py
1 # XXX: All monkey patches should be sent upstream and eventually removed.
2
3 import functools
4
5 def patch(cls, attr):
6     """Patch the function named attr in the object cls with the decorated function."""
7     orig_func = getattr(cls, attr)
8     @wraps(orig_func)
9     def decorator(func):
10         def wrapped_func(*args, **kwargs):
11             return func(orig_func, *args, **kwargs)
12         setattr(cls, attr, wrapped_func)
13         return orig_func
14     return decorator
15
16 # Modify jabber.error.exceptionFromStreamError to include the XML element in
17 # the exception.
18 from twisted.words.protocols.jabber import error as jabber_error
19 @patch(jabber_error, "exceptionFromStreamError")
20 def exceptionFromStreamError(orig, element):
21     exception = orig(element)
22     exception.element = element
23     return exception
24