← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:py3-apidoc-bytes-text into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:py3-apidoc-bytes-text into launchpad:master.

Commit message:
Fix bytes/text handling in create-lp-wadl-and-apidoc.py

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

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

generate_wadl and generate_html produce bytes, while generate_json produces text.  It's easiest to just handle either.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:py3-apidoc-bytes-text into launchpad:master.
diff --git a/utilities/create-lp-wadl-and-apidoc.py b/utilities/create-lp-wadl-and-apidoc.py
index a2255ff..7157a1a 100755
--- a/utilities/create-lp-wadl-and-apidoc.py
+++ b/utilities/create-lp-wadl-and-apidoc.py
@@ -22,6 +22,7 @@ import subprocess
 import sys
 
 from lazr.restful.interfaces import IWebServiceConfiguration
+import six
 from zope.component import getUtility
 from zope.pagetemplate.pagetemplatefile import PageTemplateFile
 
@@ -36,9 +37,8 @@ from lp.systemhomes import WebServiceApplication
 
 def write(filename, content, timestamp):
     """Replace the named file with the given string."""
-    f = open(filename, 'w')
-    f.write(content)
-    f.close()
+    with open(filename, 'wb') as f:
+        f.write(six.ensure_binary(content))
     os.utime(filename, (timestamp, timestamp))  # (atime, mtime)