← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:py3-mantis-newlines into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:py3-mantis-newlines into launchpad:master.

Commit message:
Mantis: Handle newline reading differences

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/398906

When opening files in text mode, Python 3 turns \r\n into \n.  Adjust Mantis.getRemoteBugBatch to handle either line ending convention.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:py3-mantis-newlines into launchpad:master.
diff --git a/lib/lp/bugs/externalbugtracker/mantis.py b/lib/lp/bugs/externalbugtracker/mantis.py
index 69781a4..6673378 100644
--- a/lib/lp/bugs/externalbugtracker/mantis.py
+++ b/lib/lp/bugs/externalbugtracker/mantis.py
@@ -11,6 +11,7 @@ __all__ = [
 
 import csv
 import logging
+import re
 
 from bs4.element import Comment
 from requests.cookies import RequestsCookieJar
@@ -329,13 +330,13 @@ class Mantis(ExternalBugTracker):
     def getRemoteBugBatch(self, bug_ids):
         """See `ExternalBugTracker`."""
         # XXX: Gavin Panella 2007-09-06 bug=137780:
-        # You may find this zero in "\r\n0" funny. Well I don't. This is
+        # You may find this zero in "\r?\n0" funny. Well I don't. This is
         # to work around the fact that Mantis' CSV export doesn't cope
         # with the fact that the bug summary can contain embedded "\r\n"
         # characters! I don't see a better way to handle this short of
         # not using the CSV module and forcing all lines to have the
         # same number as fields as the header.
-        csv_data = self.csv_data.strip().split("\r\n0")
+        csv_data = re.split(r"\r?\n0", self.csv_data.strip())
 
         if not csv_data:
             raise UnparsableBugData("Empty CSV for %s" % self.baseurl)