← Back to team overview

launchpad-reviewers team mailing list archive

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

 

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

Commit message:
Adjust backslashreplace for Python 3

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

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

There's a lot of type conversion going on here, but this results in something that's the right shape for use in doctests on both Python 2 and 3.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:py3-backslashreplace into launchpad:master.
diff --git a/lib/lp/services/helpers.py b/lib/lp/services/helpers.py
index 33f2e23..ca2f9ac 100644
--- a/lib/lp/services/helpers.py
+++ b/lib/lp/services/helpers.py
@@ -85,7 +85,8 @@ def backslashreplace(str):
     """Return a copy of the string, with non-ASCII characters rendered as
     xNN or uNNNN. Used to test data containing typographical quotes etc.
     """
-    return str.decode('UTF-8').encode('ASCII', 'backslashreplace')
+    return six.ensure_str(
+        six.ensure_text(str).encode('ASCII', 'backslashreplace'))
 
 
 def bytes_to_tarfile(s):