diff options
Diffstat (limited to 'coverage')
-rw-r--r-- | coverage/backward.py | 16 | ||||
-rw-r--r-- | coverage/files.py | 5 |
2 files changed, 18 insertions, 3 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 + diff --git a/coverage/files.py b/coverage/files.py index 9a8ac564..a68a0a7f 100644 --- a/coverage/files.py +++ b/coverage/files.py @@ -1,5 +1,6 @@ """File wrangling.""" +from coverage.backward import to_string import fnmatch, os, sys class FileLocator(object): @@ -72,9 +73,7 @@ class FileLocator(object): data = zi.get_data(parts[1]) except IOError: continue - if sys.version_info >= (3, 0): - data = data.decode('utf8') # TODO: How to do this properly? - return data + return to_string(data) return None |