Mercurial > hg-stable
changeset 43867:229215fc1c1c
fuzz: fix mpatch_corpus to not have an overridden __repr__ on py3
Differential Revision: https://phab.mercurial-scm.org/D7606
author | Kyle Lippincott <spectral@google.com> |
---|---|
date | Wed, 11 Dec 2019 15:23:54 -0800 |
parents | 612951e08278 |
children | 74ec6ca0eb75 |
files | contrib/fuzz/mpatch_corpus.py |
diffstat | 1 files changed, 18 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/contrib/fuzz/mpatch_corpus.py Wed Dec 11 10:00:24 2019 -0800 +++ b/contrib/fuzz/mpatch_corpus.py Wed Dec 11 15:23:54 2019 -0800 @@ -2,6 +2,7 @@ import argparse import struct +import sys import zipfile from mercurial import ( @@ -14,16 +15,26 @@ 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 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 = (