summaryrefslogtreecommitdiff
path: root/pysnmp/proto/rfc1902.py
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 /pysnmp/proto/rfc1902.py
parent7080bfa36e0f7df5ef3666b8853eb7a51a214295 (diff)
downloadpysnmp-git-1a6b98b2ba15f9b821140cd48d695e196d03561c.tar.gz
fix to OctetString.prettyOut() to pretty-print Python 3 bytes without
'b' qualifier
Diffstat (limited to 'pysnmp/proto/rfc1902.py')
-rw-r--r--pysnmp/proto/rfc1902.py14
1 files changed, 14 insertions, 0 deletions
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.