Skip to content

Commit

Permalink
Fix problems @trap'ing print() on py3
Browse files Browse the repository at this point in the history
  • Loading branch information
bitprophet committed Apr 14, 2013
1 parent 271e853 commit 79f2714
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions spec/trap.py
Expand Up @@ -34,6 +34,11 @@ def __init__(self, buffer=b'', cc=None):
self.cc = cc

def write(self, s):
# Ensure we always write bytes. This means that wrapped code calling
# print(<a string object>) in Python 3 will still work. Sigh.
if not isinstance(s, six.binary_type):
s = s.encode('utf-8')
# Write out to our capturing object & any CC's
IO.write(self, s)
for writer in self.cc:
writer.write(s)
Expand Down

0 comments on commit 79f2714

Please sign in to comment.