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

Side by Side Diff: Lib/modulefinder.py

Issue 20778: ModuleFinder.load_module skips incorrect number of bytes in pyc files
Patch Set: Created 6 years, 1 month 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 | « no previous file | Lib/test/test_modulefinder.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 """Find modules used by a script, using introspection.""" 1 """Find modules used by a script, using introspection."""
2 2
3 import dis 3 import dis
4 import importlib.machinery 4 import importlib.machinery
5 import marshal 5 import marshal
6 import os 6 import os
7 import sys 7 import sys
8 import types 8 import types
9 import struct 9 import struct
10 import warnings 10 import warnings
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 if type == imp.PKG_DIRECTORY: 283 if type == imp.PKG_DIRECTORY:
284 m = self.load_package(fqname, pathname) 284 m = self.load_package(fqname, pathname)
285 self.msgout(2, "load_module ->", m) 285 self.msgout(2, "load_module ->", m)
286 return m 286 return m
287 if type == imp.PY_SOURCE: 287 if type == imp.PY_SOURCE:
288 co = compile(fp.read()+'\n', pathname, 'exec') 288 co = compile(fp.read()+'\n', pathname, 'exec')
289 elif type == imp.PY_COMPILED: 289 elif type == imp.PY_COMPILED:
290 if fp.read(4) != imp.get_magic(): 290 if fp.read(4) != imp.get_magic():
291 self.msgout(2, "raise ImportError: Bad magic number", pathname) 291 self.msgout(2, "raise ImportError: Bad magic number", pathname)
292 raise ImportError("Bad magic number in %s" % pathname) 292 raise ImportError("Bad magic number in %s" % pathname)
293 fp.read(4) 293 fp.read(8) # skip date and file size
294 co = marshal.load(fp) 294 co = marshal.load(fp)
295 else: 295 else:
296 co = None 296 co = None
297 m = self.add_module(fqname) 297 m = self.add_module(fqname)
298 m.__file__ = pathname 298 m.__file__ = pathname
299 if co: 299 if co:
300 if self.replace_paths: 300 if self.replace_paths:
301 co = self.replace_paths_in_code(co) 301 co = self.replace_paths_in_code(co)
302 m.__code__ = co 302 m.__code__ = co
303 self.scan_code(co, m) 303 self.scan_code(co, m)
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 mf.run_script(script) 630 mf.run_script(script)
631 mf.report() 631 mf.report()
632 return mf # for -i debugging 632 return mf # for -i debugging
633 633
634 634
635 if __name__ == '__main__': 635 if __name__ == '__main__':
636 try: 636 try:
637 mf = test() 637 mf = test()
638 except KeyboardInterrupt: 638 except KeyboardInterrupt:
639 print("\n[interrupted]") 639 print("\n[interrupted]")
OLDNEW
« no previous file with comments | « no previous file | Lib/test/test_modulefinder.py » ('j') | no next file with comments »

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