From 1121ff24562fcb5550cf5254621dad1a222f3919 Mon Sep 17 00:00:00 2001 From: rocky Date: Wed, 18 May 2016 17:01:40 -0400 Subject: [PATCH] Handle marshal frozenset --- pytest/test_marsh.py | 8 ++++++++ test/bytecode_3.3/06_frozenset.pyc | Bin 0 -> 320 bytes test/simple_source/expression/06_frozenset.py | 5 +++++ uncompyle6/marsh.py | 11 +++++++++-- 4 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 test/bytecode_3.3/06_frozenset.pyc create mode 100644 test/simple_source/expression/06_frozenset.py diff --git a/pytest/test_marsh.py b/pytest/test_marsh.py index 4812200e..b5a4739a 100644 --- a/pytest/test_marsh.py +++ b/pytest/test_marsh.py @@ -18,3 +18,11 @@ def test_load_module(): version, timestamp, magic_int, co = load_module(mod_file) assert version == 2.5, "Should have picked up Python version properly" assert co.co_consts == (5j, None), "Code should have a complex constant" + + mod_file = os.path.join(get_srcdir(), '..', 'test', 'bytecode_3.3', + '06_frozenset.pyc') + version, timestamp, magic_int, co = load_module(mod_file) + print(co.co_consts) + expect = (0, None, 'attlist', 'linktype', 'link', 'element', 'Yep', + frozenset({'linktype', 'attlist', 'element', 'link'})) + assert co.co_consts == expect, "Should handle frozenset" diff --git a/test/bytecode_3.3/06_frozenset.pyc b/test/bytecode_3.3/06_frozenset.pyc new file mode 100644 index 0000000000000000000000000000000000000000..8df4b6184967a9960d6ea03771272fde4d9c5589 GIT binary patch literal 320 zcmY*UJ8nWT5FF3LrJl1_|dx#^@73v;#2F4fT zTXiQPD}~qG7hI*}ET^opvwoYpK>6l$C=PPekWcwq#CHlaZJr$$x&Id`KSe8zmOOV{ zqO17vmGvJXTAwN*I73#-wh4}w+~&BZF@1+f%(nI8$@6j(+aK~w=_zz&@M+W5+0jhj KVV!Sa9?TK*W<(_b literal 0 HcmV?d00001 diff --git a/test/simple_source/expression/06_frozenset.py b/test/simple_source/expression/06_frozenset.py new file mode 100644 index 00000000..0eef7d55 --- /dev/null +++ b/test/simple_source/expression/06_frozenset.py @@ -0,0 +1,5 @@ +# Bug from Python 3.3 _markupbase.py cross compilatin +# error in unmarshaling a frozenset +import sys +if sys.argv[0] in {"attlist", "linktype", "link", "element"}: + print("Yep") diff --git a/uncompyle6/marsh.py b/uncompyle6/marsh.py index e24a957b..ce0e0fcd 100644 --- a/uncompyle6/marsh.py +++ b/uncompyle6/marsh.py @@ -258,8 +258,15 @@ def load_code_internal(fp, magic_int, bytes_for_s=False, raise KeyError(marshalType) elif marshalType in ['<', '>']: # set and frozenset - raise KeyError(marshalType) - return None + setsize = unpack('i', fp.read(4))[0] + ret = tuple() + while setsize > 0: + ret += load_code_internal(fp, magic_int, code_objects=code_objects), + setsize -= 1 + if marshalType == '>': + return frozenset(ret) + else: + return set(ret) elif marshalType == 'a': # ascii # FIXME check