class DumpRecord(abstract.AbstractRecord): grammar = dump.DumpGrammar() ext = 'dump' def evaluate_oid(self, oid): return univ.ObjectIdentifier(oid) def evaluate_value(self, oid, tag, value, **context): try: value = self.grammar.TAG_MAP[tag](value) except Exception as exc: raise SnmpsimError( 'value evaluation error for tag %r, value %r: ' '%s' % (tag, value, exc)) # not all callers supply the context - just ignore it try: if (not context['nextFlag'] and not context['exactMatch'] or context['setFlag']): return context['origOid'], tag, context['errorStatus'] except KeyError: pass return oid, tag, value def evaluate(self, line, **context): oid, tag, value = self.grammar.parse(line) oid = self.evaluate_oid(oid) if context.get('oidOnly'): value = None else: try: oid, tag, value = self.evaluate_value( oid, tag, value, **context) except PyAsn1Error as exc: raise SnmpsimError( 'value evaluation for %s = %r failed: ' '%s\r\n' % (oid, value, exc)) return oid, value def format_oid(self, oid): return univ.ObjectIdentifier(oid).prettyPrint() def format_value(self, oid, value, **context): return self.format_oid(oid), self.grammar.get_tag_by_type(value), str(value) def format(self, oid, value, **context): return self.grammar.build(*self.format_value(oid, value, **context))
class DumpRecord(abstract.AbstractRecord): grammar = dump.DumpGrammar() ext = 'dump' def evaluateOid(self, oid): return univ.ObjectIdentifier(oid) def evaluateValue(self, oid, tag, value, **context): try: value = self.grammar.tagMap[tag](value) except: raise SnmpsimError('value evaluation error for tag %r, value %r' % (tag, value)) # not all callers supply the context - just ignore it try: if (not context['nextFlag'] and not context['exactMatch'] or context['setFlag']): return context['origOid'], tag, context['errorStatus'] except KeyError: pass return oid, tag, value def evaluate(self, line, **context): oid, tag, value = self.grammar.parse(line) oid = self.evaluateOid(oid) if context.get('oidOnly'): value = None else: try: oid, tag, value = self.evaluateValue(oid, tag, value, **context) except PyAsn1Error: raise SnmpsimError('value evaluation for %s = %r failed: %s\r\n' % (oid, value, sys.exc_info()[1])) return oid, value def formatOid(self, oid): return univ.ObjectIdentifier(oid).prettyPrint() def formatValue(self, oid, value, **context): return self.formatOid(oid), self.grammar.getTagByType(value), str(value) def format(self, oid, value, **context): textOid, textTag, textValue = self.formatValue(oid, value, **context) return self.grammar.build( textOid, textTag, textValue )
class DumpRecord(abstract.AbstractRecord): grammar = dump.DumpGrammar() ext = 'dump' def evaluateOid(self, oid): return univ.ObjectIdentifier(oid) def evaluateValue(self, oid, tag, value, **context): try: return oid, tag, self.grammar.tagMap[tag](value) except: raise SnmpsimError('value evaluation error for tag %r, value %r' % (tag, value)) def evaluate(self, line, **context): oid, tag, value = self.grammar.parse(line) oid = self.evaluateOid(oid) if context.get('oidOnly'): value = None else: try: oid, tag, value = self.evaluateValue(oid, tag, value, **context) except PyAsn1Error: raise SnmpsimError( 'value evaluation for %s = %r failed: %s\r\n' % (oid, value, sys.exc_info()[1])) return oid, value def formatOid(self, oid): return univ.ObjectIdentifier(oid).prettyPrint() def formatValue(self, oid, value, **context): return self.formatOid(oid), self.grammar.getTagByType(value), str( value) def format(self, oid, value, **context): textOid, textTag, textValue = self.formatValue(oid, value, **context) return self.grammar.build(textOid, textTag, textValue)