Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(5)

Side by Side Diff: Lib/runpy.py

Issue 10639: reindent.py converts newlines to platform default
Patch Set: Created 8 years, 8 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/random.py ('k') | Lib/shutil.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 """runpy.py - locating and running Python code using the module namespace 1 """runpy.py - locating and running Python code using the module namespace
2 2
3 Provides support for locating and running Python scripts using the Python 3 Provides support for locating and running Python scripts using the Python
4 module namespace instead of the native filesystem. 4 module namespace instead of the native filesystem.
5 5
6 This allows Python code to play nicely with non-filesystem based PEP 302 6 This allows Python code to play nicely with non-filesystem based PEP 302
7 importers when locating support scripts as well as when importing modules. 7 importers when locating support scripts as well as when importing modules.
8 """ 8 """
9 # Written by Nick Coghlan <ncoghlan at gmail.com> 9 # Written by Nick Coghlan <ncoghlan at gmail.com>
10 # to implement PEP 338 (Executing Modules as Scripts) 10 # to implement PEP 338 (Executing Modules as Scripts)
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 return None 219 return None
220 cache[path_name] = importer 220 cache[path_name] = importer
221 return importer 221 return importer
222 222
223 def _get_code_from_file(fname): 223 def _get_code_from_file(fname):
224 # Check for a compiled file first 224 # Check for a compiled file first
225 with open(fname, "rb") as f: 225 with open(fname, "rb") as f:
226 code = read_code(f) 226 code = read_code(f)
227 if code is None: 227 if code is None:
228 # That didn't work, so try it as normal source code 228 # That didn't work, so try it as normal source code
229 with open(fname, "rb") as f: 229 with open(fname, "r") as f:
230 code = compile(f.read(), fname, 'exec') 230 code = compile(f.read(), fname, 'exec')
231 return code 231 return code
232 232
233 def run_path(path_name, init_globals=None, run_name=None): 233 def run_path(path_name, init_globals=None, run_name=None):
234 """Execute code located at the specified filesystem location 234 """Execute code located at the specified filesystem location
235 235
236 Returns the resulting top level namespace dictionary 236 Returns the resulting top level namespace dictionary
237 237
238 The file path may refer directly to a Python script (i.e. 238 The file path may refer directly to a Python script (i.e.
239 one that could be directly executed with execfile) or else 239 one that could be directly executed with execfile) or else
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 pass 279 pass
280 280
281 281
282 if __name__ == "__main__": 282 if __name__ == "__main__":
283 # Run the module specified as the next command line argument 283 # Run the module specified as the next command line argument
284 if len(sys.argv) < 2: 284 if len(sys.argv) < 2:
285 print("No module specified for execution", file=sys.stderr) 285 print("No module specified for execution", file=sys.stderr)
286 else: 286 else:
287 del sys.argv[0] # Make the requested module sys.argv[0] 287 del sys.argv[0] # Make the requested module sys.argv[0]
288 _run_module_as_main(sys.argv[0]) 288 _run_module_as_main(sys.argv[0])
OLDNEW
« no previous file with comments | « Lib/random.py ('k') | Lib/shutil.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+