Patch to make mutt's trac work, proper csv parsing

Christoph Berg myon at debian.org
Mon Jan 19 22:45:04 UTC 2009


Hi,

mutt's trac includes the full report in the csv (tab-separated)
reports bts-link tries to download. The trac parser will choke on the
embedded newlines an then try to apply a html parser.

The patch below fixes this; this should be compatible with other
tracs.

See for example http://dev.mutt.org/trac/ticket/3000?format=tab (from
#460904).


diff --git a/remote/trac.py b/remote/trac.py
index b868c0f..6306d0a 100644
--- a/remote/trac.py
+++ b/remote/trac.py
@@ -30,7 +30,7 @@
 
 # @see http://projects.edgewall.com/trac/wiki/TracTickets
 
-import re, urllib
+import re, urllib, csv
 
 from BeautifulSoup import BeautifulSoup
 from __init__ import *
@@ -40,11 +40,12 @@ any = re.compile(r'.*')
 
 class TracTicket:
     def __init__(self, page):
-        lines = page.split('\n');
+        try:
+            list = [ x + '\n' for x in page.split('\n')]
+            data = csv.reader(list, delimiter = '\t')
 
-        if len(lines) == 2:
-            keys = lines[0].split('\t')
-            vals = lines[1].split('\t')
+            keys = data.next()
+            vals = data.next()
             dct  = dict((keys[i], vals[i]) for i in range(0, len(keys)))
 
             self.status     = dct['status']
@@ -57,7 +58,7 @@ class TracTicket:
             self.version    = dct['version']
             self.priority   = dct['priority']
             self.description = dct['description'].replace("\\r\\n", "\r\n")
-        else:
+        except:
             soup = BeautifulSoup(page)
 
             status = soup.first(any, 'status')

Christoph
-- 
cb at df7cb.de | http://www.df7cb.de/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: Digital signature
Url : http://lists.alioth.debian.org/pipermail/bts-link-devel/attachments/20090119/48bf7a12/attachment.pgp 


More information about the Bts-link-devel mailing list