Fix PySnmpError implementation

This is a follow up fix to make PySnmpError properly
overriding base Exception call signature
pull/186/head
Ilya Etingof 2018-08-05 10:24:50 +02:00
parent 853ba0bbf5
commit 3b514f9aec
1 changed files with 11 additions and 2 deletions

View File

@ -9,6 +9,15 @@ import sys
class PySnmpError(Exception):
def __init__(self, message):
def __init__(self, *args):
msg = args and str(args[0]) or ''
self.cause = sys.exc_info()
Exception.__init__(self, '%s, caused by %s: %s' % (message, self.cause[0], self.cause[1]))
if self.cause[0]:
msg += 'caused by %s: %s' % (self.cause[0], self.cause[1])
if msg:
args = (msg,) + args[1:]
Exception.__init__(self, *args)