Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/cygwin-apps/calm.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Turney <jon.turney@dronecode.org.uk>2022-07-16 21:56:28 +0300
committerJon Turney <jon.turney@dronecode.org.uk>2022-07-16 22:11:09 +0300
commit4ef519f84b9da106f07677289f629787384cb469 (patch)
tree1e0d7ba891aff91421c283fb3981eaa211a52a39
parent3208633a6de90abb61ff737d0b6fc994c65ea3a9 (diff)
Fix BufferingSMTPHandler used as a context
Since a1cb1581, BufferingSMTPHandler was used directly as a context to send an unhandled exception termination report email, but that class doesn't support such use...
-rw-r--r--calm/buffering_smtp_handler.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/calm/buffering_smtp_handler.py b/calm/buffering_smtp_handler.py
index b7dfee7..2cd1b63 100644
--- a/calm/buffering_smtp_handler.py
+++ b/calm/buffering_smtp_handler.py
@@ -95,3 +95,14 @@ class BufferingSMTPHandler(logging.handlers.BufferingHandler):
# the capacity we pass to BufferingHandler is irrelevant since we
# override shouldFlush so it never indicates we have reached capacity
return False
+
+ def __enter__(self):
+ logging.getLogger().addHandler(self)
+ return self
+
+ def __exit__(self, exception_type, exception_value, traceback):
+ self.close()
+ logging.getLogger().removeHandler(self)
+
+ # process any exception in the with-block normally
+ return False