summaryrefslogtreecommitdiff
path: root/coverage/files.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2014-12-26 10:48:29 -0500
committerNed Batchelder <ned@nedbatchelder.com>2014-12-26 10:48:29 -0500
commitff0f1ae98dad66594cd34b5aa7c24e909554bad3 (patch)
treefdcac4f02baa46101c4ab0cfe6904823b3b600cc /coverage/files.py
parent0dd9c8fb84dab988f1e34421bb91d53d45da807b (diff)
downloadpython-coveragepy-ff0f1ae98dad66594cd34b5aa7c24e909554bad3.tar.gz
Unify and clarify reading Python source. Probably broke .pyw files
Diffstat (limited to 'coverage/files.py')
-rw-r--r--coverage/files.py13
1 files changed, 7 insertions, 6 deletions
diff --git a/coverage/files.py b/coverage/files.py
index 6ba7983..2945054 100644
--- a/coverage/files.py
+++ b/coverage/files.py
@@ -8,8 +8,8 @@ import sys
import ntpath
import posixpath
-from coverage.misc import CoverageException, join_regex
-from coverage.phystokens import open_python_source
+from coverage.misc import CoverageException, NoSource, join_regex
+from coverage.phystokens import read_python_source, source_encoding
class FileLocator(object):
@@ -56,19 +56,20 @@ class FileLocator(object):
def get_python_source(filename):
- """Return the source code, as a string."""
+ """Return the source code, as a str."""
if os.path.exists(filename):
# A regular text file: open it.
- with open_python_source(filename) as f:
- return f.read()
+ return read_python_source(filename)
# Maybe it's in a zip file?
source = get_zip_bytes(filename)
if source is not None:
+ if sys.version_info >= (3, 0):
+ source = source.decode(source_encoding(source))
return source
# Couldn't find source.
- raise CoverageException(
+ raise NoSource(
"No source for code: '%s'." % filename
)