summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorelie <elie>2015-12-31 00:20:20 +0000
committerelie <elie>2015-12-31 00:20:20 +0000
commit1a6b98b2ba15f9b821140cd48d695e196d03561c (patch)
tree6d0f2503cd0d33b4b972ab918fd927b1598b3d3f
parent7080bfa36e0f7df5ef3666b8853eb7a51a214295 (diff)
downloadpysnmp-git-1a6b98b2ba15f9b821140cd48d695e196d03561c.tar.gz
fix to OctetString.prettyOut() to pretty-print Python 3 bytes without
'b' qualifier
-rw-r--r--CHANGES.txt2
-rw-r--r--pysnmp/proto/rfc1902.py14
2 files changed, 16 insertions, 0 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 99067306..8a07c22d 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -23,6 +23,8 @@ Repository `tarball download <http://pysnmp.cvs.sourceforge.net/viewvc/pysnmp/py
- Fix to snmpInvalidMsgs and snmpUnknownSecurityModels MIB symbols
import at SNMPv3 MP model.
- Fix to NotificationOriginator to cope with unspecified user callable.
+- Fix to OctetString.prettyOut() to pretty-print Python 3 bytes without
+ 'b' qualifier.
Revision 4.3.1, released 12-11-2015
-----------------------------------
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 <ilya@glas.net>
# 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.