# HG changeset patch # User Kyle Lippincott # Date 2019-12-11 23:23:54 # Node ID 229215fc1c1c8c55d9edd47737a00283f89efec6 # Parent 612951e08278318f89f5db52da314ab6823a09fa fuzz: fix mpatch_corpus to not have an overridden __repr__ on py3 Differential Revision: https://phab.mercurial-scm.org/D7606 diff --git a/contrib/fuzz/mpatch_corpus.py b/contrib/fuzz/mpatch_corpus.py --- a/contrib/fuzz/mpatch_corpus.py +++ b/contrib/fuzz/mpatch_corpus.py @@ -2,6 +2,7 @@ from __future__ import absolute_import, import argparse import struct +import sys import zipfile from mercurial import ( @@ -14,16 +15,26 @@ ap.add_argument("out", metavar="some.zip args = ap.parse_args() -class deltafrag(object): +if sys.version_info[0] < 3: + + class py2reprhack(object): + def __repr__(self): + """Py2 calls __repr__ for `bytes(foo)`, forward to __bytes__""" + return self.__bytes__() + + +else: + + class py2reprhack(object): + """Not needed on py3.""" + + +class deltafrag(py2reprhack): def __init__(self, start, end, data): self.start = start self.end = end self.data = data - def __repr__(self): - # py2 calls __repr__ when you do `bytes(foo)` - return self.__bytes__() - def __bytes__(self): return ( struct.pack(">lll", self.start, self.end, len(self.data)) @@ -31,27 +42,19 @@ class deltafrag(object): ) -class delta(object): +class delta(py2reprhack): def __init__(self, frags): self.frags = frags - def __repr__(self): - # py2 calls __repr__ when you do `bytes(foo)` - return self.__bytes__() - def __bytes__(self): return b''.join(bytes(f) for f in self.frags) -class corpus(object): +class corpus(py2reprhack): def __init__(self, base, deltas): self.base = base self.deltas = deltas - def __repr__(self): - # py2 calls __repr__ when you do `bytes(foo)` - return self.__bytes__() - def __bytes__(self): deltas = [bytes(d) for d in self.deltas] parts = (