wrapexp.py
来自「实现snmp协议的agent 和manager」· Python 代码 · 共 69 行
PY
69 行
""" Invoke base API methods, catch possible exceptions and translate them into legacy PySNMP 1.x counterparts. Copyright 1999-2002 by Ilya Etingof <ilya@glas.net>. See LICENSE for details."""import pysnmp.proto.error, pysnmp.asn1.error, pysnmp.asn1.encoding.ber.errorfrom pysnmp.compat.pysnmp1x import errorclass Base: """Base compatibility class """ def _wrapper(self, fun, *args): """Call passed function and translate possible exceptions """ try: return apply(fun, args) # Catch transport exceptions except pysnmp.mapping.udp.error.BadArgumentError, why: raise error.BadArgument(why) except pysnmp.mapping.udp.error.NoResponseError, why: raise error.NoResponse(why) except pysnmp.mapping.udp.error.NetworkError, why: raise error.TransportError(why) # Catch protocol package exceptions except pysnmp.proto.error.BadArgumentError, why: raise error.BadArgument(why) except pysnmp.proto.error.ProtoError, why: raise error.SNMPEngineError(why) # Catch ber package exceptions except pysnmp.asn1.encoding.ber.error.BadArgumentError, why: raise error.BEREngineError(why) except pysnmp.asn1.encoding.ber.error.TypeMismatchError, why: raise error.UnknownTag(why) except pysnmp.asn1.encoding.ber.error.OverFlowError, why: raise error.OverFlow(why) except pysnmp.asn1.encoding.ber.error.UnderRunError, why: raise error.BadEncoding(why) except pysnmp.asn1.encoding.ber.error.BadEncodingError, why: raise error.BadEncoding(why) except pysnmp.asn1.encoding.ber.error.BerEncodingError, why: raise error.BEREngineError(why) # Catch asn1 package exceptions except pysnmp.asn1.error.BadArgumentError, why: raise error.BadArgument(why) except pysnmp.asn1.error.ValueConstraintError, why: raise error.TypeMismatch(why) except pysnmp.asn1.error.Asn1Error, why: raise error.PySNMPError(why)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?