Show More
@@ -8,6 +8,11 b'' | |||||
8 |
|
8 | |||
9 | import struct |
|
9 | import struct | |
10 |
|
10 | |||
|
11 | from typing import ( | |||
|
12 | List, | |||
|
13 | Tuple, | |||
|
14 | ) | |||
|
15 | ||||
11 | from ..pure.bdiff import * |
|
16 | from ..pure.bdiff import * | |
12 | from . import _bdiff # pytype: disable=import-error |
|
17 | from . import _bdiff # pytype: disable=import-error | |
13 |
|
18 | |||
@@ -15,7 +20,7 b' ffi = _bdiff.ffi' | |||||
15 | lib = _bdiff.lib |
|
20 | lib = _bdiff.lib | |
16 |
|
21 | |||
17 |
|
22 | |||
18 | def blocks(sa, sb): |
|
23 | def blocks(sa: bytes, sb: bytes) -> List[Tuple[int, int, int, int]]: | |
19 | a = ffi.new(b"struct bdiff_line**") |
|
24 | a = ffi.new(b"struct bdiff_line**") | |
20 | b = ffi.new(b"struct bdiff_line**") |
|
25 | b = ffi.new(b"struct bdiff_line**") | |
21 | ac = ffi.new(b"char[]", str(sa)) |
|
26 | ac = ffi.new(b"char[]", str(sa)) | |
@@ -43,7 +48,7 b' def blocks(sa, sb):' | |||||
43 | return rl |
|
48 | return rl | |
44 |
|
49 | |||
45 |
|
50 | |||
46 | def bdiff(sa, sb): |
|
51 | def bdiff(sa: bytes, sb: bytes) -> bytes: | |
47 | a = ffi.new(b"struct bdiff_line**") |
|
52 | a = ffi.new(b"struct bdiff_line**") | |
48 | b = ffi.new(b"struct bdiff_line**") |
|
53 | b = ffi.new(b"struct bdiff_line**") | |
49 | ac = ffi.new(b"char[]", str(sa)) |
|
54 | ac = ffi.new(b"char[]", str(sa)) |
@@ -10,8 +10,13 b' import difflib' | |||||
10 | import re |
|
10 | import re | |
11 | import struct |
|
11 | import struct | |
12 |
|
12 | |||
|
13 | from typing import ( | |||
|
14 | List, | |||
|
15 | Tuple, | |||
|
16 | ) | |||
13 |
|
17 | |||
14 | def splitnewlines(text): |
|
18 | ||
|
19 | def splitnewlines(text: bytes) -> List[bytes]: | |||
15 | '''like str.splitlines, but only split on newlines.''' |
|
20 | '''like str.splitlines, but only split on newlines.''' | |
16 | lines = [l + b'\n' for l in text.split(b'\n')] |
|
21 | lines = [l + b'\n' for l in text.split(b'\n')] | |
17 | if lines: |
|
22 | if lines: | |
@@ -22,7 +27,9 b' def splitnewlines(text):' | |||||
22 | return lines |
|
27 | return lines | |
23 |
|
28 | |||
24 |
|
29 | |||
25 |
def _normalizeblocks( |
|
30 | def _normalizeblocks( | |
|
31 | a: List[bytes], b: List[bytes], blocks | |||
|
32 | ) -> List[Tuple[int, int, int]]: | |||
26 | prev = None |
|
33 | prev = None | |
27 | r = [] |
|
34 | r = [] | |
28 | for curr in blocks: |
|
35 | for curr in blocks: | |
@@ -57,7 +64,7 b' def _normalizeblocks(a, b, blocks):' | |||||
57 | return r |
|
64 | return r | |
58 |
|
65 | |||
59 |
|
66 | |||
60 | def bdiff(a, b): |
|
67 | def bdiff(a: bytes, b: bytes) -> bytes: | |
61 | a = bytes(a).splitlines(True) |
|
68 | a = bytes(a).splitlines(True) | |
62 | b = bytes(b).splitlines(True) |
|
69 | b = bytes(b).splitlines(True) | |
63 |
|
70 | |||
@@ -84,7 +91,7 b' def bdiff(a, b):' | |||||
84 | return b"".join(bin) |
|
91 | return b"".join(bin) | |
85 |
|
92 | |||
86 |
|
93 | |||
87 | def blocks(a, b): |
|
94 | def blocks(a: bytes, b: bytes) -> List[Tuple[int, int, int, int]]: | |
88 | an = splitnewlines(a) |
|
95 | an = splitnewlines(a) | |
89 | bn = splitnewlines(b) |
|
96 | bn = splitnewlines(b) | |
90 | d = difflib.SequenceMatcher(None, an, bn).get_matching_blocks() |
|
97 | d = difflib.SequenceMatcher(None, an, bn).get_matching_blocks() | |
@@ -92,7 +99,7 b' def blocks(a, b):' | |||||
92 | return [(i, i + n, j, j + n) for (i, j, n) in d] |
|
99 | return [(i, i + n, j, j + n) for (i, j, n) in d] | |
93 |
|
100 | |||
94 |
|
101 | |||
95 | def fixws(text, allws): |
|
102 | def fixws(text: bytes, allws: bool) -> bytes: | |
96 | if allws: |
|
103 | if allws: | |
97 | text = re.sub(b'[ \t\r]+', b'', text) |
|
104 | text = re.sub(b'[ \t\r]+', b'', text) | |
98 | else: |
|
105 | else: |
General Comments 0
You need to be logged in to leave comments.
Login now