zodbdump: Fix pickle disassembly on py3
pickletools.dis, which is used to handle --pretty=zpickledis (*), expects output stream be text-like, not binary. We were passing a binary stream to it. As the result pickle disassembly was failing on py3: _______________________ test_zodbdump[!zext-zpickledis] ________________________ tmpdir = local('/tmp/pytest-of-kirr/pytest-11/test_zodbdump__zext_zpickledis0') zext = <function zext.<locals>._ at 0x7f538b508670>, pretty = 'zpickledis' @mark.parametrize('pretty', ('raw', 'zpickledis')) def test_zodbdump(tmpdir, zext, pretty): tdir = dirname(__file__) zkind = '_!zext' if zext.disabled else '' tfs1 = fs1_testdata_py23(tmpdir, '%s/testdata/1%s.fs' % (tdir, zkind)) stor = FileStorage(tfs1, read_only=True) with open('%s/testdata/1%s.zdump.%s.ok' % (tdir, zkind, pretty), 'rb') as f: dumpok = f.read() out = BytesIO() > zodbdump(stor, None, None, pretty=pretty, out=out) zodbtools/test/test_dump.py:48: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ zodbtools/zodbdump.py:165: in zodbdump pickletools.dis(dataf, disf) # class _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ pickle = <_io.BytesIO object at 0x7f538b577130> out = <_io.BytesIO object at 0x7f538b49f8b0>, memo = {}, indentlevel = 4 annotate = 0 def dis(pickle, out=None, memo=None, indentlevel=4, annotate=0): """Produce a symbolic disassembly of a pickle...""" ... for opcode, arg, pos in genops(pickle): if pos is not None: > print("%5d:" % pos, end=' ', file=out) E TypeError: a bytes-like object is required, not 'str' /usr/lib/python3.9/pickletools.py:2450: TypeError -> Fix it by letting pickletools.dis to emit its output to StringIO instead of BytesIO. (*) see 80559a94 "zodbdump: support --pretty option with a format to show pickles disassembly"
Showing
Please register or sign in to comment