summaryrefslogtreecommitdiff
path: root/dns/exception.py
diff options
context:
space:
mode:
authorBob Halley <halley@dnspython.org>2020-07-26 17:48:14 -0700
committerBob Halley <halley@dnspython.org>2020-07-26 17:48:14 -0700
commit84e076521246abd2ecdcb34b458adc402e14e3d6 (patch)
tree255f5e876aa6161b40780b0681b0f1ac9c953a47 /dns/exception.py
parentcb49bfc57cbf68f0e31f0c2f541eb64a06463eca (diff)
downloaddnspython-wrap.tar.gz
Wrap exceptions from rdata from_text() and from_wire().wrap
Diffstat (limited to 'dns/exception.py')
-rw-r--r--dns/exception.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/dns/exception.py b/dns/exception.py
index 8f1d488..9486f45 100644
--- a/dns/exception.py
+++ b/dns/exception.py
@@ -126,3 +126,17 @@ class Timeout(DNSException):
"""The DNS operation timed out."""
supp_kwargs = {'timeout'}
fmt = "The DNS operation timed out after {timeout} seconds"
+
+
+class ExceptionWrapper:
+ def __init__(self, exception_class):
+ self.exception_class = exception_class
+
+ def __enter__(self):
+ return self
+
+ def __exit__(self, exc_type, exc_val, exc_tb):
+ if exc_type is not None and not isinstance(exc_val,
+ self.exception_class):
+ raise self.exception_class() from exc_val
+ return False