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

Proposed by Brian Curtin on 2012-08-20
Status: Merged
Approved by: Brian Curtin on 2012-08-21
Approved revision: 83
Merged at revision: 87
Proposed branch: lp:~brian.curtin/ubuntuone-dev-tools/py3-io
Merge into: lp:ubuntuone-dev-tools
Diff against target: 32 lines (+4/-4)
1 file modified
ubuntuone/devtools/services/tests/test_squid.py (+4/-4)
To merge this branch: bzr merge lp:~brian.curtin/ubuntuone-dev-tools/py3-io
Reviewer Review Type Date Requested Status
Alejandro J. Cura (community) 2012-08-20 Approve on 2012-08-21
Review via email: mp+120478@code.launchpad.net

Commit Message

- Import StringIO from the io module for Python 3 compatibility

Description of the Change

Python 3 no longer has a StringIO module, instead getting the StringIO class from the io module which was backported to Python 2 as well. We can have 2 and 3 friendly code by importing StringIO from io regardless of version, and by using unicode_literals as well.

To post a comment you must log in.
Alejandro J. Cura (alecu) wrote :

The StringIO derived instance in this code is used as a fake Popen.PIPE.
But those pipes in python 3 still return bytes, so it should be BytesIO in that case.
Also, the literals used by the related testing functions should be changed to bytes literals in this branch.

review: Needs Fixing
83. By Brian Curtin on 2012-08-21

Use BytesIO and byte literals

Alejandro J. Cura (alecu) wrote :

Looks good to me.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ubuntuone/devtools/services/tests/test_squid.py'
2--- ubuntuone/devtools/services/tests/test_squid.py 2012-04-24 17:58:16 +0000
3+++ ubuntuone/devtools/services/tests/test_squid.py 2012-08-21 20:14:36 +0000
4@@ -30,7 +30,7 @@
5 import json
6 import os
7
8-from StringIO import StringIO
9+from io import BytesIO
10
11 from twisted.internet import defer
12
13@@ -237,7 +237,7 @@
14 self._assert_missing_binary('htpasswd')
15
16
17-class Pipe(StringIO):
18+class Pipe(BytesIO):
19 """A read write pipe."""
20
21 def read(self):
22@@ -364,8 +364,8 @@
23 def test_start_error(self):
24 """Test that we do raise an exception correctly."""
25 # set the error in the pipes
26- out = 'Normal out'
27- err = 'Error goes here'
28+ out = b'Normal out'
29+ err = b'Error goes here'
30 self.subprocess.stdout.write(out)
31 self.subprocess.stderr.write(err)
32 no_op = lambda _: None

Subscribers

People subscribed via source and target branches

to all changes: