Method: difflib.SequenceMatcher.get_opcodes
Calls: 130, Exceptions: 0, Paths: 9Back
Path 1: 66 calls (0.51)
list (66)
1def get_opcodes(self):
2 """Return list of 5-tuples describing how to turn a into b.
3
4 Each tuple is of the form (tag, i1, i2, j1, j2). The first tuple
5 has i1 == j1 == 0, and remaining tuples have i1 == the i2 from the
6 tuple preceding it, and likewise for j1 == the previous j2.
7
8 The tags are strings, with these meanings:
9
10 'replace': a[i1:i2] should be replaced by b[j1:j2]
11 'delete': a[i1:i2] should be deleted.
12 Note that j1==j2 in this case.
13 'insert': b[j1:j2] should be inserted at a[i1:i1].
14 Note that i1==i2 in this case.
15 'equal': a[i1:i2] == b[j1:j2]
16
17 >>> a = "qabxcd"
18 >>> b = "abycdf"
19 >>> s = SequenceMatcher(None, a, b)
20 >>> for tag, i1, i2, j1, j2 in s.get_opcodes():
21 ... print(("%7s a[%d:%d] (%s) b[%d:%d] (%s)" %
22 ... (tag, i1, i2, a[i1:i2], j1, j2, b[j1:j2])))
23 delete a[0:1] (q) b[0:0] ()
24 equal a[1:3] (ab) b[0:2] (ab)
25 replace a[3:4] (x) b[2:3] (y)
26 equal a[4:6] (cd) b[3:5] (cd)
27 insert a[6:6] () b[5:6] (f)
28 """
29
30 if self.opcodes is not None:
31 return self.opcodes
32 i = j = 0
33 self.opcodes = answer = []
34 for ai, bj, size in self.get_matching_blocks():
35 # invariant: we've pumped out correct diffs to change
36 # a[:i] into b[:j], and the next matching block is
37 # a[ai:ai+size] == b[bj:bj+size]. So we need to pump
38 # out a diff to change a[i:ai] into b[j:bj], pump out
39 # the matching block, and move (i,j) beyond the match
40 tag = ''
41 if i < ai and j < bj:
42 tag = 'replace'
43 elif i < ai:
44 tag = 'delete'
45 elif j < bj:
46 tag = 'insert'
47 if tag:
48 answer.append( (tag, i, ai, j, bj) )
49 i, j = ai+size, bj+size
50 # the list of matching blocks is terminated by a
51 # sentinel with size 0
52 if size:
53 answer.append( ('equal', ai, i, bj, j) )
54 return answer
Path 2: 22 calls (0.17)
list (22)
1def get_opcodes(self):
2 """Return list of 5-tuples describing how to turn a into b.
3
4 Each tuple is of the form (tag, i1, i2, j1, j2). The first tuple
5 has i1 == j1 == 0, and remaining tuples have i1 == the i2 from the
6 tuple preceding it, and likewise for j1 == the previous j2.
7
8 The tags are strings, with these meanings:
9
10 'replace': a[i1:i2] should be replaced by b[j1:j2]
11 'delete': a[i1:i2] should be deleted.
12 Note that j1==j2 in this case.
13 'insert': b[j1:j2] should be inserted at a[i1:i1].
14 Note that i1==i2 in this case.
15 'equal': a[i1:i2] == b[j1:j2]
16
17 >>> a = "qabxcd"
18 >>> b = "abycdf"
19 >>> s = SequenceMatcher(None, a, b)
20 >>> for tag, i1, i2, j1, j2 in s.get_opcodes():
21 ... print(("%7s a[%d:%d] (%s) b[%d:%d] (%s)" %
22 ... (tag, i1, i2, a[i1:i2], j1, j2, b[j1:j2])))
23 delete a[0:1] (q) b[0:0] ()
24 equal a[1:3] (ab) b[0:2] (ab)
25 replace a[3:4] (x) b[2:3] (y)
26 equal a[4:6] (cd) b[3:5] (cd)
27 insert a[6:6] () b[5:6] (f)
28 """
29
30 if self.opcodes is not None:
31 return self.opcodes
32 i = j = 0
33 self.opcodes = answer = []
34 for ai, bj, size in self.get_matching_blocks():
35 # invariant: we've pumped out correct diffs to change
36 # a[:i] into b[:j], and the next matching block is
37 # a[ai:ai+size] == b[bj:bj+size]. So we need to pump
38 # out a diff to change a[i:ai] into b[j:bj], pump out
39 # the matching block, and move (i,j) beyond the match
40 tag = ''
41 if i < ai and j < bj:
42 tag = 'replace'
43 elif i < ai:
44 tag = 'delete'
45 elif j < bj:
46 tag = 'insert'
47 if tag:
48 answer.append( (tag, i, ai, j, bj) )
49 i, j = ai+size, bj+size
50 # the list of matching blocks is terminated by a
51 # sentinel with size 0
52 if size:
53 answer.append( ('equal', ai, i, bj, j) )
54 return answer
Path 3: 13 calls (0.1)
list (13)
1def get_opcodes(self):
2 """Return list of 5-tuples describing how to turn a into b.
3
4 Each tuple is of the form (tag, i1, i2, j1, j2). The first tuple
5 has i1 == j1 == 0, and remaining tuples have i1 == the i2 from the
6 tuple preceding it, and likewise for j1 == the previous j2.
7
8 The tags are strings, with these meanings:
9
10 'replace': a[i1:i2] should be replaced by b[j1:j2]
11 'delete': a[i1:i2] should be deleted.
12 Note that j1==j2 in this case.
13 'insert': b[j1:j2] should be inserted at a[i1:i1].
14 Note that i1==i2 in this case.
15 'equal': a[i1:i2] == b[j1:j2]
16
17 >>> a = "qabxcd"
18 >>> b = "abycdf"
19 >>> s = SequenceMatcher(None, a, b)
20 >>> for tag, i1, i2, j1, j2 in s.get_opcodes():
21 ... print(("%7s a[%d:%d] (%s) b[%d:%d] (%s)" %
22 ... (tag, i1, i2, a[i1:i2], j1, j2, b[j1:j2])))
23 delete a[0:1] (q) b[0:0] ()
24 equal a[1:3] (ab) b[0:2] (ab)
25 replace a[3:4] (x) b[2:3] (y)
26 equal a[4:6] (cd) b[3:5] (cd)
27 insert a[6:6] () b[5:6] (f)
28 """
29
30 if self.opcodes is not None:
31 return self.opcodes
32 i = j = 0
33 self.opcodes = answer = []
34 for ai, bj, size in self.get_matching_blocks():
35 # invariant: we've pumped out correct diffs to change
36 # a[:i] into b[:j], and the next matching block is
37 # a[ai:ai+size] == b[bj:bj+size]. So we need to pump
38 # out a diff to change a[i:ai] into b[j:bj], pump out
39 # the matching block, and move (i,j) beyond the match
40 tag = ''
41 if i < ai and j < bj:
42 tag = 'replace'
43 elif i < ai:
44 tag = 'delete'
45 elif j < bj:
46 tag = 'insert'
47 if tag:
48 answer.append( (tag, i, ai, j, bj) )
49 i, j = ai+size, bj+size
50 # the list of matching blocks is terminated by a
51 # sentinel with size 0
52 if size:
53 answer.append( ('equal', ai, i, bj, j) )
54 return answer
Path 4: 8 calls (0.06)
list (8)
1def get_opcodes(self):
2 """Return list of 5-tuples describing how to turn a into b.
3
4 Each tuple is of the form (tag, i1, i2, j1, j2). The first tuple
5 has i1 == j1 == 0, and remaining tuples have i1 == the i2 from the
6 tuple preceding it, and likewise for j1 == the previous j2.
7
8 The tags are strings, with these meanings:
9
10 'replace': a[i1:i2] should be replaced by b[j1:j2]
11 'delete': a[i1:i2] should be deleted.
12 Note that j1==j2 in this case.
13 'insert': b[j1:j2] should be inserted at a[i1:i1].
14 Note that i1==i2 in this case.
15 'equal': a[i1:i2] == b[j1:j2]
16
17 >>> a = "qabxcd"
18 >>> b = "abycdf"
19 >>> s = SequenceMatcher(None, a, b)
20 >>> for tag, i1, i2, j1, j2 in s.get_opcodes():
21 ... print(("%7s a[%d:%d] (%s) b[%d:%d] (%s)" %
22 ... (tag, i1, i2, a[i1:i2], j1, j2, b[j1:j2])))
23 delete a[0:1] (q) b[0:0] ()
24 equal a[1:3] (ab) b[0:2] (ab)
25 replace a[3:4] (x) b[2:3] (y)
26 equal a[4:6] (cd) b[3:5] (cd)
27 insert a[6:6] () b[5:6] (f)
28 """
29
30 if self.opcodes is not None:
31 return self.opcodes
32 i = j = 0
33 self.opcodes = answer = []
34 for ai, bj, size in self.get_matching_blocks():
35 # invariant: we've pumped out correct diffs to change
36 # a[:i] into b[:j], and the next matching block is
37 # a[ai:ai+size] == b[bj:bj+size]. So we need to pump
38 # out a diff to change a[i:ai] into b[j:bj], pump out
39 # the matching block, and move (i,j) beyond the match
40 tag = ''
41 if i < ai and j < bj:
42 tag = 'replace'
43 elif i < ai:
44 tag = 'delete'
45 elif j < bj:
46 tag = 'insert'
47 if tag:
48 answer.append( (tag, i, ai, j, bj) )
49 i, j = ai+size, bj+size
50 # the list of matching blocks is terminated by a
51 # sentinel with size 0
52 if size:
53 answer.append( ('equal', ai, i, bj, j) )
54 return answer
Path 5: 6 calls (0.05)
list (6)
1def get_opcodes(self):
2 """Return list of 5-tuples describing how to turn a into b.
3
4 Each tuple is of the form (tag, i1, i2, j1, j2). The first tuple
5 has i1 == j1 == 0, and remaining tuples have i1 == the i2 from the
6 tuple preceding it, and likewise for j1 == the previous j2.
7
8 The tags are strings, with these meanings:
9
10 'replace': a[i1:i2] should be replaced by b[j1:j2]
11 'delete': a[i1:i2] should be deleted.
12 Note that j1==j2 in this case.
13 'insert': b[j1:j2] should be inserted at a[i1:i1].
14 Note that i1==i2 in this case.
15 'equal': a[i1:i2] == b[j1:j2]
16
17 >>> a = "qabxcd"
18 >>> b = "abycdf"
19 >>> s = SequenceMatcher(None, a, b)
20 >>> for tag, i1, i2, j1, j2 in s.get_opcodes():
21 ... print(("%7s a[%d:%d] (%s) b[%d:%d] (%s)" %
22 ... (tag, i1, i2, a[i1:i2], j1, j2, b[j1:j2])))
23 delete a[0:1] (q) b[0:0] ()
24 equal a[1:3] (ab) b[0:2] (ab)
25 replace a[3:4] (x) b[2:3] (y)
26 equal a[4:6] (cd) b[3:5] (cd)
27 insert a[6:6] () b[5:6] (f)
28 """
29
30 if self.opcodes is not None:
31 return self.opcodes
32 i = j = 0
33 self.opcodes = answer = []
34 for ai, bj, size in self.get_matching_blocks():
35 # invariant: we've pumped out correct diffs to change
36 # a[:i] into b[:j], and the next matching block is
37 # a[ai:ai+size] == b[bj:bj+size]. So we need to pump
38 # out a diff to change a[i:ai] into b[j:bj], pump out
39 # the matching block, and move (i,j) beyond the match
40 tag = ''
41 if i < ai and j < bj:
42 tag = 'replace'
43 elif i < ai:
44 tag = 'delete'
45 elif j < bj:
46 tag = 'insert'
47 if tag:
48 answer.append( (tag, i, ai, j, bj) )
49 i, j = ai+size, bj+size
50 # the list of matching blocks is terminated by a
51 # sentinel with size 0
52 if size:
53 answer.append( ('equal', ai, i, bj, j) )
54 return answer
Path 6: 5 calls (0.04)
list (5)
1def get_opcodes(self):
2 """Return list of 5-tuples describing how to turn a into b.
3
4 Each tuple is of the form (tag, i1, i2, j1, j2). The first tuple
5 has i1 == j1 == 0, and remaining tuples have i1 == the i2 from the
6 tuple preceding it, and likewise for j1 == the previous j2.
7
8 The tags are strings, with these meanings:
9
10 'replace': a[i1:i2] should be replaced by b[j1:j2]
11 'delete': a[i1:i2] should be deleted.
12 Note that j1==j2 in this case.
13 'insert': b[j1:j2] should be inserted at a[i1:i1].
14 Note that i1==i2 in this case.
15 'equal': a[i1:i2] == b[j1:j2]
16
17 >>> a = "qabxcd"
18 >>> b = "abycdf"
19 >>> s = SequenceMatcher(None, a, b)
20 >>> for tag, i1, i2, j1, j2 in s.get_opcodes():
21 ... print(("%7s a[%d:%d] (%s) b[%d:%d] (%s)" %
22 ... (tag, i1, i2, a[i1:i2], j1, j2, b[j1:j2])))
23 delete a[0:1] (q) b[0:0] ()
24 equal a[1:3] (ab) b[0:2] (ab)
25 replace a[3:4] (x) b[2:3] (y)
26 equal a[4:6] (cd) b[3:5] (cd)
27 insert a[6:6] () b[5:6] (f)
28 """
29
30 if self.opcodes is not None:
31 return self.opcodes
32 i = j = 0
33 self.opcodes = answer = []
34 for ai, bj, size in self.get_matching_blocks():
35 # invariant: we've pumped out correct diffs to change
36 # a[:i] into b[:j], and the next matching block is
37 # a[ai:ai+size] == b[bj:bj+size]. So we need to pump
38 # out a diff to change a[i:ai] into b[j:bj], pump out
39 # the matching block, and move (i,j) beyond the match
40 tag = ''
41 if i < ai and j < bj:
42 tag = 'replace'
43 elif i < ai:
44 tag = 'delete'
45 elif j < bj:
46 tag = 'insert'
47 if tag:
48 answer.append( (tag, i, ai, j, bj) )
49 i, j = ai+size, bj+size
50 # the list of matching blocks is terminated by a
51 # sentinel with size 0
52 if size:
53 answer.append( ('equal', ai, i, bj, j) )
54 return answer
Path 7: 4 calls (0.03)
[] (4)
1def get_opcodes(self):
2 """Return list of 5-tuples describing how to turn a into b.
3
4 Each tuple is of the form (tag, i1, i2, j1, j2). The first tuple
5 has i1 == j1 == 0, and remaining tuples have i1 == the i2 from the
6 tuple preceding it, and likewise for j1 == the previous j2.
7
8 The tags are strings, with these meanings:
9
10 'replace': a[i1:i2] should be replaced by b[j1:j2]
11 'delete': a[i1:i2] should be deleted.
12 Note that j1==j2 in this case.
13 'insert': b[j1:j2] should be inserted at a[i1:i1].
14 Note that i1==i2 in this case.
15 'equal': a[i1:i2] == b[j1:j2]
16
17 >>> a = "qabxcd"
18 >>> b = "abycdf"
19 >>> s = SequenceMatcher(None, a, b)
20 >>> for tag, i1, i2, j1, j2 in s.get_opcodes():
21 ... print(("%7s a[%d:%d] (%s) b[%d:%d] (%s)" %
22 ... (tag, i1, i2, a[i1:i2], j1, j2, b[j1:j2])))
23 delete a[0:1] (q) b[0:0] ()
24 equal a[1:3] (ab) b[0:2] (ab)
25 replace a[3:4] (x) b[2:3] (y)
26 equal a[4:6] (cd) b[3:5] (cd)
27 insert a[6:6] () b[5:6] (f)
28 """
29
30 if self.opcodes is not None:
31 return self.opcodes
32 i = j = 0
33 self.opcodes = answer = []
34 for ai, bj, size in self.get_matching_blocks():
35 # invariant: we've pumped out correct diffs to change
36 # a[:i] into b[:j], and the next matching block is
37 # a[ai:ai+size] == b[bj:bj+size]. So we need to pump
38 # out a diff to change a[i:ai] into b[j:bj], pump out
39 # the matching block, and move (i,j) beyond the match
40 tag = ''
41 if i < ai and j < bj:
42 tag = 'replace'
43 elif i < ai:
44 tag = 'delete'
45 elif j < bj:
46 tag = 'insert'
47 if tag:
48 answer.append( (tag, i, ai, j, bj) )
49 i, j = ai+size, bj+size
50 # the list of matching blocks is terminated by a
51 # sentinel with size 0
52 if size:
53 answer.append( ('equal', ai, i, bj, j) )
54 return answer
Path 8: 3 calls (0.02)
list (3)
1def get_opcodes(self):
2 """Return list of 5-tuples describing how to turn a into b.
3
4 Each tuple is of the form (tag, i1, i2, j1, j2). The first tuple
5 has i1 == j1 == 0, and remaining tuples have i1 == the i2 from the
6 tuple preceding it, and likewise for j1 == the previous j2.
7
8 The tags are strings, with these meanings:
9
10 'replace': a[i1:i2] should be replaced by b[j1:j2]
11 'delete': a[i1:i2] should be deleted.
12 Note that j1==j2 in this case.
13 'insert': b[j1:j2] should be inserted at a[i1:i1].
14 Note that i1==i2 in this case.
15 'equal': a[i1:i2] == b[j1:j2]
16
17 >>> a = "qabxcd"
18 >>> b = "abycdf"
19 >>> s = SequenceMatcher(None, a, b)
20 >>> for tag, i1, i2, j1, j2 in s.get_opcodes():
21 ... print(("%7s a[%d:%d] (%s) b[%d:%d] (%s)" %
22 ... (tag, i1, i2, a[i1:i2], j1, j2, b[j1:j2])))
23 delete a[0:1] (q) b[0:0] ()
24 equal a[1:3] (ab) b[0:2] (ab)
25 replace a[3:4] (x) b[2:3] (y)
26 equal a[4:6] (cd) b[3:5] (cd)
27 insert a[6:6] () b[5:6] (f)
28 """
29
30 if self.opcodes is not None:
31 return self.opcodes
32 i = j = 0
33 self.opcodes = answer = []
34 for ai, bj, size in self.get_matching_blocks():
35 # invariant: we've pumped out correct diffs to change
36 # a[:i] into b[:j], and the next matching block is
37 # a[ai:ai+size] == b[bj:bj+size]. So we need to pump
38 # out a diff to change a[i:ai] into b[j:bj], pump out
39 # the matching block, and move (i,j) beyond the match
40 tag = ''
41 if i < ai and j < bj:
42 tag = 'replace'
43 elif i < ai:
44 tag = 'delete'
45 elif j < bj:
46 tag = 'insert'
47 if tag:
48 answer.append( (tag, i, ai, j, bj) )
49 i, j = ai+size, bj+size
50 # the list of matching blocks is terminated by a
51 # sentinel with size 0
52 if size:
53 answer.append( ('equal', ai, i, bj, j) )
54 return answer
Path 9: 3 calls (0.02)
list (3)
1def get_opcodes(self):
2 """Return list of 5-tuples describing how to turn a into b.
3
4 Each tuple is of the form (tag, i1, i2, j1, j2). The first tuple
5 has i1 == j1 == 0, and remaining tuples have i1 == the i2 from the
6 tuple preceding it, and likewise for j1 == the previous j2.
7
8 The tags are strings, with these meanings:
9
10 'replace': a[i1:i2] should be replaced by b[j1:j2]
11 'delete': a[i1:i2] should be deleted.
12 Note that j1==j2 in this case.
13 'insert': b[j1:j2] should be inserted at a[i1:i1].
14 Note that i1==i2 in this case.
15 'equal': a[i1:i2] == b[j1:j2]
16
17 >>> a = "qabxcd"
18 >>> b = "abycdf"
19 >>> s = SequenceMatcher(None, a, b)
20 >>> for tag, i1, i2, j1, j2 in s.get_opcodes():
21 ... print(("%7s a[%d:%d] (%s) b[%d:%d] (%s)" %
22 ... (tag, i1, i2, a[i1:i2], j1, j2, b[j1:j2])))
23 delete a[0:1] (q) b[0:0] ()
24 equal a[1:3] (ab) b[0:2] (ab)
25 replace a[3:4] (x) b[2:3] (y)
26 equal a[4:6] (cd) b[3:5] (cd)
27 insert a[6:6] () b[5:6] (f)
28 """
29
30 if self.opcodes is not None:
31 return self.opcodes
32 i = j = 0
33 self.opcodes = answer = []
34 for ai, bj, size in self.get_matching_blocks():
35 # invariant: we've pumped out correct diffs to change
36 # a[:i] into b[:j], and the next matching block is
37 # a[ai:ai+size] == b[bj:bj+size]. So we need to pump
38 # out a diff to change a[i:ai] into b[j:bj], pump out
39 # the matching block, and move (i,j) beyond the match
40 tag = ''
41 if i < ai and j < bj:
42 tag = 'replace'
43 elif i < ai:
44 tag = 'delete'
45 elif j < bj:
46 tag = 'insert'
47 if tag:
48 answer.append( (tag, i, ai, j, bj) )
49 i, j = ai+size, bj+size
50 # the list of matching blocks is terminated by a
51 # sentinel with size 0
52 if size:
53 answer.append( ('equal', ai, i, bj, j) )
54 return answer