Show More
@@ -2,6 +2,7 b' from __future__ import absolute_import, ' | |||
|
2 | 2 | |
|
3 | 3 | import argparse |
|
4 | 4 | import struct |
|
5 | import sys | |
|
5 | 6 | import zipfile |
|
6 | 7 | |
|
7 | 8 | from mercurial import ( |
@@ -14,16 +15,26 b' ap.add_argument("out", metavar="some.zip' | |||
|
14 | 15 | args = ap.parse_args() |
|
15 | 16 | |
|
16 | 17 | |
|
17 | class deltafrag(object): | |
|
18 | if sys.version_info[0] < 3: | |
|
19 | ||
|
20 | class py2reprhack(object): | |
|
21 | def __repr__(self): | |
|
22 | """Py2 calls __repr__ for `bytes(foo)`, forward to __bytes__""" | |
|
23 | return self.__bytes__() | |
|
24 | ||
|
25 | ||
|
26 | else: | |
|
27 | ||
|
28 | class py2reprhack(object): | |
|
29 | """Not needed on py3.""" | |
|
30 | ||
|
31 | ||
|
32 | class deltafrag(py2reprhack): | |
|
18 | 33 | def __init__(self, start, end, data): |
|
19 | 34 | self.start = start |
|
20 | 35 | self.end = end |
|
21 | 36 | self.data = data |
|
22 | 37 | |
|
23 | def __repr__(self): | |
|
24 | # py2 calls __repr__ when you do `bytes(foo)` | |
|
25 | return self.__bytes__() | |
|
26 | ||
|
27 | 38 | def __bytes__(self): |
|
28 | 39 | return ( |
|
29 | 40 | struct.pack(">lll", self.start, self.end, len(self.data)) |
@@ -31,27 +42,19 b' class deltafrag(object):' | |||
|
31 | 42 | ) |
|
32 | 43 | |
|
33 | 44 | |
|
34 |
class delta( |
|
|
45 | class delta(py2reprhack): | |
|
35 | 46 | def __init__(self, frags): |
|
36 | 47 | self.frags = frags |
|
37 | 48 | |
|
38 | def __repr__(self): | |
|
39 | # py2 calls __repr__ when you do `bytes(foo)` | |
|
40 | return self.__bytes__() | |
|
41 | ||
|
42 | 49 | def __bytes__(self): |
|
43 | 50 | return b''.join(bytes(f) for f in self.frags) |
|
44 | 51 | |
|
45 | 52 | |
|
46 |
class corpus( |
|
|
53 | class corpus(py2reprhack): | |
|
47 | 54 | def __init__(self, base, deltas): |
|
48 | 55 | self.base = base |
|
49 | 56 | self.deltas = deltas |
|
50 | 57 | |
|
51 | def __repr__(self): | |
|
52 | # py2 calls __repr__ when you do `bytes(foo)` | |
|
53 | return self.__bytes__() | |
|
54 | ||
|
55 | 58 | def __bytes__(self): |
|
56 | 59 | deltas = [bytes(d) for d in self.deltas] |
|
57 | 60 | parts = ( |
General Comments 0
You need to be logged in to leave comments.
Login now