D7606: fuzz: fix mpatch_corpus to not have an overridden __repr__ on py3
spectral (Kyle Lippincott)
phabricator at mercurial-scm.org
Thu Dec 12 07:52:10 EST 2019
Closed by commit rHG229215fc1c1c: fuzz: fix mpatch_corpus to not have an overridden __repr__ on py3 (authored by spectral).
This revision was automatically updated to reflect the committed changes.
CHANGED PRIOR TO COMMIT
https://phab.mercurial-scm.org/D7606?vs=18622&id=18627#toc
REPOSITORY
rHG Mercurial
CHANGES SINCE LAST UPDATE
https://phab.mercurial-scm.org/D7606?vs=18622&id=18627
CHANGES SINCE LAST ACTION
https://phab.mercurial-scm.org/D7606/new/
REVISION DETAIL
https://phab.mercurial-scm.org/D7606
AFFECTED FILES
contrib/fuzz/mpatch_corpus.py
CHANGE DETAILS
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 @@
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 = (
To: spectral, #hg-reviewers, pulkit
Cc: mjpieters, mercurial-devel
More information about the Mercurial-devel
mailing list