Merge lp:~brian.curtin/ubuntuone-dev-tools/py3-bytes-formatting into lp:ubuntuone-dev-tools

Proposed by Brian Curtin
Status: Merged
Approved by: dobey
Approved revision: 96
Merged at revision: 94
Proposed branch: lp:~brian.curtin/ubuntuone-dev-tools/py3-bytes-formatting
Merge into: lp:ubuntuone-dev-tools
Diff against target: 35 lines (+6/-5)
1 file modified
ubuntuone/devtools/testing/tests/test_txwebserver.py (+6/-5)
To merge this branch: bzr merge lp:~brian.curtin/ubuntuone-dev-tools/py3-bytes-formatting
Reviewer Review Type Date Requested Status
dobey (community) Approve
Manuel de la Peña (community) Approve
Review via email: mp+121711@code.launchpad.net

Commit message

- Remove byte string formatting, instead first formatting Unicode strings and then storing encoded bytes.

Description of the change

Python 3 byte strings do not have the ".format" method, so instead we should format a Unicode string and then encode it.

To post a comment you must log in.
Revision history for this message
Manuel de la Peña (mandel) :
review: Approve
Revision history for this message
dobey (dobey) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ubuntuone/devtools/testing/tests/test_txwebserver.py'
2--- ubuntuone/devtools/testing/tests/test_txwebserver.py 2012-08-21 20:55:43 +0000
3+++ ubuntuone/devtools/testing/tests/test_txwebserver.py 2012-08-28 21:31:22 +0000
4@@ -39,7 +39,8 @@
5
6 SAMPLE_KEY = b"result"
7 SAMPLE_VALUE = b"sample result"
8-SAMPLE_RESOURCE = b'{{"{0}": "{1}"}}'.format(SAMPLE_KEY, SAMPLE_VALUE)
9+SAMPLE_RESOURCE = '{{"{0}": "{1}"}}'.format(
10+ SAMPLE_KEY, SAMPLE_VALUE).encode("utf8")
11 SIMPLERESOURCE = b"simpleresource"
12 OTHER_SIMPLERESOURCE = b"othersimpleresource"
13 THROWERROR = b"throwerror"
14@@ -77,8 +78,8 @@
15 root.putChild(UNAUTHORIZED, unauthorized_resource)
16 self.server = HTTPWebServer(root)
17 self.server.start()
18- self.uri = b"http://127.0.0.1:{port}/".format(
19- port=self.server.get_port())
20+ self.uri = "http://127.0.0.1:{port}/".format(
21+ port=self.server.get_port()).encode("utf8")
22 self.addCleanup(self.server.stop)
23
24 @defer.inlineCallbacks
25@@ -134,8 +135,8 @@
26
27 def get_uri(self, server):
28 """Return the uri for the server."""
29- url = b"http://127.0.0.1:{port}/"
30- return url.format(port=server.get_port())
31+ url = "http://127.0.0.1:{port}/"
32+ return url.format(port=server.get_port()).encode("utf8")
33
34 @defer.inlineCallbacks
35 def test_single_request(self):

Subscribers

People subscribed via source and target branches

to all changes: