summaryrefslogtreecommitdiff
path: root/coverage/codeunit.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2009-09-30 08:45:39 -0400
committerNed Batchelder <ned@nedbatchelder.com>2009-09-30 08:45:39 -0400
commit4c5448eda225588b705074a68663b9322b54006c (patch)
tree8a786e851dd4e91632d22e420a5c3afb0a47abff /coverage/codeunit.py
parentefb089e1576eaa9326cce08978f81c25169850f2 (diff)
downloadpython-coveragepy-4c5448eda225588b705074a68663b9322b54006c.tar.gz
Last clean up on the egg-reading code. Fixes issue #25.
Diffstat (limited to 'coverage/codeunit.py')
-rw-r--r--coverage/codeunit.py21
1 files changed, 12 insertions, 9 deletions
diff --git a/coverage/codeunit.py b/coverage/codeunit.py
index d85735d..79ae4f0 100644
--- a/coverage/codeunit.py
+++ b/coverage/codeunit.py
@@ -86,7 +86,6 @@ class CodeUnit:
self.name = n
self.modname = modname
-
def __repr__(self):
return "<CodeUnit name=%r filename=%r>" % (self.name, self.filename)
@@ -129,12 +128,16 @@ class CodeUnit:
def source_file(self):
"""Return an open file for reading the source of the code unit."""
- if not os.path.exists(self.filename):
- source = self.file_locator.get_zip_data(self.filename)
- if source is None:
- raise CoverageException(
- "No source for code %r." % self.filename
- )
+ if os.path.exists(self.filename):
+ # A regular text file: open it.
+ return open(self.filename)
+
+ # Maybe it's in a zip file?
+ source = self.file_locator.get_zip_data(self.filename)
+ if source is not None:
return StringIO(source)
-
- return open(self.filename)
+
+ # Couldn't find source.
+ raise CoverageException(
+ "No source for code %r." % self.filename
+ )