From 1a6b98b2ba15f9b821140cd48d695e196d03561c Mon Sep 17 00:00:00 2001 From: elie Date: Thu, 31 Dec 2015 00:20:20 +0000 Subject: fix to OctetString.prettyOut() to pretty-print Python 3 bytes without 'b' qualifier --- pysnmp/proto/rfc1902.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'pysnmp/proto/rfc1902.py') diff --git a/pysnmp/proto/rfc1902.py b/pysnmp/proto/rfc1902.py index 1acc403c..3b69218b 100644 --- a/pysnmp/proto/rfc1902.py +++ b/pysnmp/proto/rfc1902.py @@ -4,7 +4,9 @@ # Copyright (c) 2005-2016, Ilya Etingof # License: http://pysnmp.sf.net/license.html # +from sys import version_info from pyasn1.type import univ, tag, constraint, namedtype, namedval +from pyasn1.compat import octets from pysnmp.proto import rfc1155, error __all__ = ['Opaque', 'TimeTicks', 'Bits', 'Integer', 'OctetString', @@ -208,6 +210,18 @@ class OctetString(univ.OctetString): X.__name__ = cls.__name__ return X + # modern pyasn1 does this all by itself + def prettyOut(self, value): + if version_info[0] <= 2: + numbers = tuple((ord(x) for x in value)) + else: + numbers = tuple(value) + for x in numbers: + if x < 32 or x > 126: + return '0x' + ''.join(('%.2x' % x for x in numbers)) + else: + return octets.octs2str(value) + class ObjectIdentifier(univ.ObjectIdentifier): """Creates an instance of SNMP OBJECT IDENTIFIER class. -- cgit v1.2.1