@@ -805,14 +805,20 @@ def loadMibs(self, *modNames):
805805 self .__args [0 ].loadMibs (* modNames )
806806 return self
807807
808- def resolveWithMib (self , mibViewController ):
808+ def resolveWithMib (self , mibViewController , ignoreErrors = True ):
809809 """Perform MIB variable ID and associated value conversion.
810810
811811 Parameters
812812 ----------
813813 mibViewController : :py:class:`~pysnmp.smi.view.MibViewController`
814814 class instance representing MIB browsing functionality.
815815
816+ Other Parameters
817+ ----------------
818+ ignoreErrors: :py:class:`bool`
819+ If `True` (default), ignore MIB object name or value casting
820+ failures if possible.
821+
816822 Returns
817823 -------
818824 : :py:class:`~pysnmp.smi.rfc1902.ObjectType`
@@ -851,7 +857,8 @@ class instance representing MIB browsing functionality.
851857
852858 if not isinstance (self .__args [0 ].getMibNode (),
853859 (MibScalar , MibTableColumn )):
854- if not isinstance (self .__args [1 ], AbstractSimpleAsn1Item ):
860+ if (ignoreErrors and
861+ not isinstance (self .__args [1 ], AbstractSimpleAsn1Item )):
855862 raise SmiError ('MIB object %r is not OBJECT-TYPE (MIB not loaded?)' % (self .__args [0 ],))
856863 self .__state |= self .stClean
857864 return self
@@ -866,9 +873,15 @@ class instance representing MIB browsing functionality.
866873 try :
867874 self .__args [1 ] = self .__args [0 ].getMibNode ().getSyntax ().clone (self .__args [1 ])
868875 except PyAsn1Error :
869- raise SmiError ('MIB object %r having type %r failed to cast value %r: %s' % (
870- self .__args [0 ].prettyPrint (), self .__args [0 ].getMibNode ().getSyntax ().__class__ .__name__ , self .__args [1 ],
871- sys .exc_info ()[1 ]))
876+ err = ('MIB object %r having type %r failed to cast value '
877+ '%r: %s' % (self .__args [0 ].prettyPrint (),
878+ self .__args [0 ].getMibNode ().getSyntax ().__class__ .__name__ ,
879+ self .__args [1 ],
880+ sys .exc_info ()[1 ]))
881+
882+ if (not ignoreErrors or
883+ not isinstance (self .__args [1 ], AbstractSimpleAsn1Item )):
884+ raise SmiError (err )
872885
873886 if rfc1902 .ObjectIdentifier ().isSuperTypeOf (self .__args [1 ], matchConstraints = False ):
874887 self .__args [1 ] = ObjectIdentity (self .__args [1 ]).resolveWithMib (mibViewController )
0 commit comments