From 8b721d294ab99f55b9ff670b53bc1e5d1920b37c Mon Sep 17 00:00:00 2001 From: elie Date: Thu, 10 Sep 2015 19:59:23 +0000 Subject: fix to ObjectIdentifier initialization from unicode string --- CHANGES.txt | 1 + pyasn1/compat/octets.py | 2 ++ pyasn1/type/univ.py | 2 +- test/type/test_univ.py | 2 ++ 4 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGES.txt b/CHANGES.txt index 7a8e0a0..90bd1fc 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -4,6 +4,7 @@ Revision 0.1.9 - Wheel distribution format now supported. - Extensions added to text files, CVS attic flushed. - Fix to make uninitilaized pyasn1 objects failing properly on hash(). +- Fix to ObjectIdentifier initialization from unicode string. Revision 0.1.8, released 22-06-2015 ----------------------------------- diff --git a/pyasn1/compat/octets.py b/pyasn1/compat/octets.py index f7f2a29..e812737 100644 --- a/pyasn1/compat/octets.py +++ b/pyasn1/compat/octets.py @@ -9,6 +9,7 @@ if version_info[0] <= 2: str2octs = lambda x: x octs2str = lambda x: x isOctetsType = lambda s: isinstance(s, str) + isStringType = lambda s: isinstance(s, (str, unicode)) else: ints2octs = bytes int2oct = lambda x: ints2octs((x,)) @@ -18,3 +19,4 @@ else: str2octs = lambda x: x.encode() octs2str = lambda x: x.decode() isOctetsType = lambda s: isinstance(s, bytes) + isStringType = lambda s: isinstance(s, str) diff --git a/pyasn1/type/univ.py b/pyasn1/type/univ.py index f4bff81..4ed640f 100644 --- a/pyasn1/type/univ.py +++ b/pyasn1/type/univ.py @@ -533,7 +533,7 @@ class ObjectIdentifier(base.AbstractSimpleAsn1Item): pass elif isinstance(value, ObjectIdentifier): return tuple(value) - elif isinstance(value, str): + elif octets.isStringType(value): r = [] for element in [ x for x in value.split('.') if x != '' ]: try: diff --git a/test/type/test_univ.py b/test/type/test_univ.py index b973164..e8d0a4f 100644 --- a/test/type/test_univ.py +++ b/test/type/test_univ.py @@ -284,6 +284,8 @@ class ObjectIdentifier(unittest.TestCase): assert univ.ObjectIdentifier((1,3,6))==(1,3,6),'prettyIn() fails' def testInput3(self): assert univ.ObjectIdentifier(univ.ObjectIdentifier('1.3') + (6,))==(1,3,6),'prettyIn() fails' + def testUnicode(self): + assert univ.ObjectIdentifier(u'1.3.6') == (1,3,6), 'unicode init fails' def testTag(self): assert univ.ObjectIdentifier().getTagSet() == tag.TagSet( (), -- cgit v1.2.1