more comments and debug code
authorJann Horn <jann@thejh.net>
Sun, 1 Sep 2024 21:41:20 +0000 (23:41 +0200)
committerJann Horn <jann@thejh.net>
Sun, 1 Sep 2024 21:41:20 +0000 (23:41 +0200)
threadview.py

index 6b93b62..f52bbef 100755 (executable)
@@ -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)