Handle marshal frozenset

This commit is contained in:
rocky 2016-05-18 17:01:40 -04:00
parent fbcdc7a181
commit 1121ff2456
4 changed files with 22 additions and 2 deletions

View File

@ -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"

Binary file not shown.

View File

@ -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")

View File

@ -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