summaryrefslogtreecommitdiff
path: root/coverage/backward.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2011-03-15 19:18:12 -0400
committerNed Batchelder <ned@nedbatchelder.com>2011-03-15 19:18:12 -0400
commit83a4a2a389f0bc0eee32c578dd7bda64c4f3e18b (patch)
tree986bd33abdf0b44ede7469945e3351952841d10d /coverage/backward.py
parent78fa8c3bf90fdf64397565cad64846dc6807e21b (diff)
downloadpython-coveragepy-git-83a4a2a389f0bc0eee32c578dd7bda64c4f3e18b.tar.gz
A file opened in 'b' mode needs bytes, not strings. Try to do this in a clean-ish way...
Diffstat (limited to 'coverage/backward.py')
-rw-r--r--coverage/backward.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/coverage/backward.py b/coverage/backward.py
index c363f21f..af6da629 100644
--- a/coverage/backward.py
+++ b/coverage/backward.py
@@ -81,3 +81,19 @@ except AttributeError:
"""Open a source file the best way."""
return open(fname, "rU")
+# Python 3.x is picky about bytes and strings, so provide methods to
+# get them right, and make them no-ops in 2.x
+if sys.version_info >= (3, 0):
+ def to_bytes(s):
+ return s.encode('utf8')
+
+ def to_string(b):
+ return b.decode('utf8')
+
+else:
+ def to_bytes(s):
+ return s
+
+ def to_string(b):
+ return b
+