Fix stdout()/stderr() helpers for Python 3 #254

Merged
merged 1 commit into from May 9, 2014

Conversation

Projects
None yet
3 participants
@living180
Contributor

living180 commented May 8, 2014

On Python 3, the core.stdout() and core.stderr() helper functions were attempting to concatenate the message encoded as a bytestring with a unicode string containing a newline, which raises a TypeError. Fix this by concatenating the newline first, and then only encoding the result if on Python 2, since Python 3 wants unicode strings anyway.

core: fix stdout()/stderr() helpers for Python 3
On Python 3, the core.stdout() and core.stderr() helper functions were
attempting to concatenate the message encoded as a bytestring with a
unicode string containing a newline, which raises a TypeError.  Fix this
by concatenating the newline first, and then only encoding the result if
on Python 2, since Python 3 wants unicode strings anyway.

Signed-off-by: Daniel Harding <dharding@living180.net>
@hsoft

This comment has been minimized.

Show comment
Hide comment
@hsoft

hsoft May 8, 2014

Member

What about a simpler solution like .write(encode(msg) + b'\n')?

Member

hsoft commented May 8, 2014

What about a simpler solution like .write(encode(msg) + b'\n')?

@living180

This comment has been minimized.

Show comment
Hide comment
@living180

living180 May 8, 2014

Contributor

What about a simpler solution like .write(encode(msg) + b'\n')?

That doesn't work on Python 3, because in that case .write() expects a unicode string, not a bytestring.

Contributor

living180 commented May 8, 2014

What about a simpler solution like .write(encode(msg) + b'\n')?

That doesn't work on Python 3, because in that case .write() expects a unicode string, not a bytestring.

@hsoft

This comment has been minimized.

Show comment
Hide comment
@hsoft

hsoft May 8, 2014

Member

Oh yeah, true. So the source of the error isn't only the concatenation.

Member

hsoft commented May 8, 2014

Oh yeah, true. So the source of the error isn't only the concatenation.

@living180

This comment has been minimized.

Show comment
Hide comment
@living180

living180 May 8, 2014

Contributor

Right. The first solution I tried was .write(encode(msg + '\n')), but that also raises a TypeError on Python 3.

Contributor

living180 commented May 8, 2014

Right. The first solution I tried was .write(encode(msg + '\n')), but that also raises a TypeError on Python 3.

davvid added a commit that referenced this pull request May 9, 2014

Merge pull request #254 from living180/py3_fix_stdout_stderr
Fix stdout()/stderr() helpers for Python 3

@davvid davvid merged commit 13de53e into git-cola:master May 9, 2014

@living180 living180 deleted the living180:py3_fix_stdout_stderr branch May 9, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment