From ab7512500366daf4dff892d7a76bd954b28f5744 Mon Sep 17 00:00:00 2001 From: Jann Horn Date: Sun, 1 Sep 2024 23:41:20 +0200 Subject: [PATCH] more comments and debug code --- threadview.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/threadview.py b/threadview.py index 6b93b62..f52bbef 100755 --- a/threadview.py +++ b/threadview.py @@ -6,6 +6,9 @@ import email.policy import html import mailbox +# for diff preparation: +# normalize whitespace sequences to single space, for when people reply from +# gmail, which turns tabs into spaces def join_whitespace(text): return ' '.join(text.split()) @@ -27,6 +30,11 @@ class TextBlockRange: for line in self.message.lines.lines[self.start_pos_orig:self.start_pos_orig+self.length_orig]: line.real_quote = True + #print('CREATED TEXT BLOCK, '+('quote' if self.is_quote else 'orig')) + #print('<<<') + #print(self.get_text()) + #print('>>>') + # returns exclusive end def end_pos_child(self): return self.start_pos_child + self.length @@ -152,6 +160,7 @@ class TextBlockRangeset: def drop_quotes(self): self.ranges = list(filter(lambda r: not r.is_quote, self.ranges)) + # must only be called once all the blocks have been pulled up to their diff-root def trim_blocks(self): for r in self.ranges: r.trim_blanks_and_trailing_quote_header() @@ -184,6 +193,10 @@ class Line: def as_hashable_line(self): return join_whitespace(self.text.strip()) +def dump_string_list(string_list): + for idx, line in enumerate(string_list): + print(str(idx) + ' ' + line) + class Lines: def __init__(self, text): self.plain_lines = text.split('\n') @@ -196,6 +209,10 @@ class Lines: return list(map(lambda line: line.as_hashable_inherited_line(), self.lines)) def diff_to_parent(self, msg, parent): + #print('A (parent):') + #dump_string_list(parent.as_hashable_list()) + #print('B (child):') + #dump_string_list(self.as_hashable_inherited_list()) sm = difflib.SequenceMatcher((lambda line: line == None or line == ''), parent.as_hashable_list(), self.as_hashable_inherited_list()) inherited_chunks = sm.get_matching_blocks() #print(inherited_chunks) -- 2.20.1