summaryrefslogtreecommitdiff
path: root/coverage/backward.py
diff options
context:
space:
mode:
Diffstat (limited to 'coverage/backward.py')
-rw-r--r--coverage/backward.py68
1 files changed, 21 insertions, 47 deletions
diff --git a/coverage/backward.py b/coverage/backward.py
index 779cd661..da839d71 100644
--- a/coverage/backward.py
+++ b/coverage/backward.py
@@ -11,8 +11,6 @@ import sys
from datetime import datetime
-from coverage import env
-
# Pythons 2 and 3 differ on where to get StringIO.
try:
@@ -119,51 +117,27 @@ else:
return iter(seq).next
# 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 env.PY3:
- def to_bytes(s):
- """Convert string `s` to bytes."""
- return s.encode('utf8')
-
- def to_string(b):
- """Convert bytes `b` to string."""
- return b.decode('utf8')
-
- def binary_bytes(byte_values):
- """Produce a byte string with the ints from `byte_values`."""
- return bytes(byte_values)
-
- def byte_to_int(byte):
- """Turn a byte indexed from a bytes object into an int."""
- return byte
-
- def bytes_to_ints(bytes_value):
- """Turn a bytes object into a sequence of ints."""
- # In Python 3, iterating bytes gives ints.
- return bytes_value
-
-else:
- def to_bytes(s):
- """Convert string `s` to bytes (no-op in 2.x)."""
- return s
-
- def to_string(b):
- """Convert bytes `b` to string."""
- return b
-
- def binary_bytes(byte_values):
- """Produce a byte string with the ints from `byte_values`."""
- return "".join(chr(b) for b in byte_values)
-
- def byte_to_int(byte):
- """Turn a byte indexed from a bytes object into an int."""
- return ord(byte)
-
- def bytes_to_ints(bytes_value):
- """Turn a bytes object into a sequence of ints."""
- for byte in bytes_value:
- yield ord(byte)
-
+# get them right.
+def to_bytes(s):
+ """Convert string `s` to bytes."""
+ return s.encode('utf8')
+
+def to_string(b):
+ """Convert bytes `b` to string."""
+ return b.decode('utf8')
+
+def binary_bytes(byte_values):
+ """Produce a byte string with the ints from `byte_values`."""
+ return bytes(byte_values)
+
+def byte_to_int(byte):
+ """Turn a byte indexed from a bytes object into an int."""
+ return byte
+
+def bytes_to_ints(bytes_value):
+ """Turn a bytes object into a sequence of ints."""
+ # In Python 3, iterating bytes gives ints.
+ return bytes_value
try:
# In Python 2.x, the builtins were in __builtin__