diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2021-05-01 13:02:31 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2021-05-01 13:30:39 -0400 |
commit | 9df434550a499c16e9fd26cfb9627837bfdc02a5 (patch) | |
tree | 5619ea3c3bec05d04363a66ced9c7ebffcefb1df /coverage/backward.py | |
parent | 3fe17c1f2244c07cf9d0f9e3609392c2ad441db1 (diff) | |
download | python-coveragepy-git-9df434550a499c16e9fd26cfb9627837bfdc02a5.tar.gz |
refactor: remove code explicitly choosing between py2 and py3
Diffstat (limited to 'coverage/backward.py')
-rw-r--r-- | coverage/backward.py | 68 |
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__ |