for line in difflib.unified_diff(from_lines, to_lines, lineterm=""):
if line.startswith("@@"): match = re.match(self.REGEX_RANGE, line)
if not match: continue line_number = int(match.group("from_start"))
if line_number > 1: insert_tagged_text(iter, self.ELLIPSIS, "default")
elif line.startswith("---") or line.startswith("+++"): continue
Note the 'if not match: continue' after the REGEX_RANGE lookup - and REGEX_RANGE is:
REGEX_RANGE = "^@@ \-(?P<from_start>[0-9]+),(?P<from_context>[0-9]+) " \ "\+(?P<to_start>[0-9]+),(?P<to_context>[0-9]+) @@"
Now difflib.py has this for its output:
first, last = group[0], group[-1]
file1_range = _format_range_unified(first[1], last[2])
file2_range = _format_range_unified(first[3], last[4])
yield '@@ -{} +{} @@{}'.format(file1_range, file2_range, lineterm)
And if you look at _format_range_unified it has this:
# Per the diff spec at http://www.unix.org/single_unix_specification/
beginning = start + 1 # lines start numbering with one
length = stop - start
if length == 1:
return '{}'.format(beginning)
if not length:
beginning -= 1 # empty ranges begin at line just before the range
return '{},{}'.format(beginning, length)
So if the diff range is precisely 1 line long, the output will be
@@ -12 +12,13 @@
But the regex aptdaemon has expects x,y never just x.
So - bad regex, fix that and you should be good. May need to tweak the assignment code of course.
So, this is the loop http:// bazaar. launchpad. net/~aptdaemon- developers/ aptdaemon/ main/view/ head:/aptdaemon /gtk3widgets. py#L1114
for line in difflib. unified_ diff(from_ lines, to_lines, lineterm=""): ("@@"):
match = re.match( self.REGEX_ RANGE, line)
continue
line_ number = int(match. group(" from_start" ))
insert_ tagged_ text(iter, self.ELLIPSIS, "default") ("---") or line.startswith ("+++") :
continue
if line.startswith
if not match:
if line_number > 1:
elif line.startswith
Note the 'if not match: continue' after the REGEX_RANGE lookup - and REGEX_RANGE is: start>[ 0-9]+), (?P<from_ context> [0-9]+) " \
"\+ (?P<to_ start>[ 0-9]+), (?P<to_ context> [0-9]+) @@"
REGEX_RANGE = "^@@ \-(?P<from_
Now difflib.py has this for its output: range_unified( first[1] , last[2]) range_unified( first[3] , last[4]) file1_range, file2_range, lineterm)
first, last = group[0], group[-1]
file1_range = _format_
file2_range = _format_
yield '@@ -{} +{} @@{}'.format(
And if you look at _format_ range_unified it has this: www.unix. org/single_ unix_specificat ion/ beginning) .format( beginning, length)
# Per the diff spec at http://
beginning = start + 1 # lines start numbering with one
length = stop - start
if length == 1:
return '{}'.format(
if not length:
beginning -= 1 # empty ranges begin at line just before the range
return '{},{}'
So if the diff range is precisely 1 line long, the output will be
@@ -12 +12,13 @@
But the regex aptdaemon has expects x,y never just x.
So - bad regex, fix that and you should be good. May need to tweak the assignment code of course.