merge for issue #20778
authorBrett Cannon <brett@python.org>
Fri, 28 Feb 2014 15:50:34 +0000 (10:50 -0500)
committerBrett Cannon <brett@python.org>
Fri, 28 Feb 2014 15:50:34 +0000 (10:50 -0500)
1  2 
Lib/modulefinder.py
Misc/NEWS

index b19941e61e82bdde3616650c5e371b04738a9b28,264b0f0bfd1f58e941d3fa2c49235c193de94fe0..cc5b8cc691137b84e7abddb7187a45fb915261bf
@@@ -1,6 -1,7 +1,7 @@@
  """Find modules used by a script, using introspection."""
  
  import dis
 -import imp
++import importlib._bootstrap
  import importlib.machinery
  import marshal
  import os
@@@ -287,11 -284,11 +288,12 @@@ class ModuleFinder
          if type == imp.PY_SOURCE:
              co = compile(fp.read()+'\n', pathname, 'exec')
          elif type == imp.PY_COMPILED:
--            if fp.read(4) != imp.get_magic():
--                self.msgout(2, "raise ImportError: Bad magic number", pathname)
--                raise ImportError("Bad magic number in %s" % pathname)
-             fp.read(4)
 -            fp.read(8)  # Skip mtime and size.
--            co = marshal.load(fp)
++            try:
++                marshal_data = importlib._bootstrap._validate_bytecode_header(fp.read())
++            except ImportError as exc:
++                self.msgout(2, "raise ImportError: " + str(exc), pathname)
++                raise
++            co = marshal.loads(marshal_data)
          else:
              co = None
          m = self.add_module(fqname)
diff --cc Misc/NEWS
Simple merge