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

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: e0e8a1b7e83044d47841b397d2eaa6dffd7cdadf
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:py3-mantis-newlines
Merge into: launchpad:master
Diff against target: 28 lines (+3/-2)
1 file modified
lib/lp/bugs/externalbugtracker/mantis.py (+3/-2)
Reviewer Review Type Date Requested Status
Cristian Gonzalez (community) Approve
Review via email: mp+398906@code.launchpad.net

Commit message

Mantis: Handle newline reading differences

Description of the change

When opening files in text mode, Python 3 turns \r\n into \n. Adjust Mantis.getRemoteBugBatch to handle either line ending convention.

To post a comment you must log in.
Revision history for this message
Cristian Gonzalez (cristiangsp) wrote :

Looks good!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/bugs/externalbugtracker/mantis.py b/lib/lp/bugs/externalbugtracker/mantis.py
2index 69781a4..6673378 100644
3--- a/lib/lp/bugs/externalbugtracker/mantis.py
4+++ b/lib/lp/bugs/externalbugtracker/mantis.py
5@@ -11,6 +11,7 @@ __all__ = [
6
7 import csv
8 import logging
9+import re
10
11 from bs4.element import Comment
12 from requests.cookies import RequestsCookieJar
13@@ -329,13 +330,13 @@ class Mantis(ExternalBugTracker):
14 def getRemoteBugBatch(self, bug_ids):
15 """See `ExternalBugTracker`."""
16 # XXX: Gavin Panella 2007-09-06 bug=137780:
17- # You may find this zero in "\r\n0" funny. Well I don't. This is
18+ # You may find this zero in "\r?\n0" funny. Well I don't. This is
19 # to work around the fact that Mantis' CSV export doesn't cope
20 # with the fact that the bug summary can contain embedded "\r\n"
21 # characters! I don't see a better way to handle this short of
22 # not using the CSV module and forcing all lines to have the
23 # same number as fields as the header.
24- csv_data = self.csv_data.strip().split("\r\n0")
25+ csv_data = re.split(r"\r?\n0", self.csv_data.strip())
26
27 if not csv_data:
28 raise UnparsableBugData("Empty CSV for %s" % self.baseurl)

Subscribers

People subscribed via source and target branches

to status/vote changes: