Home | History | Annotate | Download | only in python2.7

Lines Matching refs:code

1 """runpy.py - locating and running Python code using the module namespace
6 This allows Python code to play nicely with non-filesystem based PEP 302
62 def _run_code(code, run_globals, init_globals=None,
65 """Helper to run code in nominated namespace"""
72 exec code in run_globals
75 def _run_module_code(code, init_globals=None,
78 """Helper to run code in new namespace with sys modified"""
81 _run_code(code, mod_globals, init_globals,
99 # Helper to get the loader, code and filename for a module
113 code = loader.get_code(mod_name)
114 if code is None:
115 raise ImportError("No code object available for %s" % mod_name)
117 return mod_name, loader, code, filename
141 function should be used to run the module code in a fresh namespace.
151 mod_name, loader, code, fname = _get_module_details(mod_name)
153 mod_name, loader, code, fname = _get_main_module_details()
161 return _run_code(code, main_globals, None,
166 """Execute a module's code without importing it
170 mod_name, loader, code, fname = _get_module_details(mod_name)
175 return _run_module_code(code, init_globals, run_name,
179 return _run_code(code, {}, init_globals, run_name,
216 code = read_code(f)
217 if code is None:
218 # That didn't work, so try it as normal source code
220 code = compile(f.read(), fname, 'exec')
221 return code
224 """Execute code located at the specified filesystem location
237 # Not a valid sys.path entry, so run the code directly
239 code = _get_code_from_file(path_name)
240 return _run_module_code(code, init_globals, run_name, path_name)
248 # code was running and doing so was somewhat optional. Here, we
250 # code. If we don't do this, a __loader__ attribute in the
256 mod_name, loader, code, fname = _get_main_module_details()
263 return _run_code(code, mod_globals, init_globals,