diff options
author | Ilya Etingof <etingof@gmail.com> | 2017-04-19 23:14:07 +0200 |
---|---|---|
committer | Ilya Etingof <etingof@gmail.com> | 2017-04-19 23:14:07 +0200 |
commit | 2d92acee6fc8b581b39ba5bca5fd370c0fbe71af (patch) | |
tree | 192a5b52ab571cb3e83bf054a8ef02f27d183850 | |
parent | 5a8af77e0d6810656d774b406ab6365259953335 (diff) | |
download | pyasn1-2d92acee6fc8b581b39ba5bca5fd370c0fbe71af.tar.gz |
ensure OctetString.prettyOut() produces unicode text
-rw-r--r-- | pyasn1/compat/octets.py | 1 | ||||
-rw-r--r-- | pyasn1/type/constraint.py | 1 | ||||
-rw-r--r-- | pyasn1/type/namedval.py | 1 | ||||
-rw-r--r-- | pyasn1/type/univ.py | 11 |
4 files changed, 11 insertions, 3 deletions
diff --git a/pyasn1/compat/octets.py b/pyasn1/compat/octets.py index ec497a6..6cf018e 100644 --- a/pyasn1/compat/octets.py +++ b/pyasn1/compat/octets.py @@ -43,4 +43,3 @@ else: isStringType = lambda s: isinstance(s, str) # noinspection PyPep8 ensureString = bytes - diff --git a/pyasn1/type/constraint.py b/pyasn1/type/constraint.py index 7f96c50..371e8ce 100644 --- a/pyasn1/type/constraint.py +++ b/pyasn1/type/constraint.py @@ -110,6 +110,7 @@ class AbstractConstraint(object): return self._valueMap def isSuperTypeOf(self, otherConstraint): + # TODO: fix possible comparison of set vs scalars here return (otherConstraint is self or not self._values or otherConstraint == self or diff --git a/pyasn1/type/namedval.py b/pyasn1/type/namedval.py index bcdbf15..bd61849 100644 --- a/pyasn1/type/namedval.py +++ b/pyasn1/type/namedval.py @@ -76,6 +76,7 @@ class NamedValues(object): 'Unknown bit identifier(s): %s' % (set(names).difference(self.nameToValIdx),) ) + # TODO support by-name subscription def __getitem__(self, i): return self.namedValues[i] diff --git a/pyasn1/type/univ.py b/pyasn1/type/univ.py index 1a146e0..911eb65 100644 --- a/pyasn1/type/univ.py +++ b/pyasn1/type/univ.py @@ -1105,9 +1105,16 @@ class OctetString(base.AbstractSimpleAsn1Item): numbers = tuple(value) for x in numbers: if x < 32 or x > 126: - return '0x' + ''.join(('%.2x' % x for x in numbers)) + return octets.octs2str('0x') + ''.join(('%.2x' % x for x in numbers)) else: - return octets.octs2str(value) + try: + return value.decode(self._encoding) + + except UnicodeDecodeError: + raise error.PyAsn1Error( + 'Can\'t decode string \'%s\' with \'%s\' codec at \'%s\'' % ( + value, self._encoding, self.__class__.__name__) + ) @staticmethod def fromBinaryString(value): |