Ed Blackman <[EMAIL PROTECTED]> writes:

> When email address lines are read from filter textfiles in
> Util.file_to_list, the lines are stripped of inline comments
> (the line "[EMAIL PROTECTED] # Joe Foo" becomes "[EMAIL PROTECTED]").
>
> However, when the filter textfiles are examined in
> Util.append_to_file, to see if the string being appended already
> exists, the lines aren't stripped of inline comments before checking
> to see if they're identical.  Since an address with a comment won't be
> identical to the same address without one, the address gets added a
> second time.
>
> The following patch fixes what I believe is inconsistent behavior by
> stripping inline comments from both strings in append_to_file, to
> ensure that the same address won't get added twice.

Thanks for the bugfix Ed.  I've checked in a slightly different
implementation that handles tabs as well as spaces (attached below).

? diff
Index: TMDA/Util.py
===================================================================
RCS file: /cvsroot/tmda/tmda/TMDA/Util.py,v
retrieving revision 1.103
diff -u -r1.103 Util.py
--- TMDA/Util.py	1 Aug 2003 07:22:53 -0000	1.103
+++ TMDA/Util.py	22 Sep 2003 22:55:08 -0000
@@ -412,16 +412,18 @@
     """Append a string to a text file if it isn't already in there."""
     if os.path.exists(fullpathname):
         for line in fileinput.input(fullpathname):
-            line = string.lower(string.strip(line))
+            line = line.strip().lower()
             # Comment or blank line?
             if line == '' or line[0] in '#':
                 continue
             else:
-                if string.lower(string.strip(str)) == line:
+                line = line.expandtabs().split('#')[0].strip()
+                bare = str.expandtabs().split('#')[0].strip()
+                if bare.lower() == line:
                     fileinput.close()
                     return 0
     file = open(fullpathname, 'a+')
-    file.write(string.strip(str) + '\n')
+    file.write(str.strip() + '\n')
     file.close()
 
 
_________________________________________________
tmda-workers mailing list ([EMAIL PROTECTED])
http://tmda.net/lists/listinfo/tmda-workers

Reply via email to