Method: difflib.Differ.compare
Calls: 24, Exceptions: 0, Paths: 4Back
Path 1: 14 calls (0.58)
['', ' 1. Beautiful is beTTer than ugly.', ' 2. Explicit is better than implicit.', ' 3. Simple is better than complex.', ' 4. Complex is bett...
['', ' 1. Beautiful is better than ugly.', ' 3. Simple is better than complex.', ' 4. Complicated is better than complex.', ' 5. Flat is bet...
' 123' (150) '? ^^\n' (34) ' ' (20) '- 1. Beautiful is beTTer than ugly.' (18) '- 3. Simple is better than complex.' (18)...
1def compare(self, a, b):
2 r"""
3 Compare two sequences of lines; generate the resulting delta.
4
5 Each sequence must contain individual single-line strings ending with
6 newlines. Such sequences can be obtained from the `readlines()` method
7 of file-like objects. The delta generated also consists of newline-
8 terminated strings, ready to be printed as-is via the writelines()
9 method of a file-like object.
10
11 Example:
12
13 >>> print(''.join(Differ().compare('one\ntwo\nthree\n'.splitlines(True),
14 ... 'ore\ntree\nemu\n'.splitlines(True))),
15 ... end="")
16 - one
17 ? ^
18 + ore
19 ? ^
20 - two
21 - three
22 ? -
23 + tree
24 + emu
25 """
26
27 cruncher = SequenceMatcher(self.linejunk, a, b)
28 for tag, alo, ahi, blo, bhi in cruncher.get_opcodes():
29 if tag == 'replace':
30 g = self._fancy_replace(a, alo, ahi, b, blo, bhi)
31 elif tag == 'delete':
32 g = self._dump('-', a, alo, ahi)
33 elif tag == 'insert':
34 g = self._dump('+', b, blo, bhi)
35 elif tag == 'equal':
36 g = self._dump(' ', a, alo, ahi)
37 else:
38 raise ValueError('unknown tag %r' % (tag,))
39
40 yield from g
Path 2: 6 calls (0.25)
['one\n', 'two\n', 'three\n'] (3) ['\tI am a buggy'] (1) ['\t \t \t^'] (1) ['2'] (1)
['ore\n', 'tree\n', 'emu\n'] (3) ['\t\tI am a bug'] (1) ['\t \t \t^\n'] (1) ['3'] (1)
'? ^\n' (6) '- one\n' (3) '+ ore\n' (3) '- two\n' (3) '- three\n' (3) '? -\n' (3) '+ tree\n' (3) '+ emu\n' (3) '- \tI am a buggy' (1) '? \t ...
1def compare(self, a, b):
2 r"""
3 Compare two sequences of lines; generate the resulting delta.
4
5 Each sequence must contain individual single-line strings ending with
6 newlines. Such sequences can be obtained from the `readlines()` method
7 of file-like objects. The delta generated also consists of newline-
8 terminated strings, ready to be printed as-is via the writelines()
9 method of a file-like object.
10
11 Example:
12
13 >>> print(''.join(Differ().compare('one\ntwo\nthree\n'.splitlines(True),
14 ... 'ore\ntree\nemu\n'.splitlines(True))),
15 ... end="")
16 - one
17 ? ^
18 + ore
19 ? ^
20 - two
21 - three
22 ? -
23 + tree
24 + emu
25 """
26
27 cruncher = SequenceMatcher(self.linejunk, a, b)
28 for tag, alo, ahi, blo, bhi in cruncher.get_opcodes():
29 if tag == 'replace':
30 g = self._fancy_replace(a, alo, ahi, b, blo, bhi)
31 elif tag == 'delete':
32 g = self._dump('-', a, alo, ahi)
33 elif tag == 'insert':
34 g = self._dump('+', b, blo, bhi)
35 elif tag == 'equal':
36 g = self._dump(' ', a, alo, ahi)
37 else:
38 raise ValueError('unknown tag %r' % (tag,))
39
40 yield from g
Path 3: 2 calls (0.08)
['', ' 1. Beautiful is beTTer than ugly.', ' 2. Explicit is better than implicit.', ' 3. Simple is better than complex.', ' 4. Complex is bett...
['', ' 1. Beautiful is beTTer than ugly.', ' 2. Explicit is better than implicit.', ' 3. Simple is better than complex.', ' 4. Complex is bett...
' 123' (60) ' ' (6) ' 1. Beautiful is beTTer than ugly.' (6) ' 2. Explicit is better than implicit.' (6) ' 3. Simple is better than comp...
1def compare(self, a, b):
2 r"""
3 Compare two sequences of lines; generate the resulting delta.
4
5 Each sequence must contain individual single-line strings ending with
6 newlines. Such sequences can be obtained from the `readlines()` method
7 of file-like objects. The delta generated also consists of newline-
8 terminated strings, ready to be printed as-is via the writelines()
9 method of a file-like object.
10
11 Example:
12
13 >>> print(''.join(Differ().compare('one\ntwo\nthree\n'.splitlines(True),
14 ... 'ore\ntree\nemu\n'.splitlines(True))),
15 ... end="")
16 - one
17 ? ^
18 + ore
19 ? ^
20 - two
21 - three
22 ? -
23 + tree
24 + emu
25 """
26
27 cruncher = SequenceMatcher(self.linejunk, a, b)
28 for tag, alo, ahi, blo, bhi in cruncher.get_opcodes():
29 if tag == 'replace':
30 g = self._fancy_replace(a, alo, ahi, b, blo, bhi)
31 elif tag == 'delete':
32 g = self._dump('-', a, alo, ahi)
33 elif tag == 'insert':
34 g = self._dump('+', b, blo, bhi)
35 elif tag == 'equal':
36 g = self._dump(' ', a, alo, ahi)
37 else:
38 raise ValueError('unknown tag %r' % (tag,))
39
40 yield from g
Path 4: 2 calls (0.08)
[] (2)
[] (2)
1def compare(self, a, b):
2 r"""
3 Compare two sequences of lines; generate the resulting delta.
4
5 Each sequence must contain individual single-line strings ending with
6 newlines. Such sequences can be obtained from the `readlines()` method
7 of file-like objects. The delta generated also consists of newline-
8 terminated strings, ready to be printed as-is via the writelines()
9 method of a file-like object.
10
11 Example:
12
13 >>> print(''.join(Differ().compare('one\ntwo\nthree\n'.splitlines(True),
14 ... 'ore\ntree\nemu\n'.splitlines(True))),
15 ... end="")
16 - one
17 ? ^
18 + ore
19 ? ^
20 - two
21 - three
22 ? -
23 + tree
24 + emu
25 """
26
27 cruncher = SequenceMatcher(self.linejunk, a, b)
28 for tag, alo, ahi, blo, bhi in cruncher.get_opcodes():
29 if tag == 'replace':
30 g = self._fancy_replace(a, alo, ahi, b, blo, bhi)
31 elif tag == 'delete':
32 g = self._dump('-', a, alo, ahi)
33 elif tag == 'insert':
34 g = self._dump('+', b, blo, bhi)
35 elif tag == 'equal':
36 g = self._dump(' ', a, alo, ahi)
37 else:
38 raise ValueError('unknown tag %r' % (tag,))
39
40 yield from g