summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIlya Etingof <etingof@gmail.com>2017-11-23 11:44:10 +0100
committerIlya Etingof <etingof@gmail.com>2017-11-23 11:44:10 +0100
commit67e460c8302cd1e2cf181b0d0430f3cdd9681b0c (patch)
tree9281bc024dc1bde2d5e49784c60779592a6825fd
parentd3f166fd034c286a2e7eaff6d690343f4bc7a56c (diff)
downloadpyasn1-git-67e460c8302cd1e2cf181b0d0430f3cdd9681b0c.tar.gz
fix to invoke potentially overridden OctetString.prettyOut()v0.4.1
-rw-r--r--pyasn1/type/char.py13
-rw-r--r--pyasn1/type/univ.py24
2 files changed, 32 insertions, 5 deletions
diff --git a/pyasn1/type/char.py b/pyasn1/type/char.py
index 3a29165..8986b70 100644
--- a/pyasn1/type/char.py
+++ b/pyasn1/type/char.py
@@ -123,7 +123,20 @@ class AbstractCharacterString(univ.OctetString):
def asNumbers(self, padding=True):
return tuple(bytes(self))
+ #
+ # See OctetString.prettyPrint() for the explanation
+ #
+
+ def prettyOut(self, value):
+ return value
+
def prettyPrint(self, scope=0):
+ # first see if subclass has its own .prettyOut()
+ value = self.prettyOut(self._value)
+
+ if value is not self._value:
+ return value
+
return AbstractCharacterString.__str__(self)
def __reversed__(self):
diff --git a/pyasn1/type/univ.py b/pyasn1/type/univ.py
index fc13705..3aaa300 100644
--- a/pyasn1/type/univ.py
+++ b/pyasn1/type/univ.py
@@ -900,23 +900,37 @@ class OctetString(base.AbstractSimpleAsn1Item):
# OctetString.prettyPrint() used to return hexified payload
# representation in cases when non-printable content is present. At the
# same time `str()` used to produce either octet-stream (Py2) or
- # text (Py3) representations. Therefore `OctetString.__str__()` is
- # decoupled from `.prettyPrint` to preserve the original behaviour.
+ # text (Py3) representations.
#
- # Eventually we should make `__str__` reporting hexified representation
- # while both text and octet-stream representation should only be requested
- # via the `.asOctets()` method.
+ # Therefore `OctetString.__str__()` -> `.prettyPrint()` call chain is
+ # reversed to preserve the original behaviour.
+ #
+ # Eventually we should deprecate `.prettyPrint()` / `.prettyOut()` harness
+ # and end up with just `__str__()` producing hexified representation while
+ # both text and octet-stream representation should only be requested via
+ # the `.asOctets()` method.
#
# Note: ASN.1 OCTET STRING is never mean to contain text!
#
+ def prettyOut(self, value):
+ return value
+
def prettyPrint(self, scope=0):
+ # first see if subclass has its own .prettyOut()
+ value = self.prettyOut(self._value)
+
+ if value is not self._value:
+ return value
+
numbers = self.asNumbers()
for x in numbers:
+ # hexify if needed
if x < 32 or x > 126:
return '0x' + ''.join(('%.2x' % x for x in numbers))
else:
+ # this prevents infinite recursion
return OctetString.__str__(self)
@staticmethod