Show More
@@ -2,6 +2,7 b' from __future__ import absolute_import, ' | |||||
2 |
|
2 | |||
3 | import argparse |
|
3 | import argparse | |
4 | import struct |
|
4 | import struct | |
|
5 | import sys | |||
5 | import zipfile |
|
6 | import zipfile | |
6 |
|
7 | |||
7 | from mercurial import ( |
|
8 | from mercurial import ( | |
@@ -14,16 +15,26 b' ap.add_argument("out", metavar="some.zip' | |||||
14 | args = ap.parse_args() |
|
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 | def __init__(self, start, end, data): |
|
33 | def __init__(self, start, end, data): | |
19 | self.start = start |
|
34 | self.start = start | |
20 | self.end = end |
|
35 | self.end = end | |
21 | self.data = data |
|
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 | def __bytes__(self): |
|
38 | def __bytes__(self): | |
28 | return ( |
|
39 | return ( | |
29 | struct.pack(">lll", self.start, self.end, len(self.data)) |
|
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 | def __init__(self, frags): |
|
46 | def __init__(self, frags): | |
36 | self.frags = frags |
|
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 | def __bytes__(self): |
|
49 | def __bytes__(self): | |
43 | return b''.join(bytes(f) for f in self.frags) |
|
50 | return b''.join(bytes(f) for f in self.frags) | |
44 |
|
51 | |||
45 |
|
52 | |||
46 |
class corpus( |
|
53 | class corpus(py2reprhack): | |
47 | def __init__(self, base, deltas): |
|
54 | def __init__(self, base, deltas): | |
48 | self.base = base |
|
55 | self.base = base | |
49 | self.deltas = deltas |
|
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 | def __bytes__(self): |
|
58 | def __bytes__(self): | |
56 | deltas = [bytes(d) for d in self.deltas] |
|
59 | deltas = [bytes(d) for d in self.deltas] | |
57 | parts = ( |
|
60 | parts = ( |
General Comments 0
You need to be logged in to leave comments.
Login now