diff options
| author | Ned Batchelder <ned@nedbatchelder.com> | 2013-09-28 10:07:55 -0400 | 
|---|---|---|
| committer | Ned Batchelder <ned@nedbatchelder.com> | 2013-09-28 10:07:55 -0400 | 
| commit | 5e5cf2d5b9d7decfce16142a7cf7cc140fcbf354 (patch) | |
| tree | 42126d750637ec001e5a46046ff76100284faf0b /coverage/backward.py | |
| parent | f859f95e5988d88b580afdb7771f03a8ff612411 (diff) | |
| download | python-coveragepy-git-5e5cf2d5b9d7decfce16142a7cf7cc140fcbf354.tar.gz | |
More abstractions for bytes objects. Cleans up some version checks in the real code.
Diffstat (limited to 'coverage/backward.py')
| -rw-r--r-- | coverage/backward.py | 26 | 
1 files changed, 26 insertions, 0 deletions
| diff --git a/coverage/backward.py b/coverage/backward.py index 4894bac0..e782284a 100644 --- a/coverage/backward.py +++ b/coverage/backward.py @@ -140,6 +140,19 @@ if sys.version_info >= (3, 0):          """Convert bytes `b` to a 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_value): +        """Turn an element of a bytes object into an int.""" +        return byte_value + +    def bytes_to_ints(bytes_value): +        """Turn a bytes object into a sequence of ints.""" +        # In Py3, iterating bytes gives ints. +        return bytes_value +  else:      def to_bytes(s):          """Convert string `s` to bytes (no-op in 2.x).""" @@ -149,6 +162,19 @@ else:          """Convert bytes `b` to a string (no-op in 2.x)."""          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_value): +        """Turn an element of a bytes object into an int.""" +        return ord(byte_value) + +    def bytes_to_ints(bytes_value): +        """Turn a bytes object into a sequence of ints.""" +        for byte in bytes_value: +            yield ord(byte) +  # Md5 is available in different places.  try:      import hashlib | 
