summaryrefslogtreecommitdiff
path: root/coverage/execfile.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2013-10-20 08:05:24 -0400
committerNed Batchelder <ned@nedbatchelder.com>2013-10-20 08:05:24 -0400
commitb94d42b78127beb210a8d9aee0746608412f305f (patch)
treeca7a966c19c9df399d1982a3723d893c122c18bb /coverage/execfile.py
parent249ad14dfedbe45919b48dbbff445394a64d985c (diff)
downloadpython-coveragepy-b94d42b78127beb210a8d9aee0746608412f305f.tar.gz
try/except/finally is ok now.
Diffstat (limited to 'coverage/execfile.py')
-rw-r--r--coverage/execfile.py55
1 files changed, 27 insertions, 28 deletions
diff --git a/coverage/execfile.py b/coverage/execfile.py
index 71ec931..aec6534 100644
--- a/coverage/execfile.py
+++ b/coverage/execfile.py
@@ -31,35 +31,34 @@ def run_python_module(modulename, args):
openfile = None
glo, loc = globals(), locals()
try:
- try:
- # Search for the module - inside its parent package, if any - using
- # standard import mechanics.
- if '.' in modulename:
- packagename, name = rsplit1(modulename, '.')
- package = __import__(packagename, glo, loc, ['__path__'])
- searchpath = package.__path__
- else:
- packagename, name = None, modulename
- searchpath = None # "top-level search" in imp.find_module()
+ # Search for the module - inside its parent package, if any - using
+ # standard import mechanics.
+ if '.' in modulename:
+ packagename, name = rsplit1(modulename, '.')
+ package = __import__(packagename, glo, loc, ['__path__'])
+ searchpath = package.__path__
+ else:
+ packagename, name = None, modulename
+ searchpath = None # "top-level search" in imp.find_module()
+ openfile, pathname, _ = imp.find_module(name, searchpath)
+
+ # Complain if this is a magic non-file module.
+ if openfile is None and pathname is None:
+ raise NoSource(
+ "module does not live in a file: %r" % modulename
+ )
+
+ # If `modulename` is actually a package, not a mere module, then we
+ # pretend to be Python 2.7 and try running its __main__.py script.
+ if openfile is None:
+ packagename = modulename
+ name = '__main__'
+ package = __import__(packagename, glo, loc, ['__path__'])
+ searchpath = package.__path__
openfile, pathname, _ = imp.find_module(name, searchpath)
-
- # Complain if this is a magic non-file module.
- if openfile is None and pathname is None:
- raise NoSource(
- "module does not live in a file: %r" % modulename
- )
-
- # If `modulename` is actually a package, not a mere module, then we
- # pretend to be Python 2.7 and try running its __main__.py script.
- if openfile is None:
- packagename = modulename
- name = '__main__'
- package = __import__(packagename, glo, loc, ['__path__'])
- searchpath = package.__path__
- openfile, pathname, _ = imp.find_module(name, searchpath)
- except ImportError:
- _, err, _ = sys.exc_info()
- raise NoSource(str(err))
+ except ImportError:
+ _, err, _ = sys.exc_info()
+ raise NoSource(str(err))
finally:
if openfile:
openfile.close()