launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #26346
[Merge] ~cjwatson/launchpad:py3-bugzilla-parseDOMString into launchpad:master
Colin Watson has proposed merging ~cjwatson/launchpad:py3-bugzilla-parseDOMString into launchpad:master.
Commit message:
Fix Bugzilla._parseDOMString for Python 3
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/398263
The object being translated is bytes, not text; and on Python 3 we have to use bytes.maketrans (or str.maketrans for text) rather than string.maketrans.
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:py3-bugzilla-parseDOMString into launchpad:master.
diff --git a/lib/lp/bugs/externalbugtracker/bugzilla.py b/lib/lp/bugs/externalbugtracker/bugzilla.py
index 8f9c1d4..5fa1163 100644
--- a/lib/lp/bugs/externalbugtracker/bugzilla.py
+++ b/lib/lp/bugs/externalbugtracker/bugzilla.py
@@ -187,10 +187,11 @@ class Bugzilla(ExternalBugTracker):
# high bit set for non-ASCII characters, we can now strip out any
# ASCII control characters without touching encoded Unicode
# characters.
- bad_chars = ''.join(chr(i) for i in range(0, 32))
- for char in '\n\r\t':
- bad_chars = bad_chars.replace(char, '')
- trans_map = string.maketrans(bad_chars, ' ' * len(bad_chars))
+ bad_chars = b''.join(six.int2byte(i) for i in range(0, 32))
+ for char in b'\n', b'\r', b'\t':
+ bad_chars = bad_chars.replace(char, b'')
+ maketrans = bytes.maketrans if six.PY3 else string.maketrans
+ trans_map = maketrans(bad_chars, b' ' * len(bad_chars))
contents = contents.translate(trans_map)
# Don't use forbid_dtd=True here; Bugzilla XML responses seem to
# include DOCTYPE declarations.