Fix loading of pyc files by ModuleFinder.load_module.
Resolves: rhbz#1060338
This commit is contained in:
parent
b8daf7369b
commit
bdf58d653f
@ -0,0 +1,65 @@
|
|||||||
|
|
||||||
|
# HG changeset patch
|
||||||
|
# User Brett Cannon <brett@python.org>
|
||||||
|
# Date 1393602285 18000
|
||||||
|
# Node ID 432cb56db05d73f55d211501bf0dfc767768923b
|
||||||
|
# Parent ade5e4922a54cb84c99ec924ab7c700a014893da
|
||||||
|
Issue #20778: Fix modulefinder to work with bytecode-only modules.
|
||||||
|
|
||||||
|
Bug filed and initial attempt at a patch by Bohuslav Kabrda.
|
||||||
|
|
||||||
|
diff --git a/Lib/modulefinder.py b/Lib/modulefinder.py
|
||||||
|
--- a/Lib/modulefinder.py
|
||||||
|
+++ b/Lib/modulefinder.py
|
||||||
|
@@ -287,7 +287,7 @@ class ModuleFinder:
|
||||||
|
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)
|
||||||
|
else:
|
||||||
|
co = None
|
||||||
|
diff --git a/Lib/test/test_modulefinder.py b/Lib/test/test_modulefinder.py
|
||||||
|
--- a/Lib/test/test_modulefinder.py
|
||||||
|
+++ b/Lib/test/test_modulefinder.py
|
||||||
|
@@ -1,5 +1,7 @@
|
||||||
|
import os
|
||||||
|
import errno
|
||||||
|
+import importlib.machinery
|
||||||
|
+import py_compile
|
||||||
|
import shutil
|
||||||
|
import unittest
|
||||||
|
import tempfile
|
||||||
|
@@ -208,6 +210,14 @@ a/module.py
|
||||||
|
from . import *
|
||||||
|
"""]
|
||||||
|
|
||||||
|
+bytecode_test = [
|
||||||
|
+ "a",
|
||||||
|
+ ["a"],
|
||||||
|
+ [],
|
||||||
|
+ [],
|
||||||
|
+ ""
|
||||||
|
+]
|
||||||
|
+
|
||||||
|
|
||||||
|
def open_file(path):
|
||||||
|
dirname = os.path.dirname(path)
|
||||||
|
@@ -288,6 +298,16 @@ class ModuleFinderTest(unittest.TestCase
|
||||||
|
def test_relative_imports_4(self):
|
||||||
|
self._do_test(relative_import_test_4)
|
||||||
|
|
||||||
|
+ def test_bytecode(self):
|
||||||
|
+ base_path = os.path.join(TEST_DIR, 'a')
|
||||||
|
+ source_path = base_path + importlib.machinery.SOURCE_SUFFIXES[0]
|
||||||
|
+ bytecode_path = base_path + importlib.machinery.BYTECODE_SUFFIXES[0]
|
||||||
|
+ with open_file(source_path) as file:
|
||||||
|
+ file.write('testing_modulefinder = True\n')
|
||||||
|
+ py_compile.compile(source_path, cfile=bytecode_path)
|
||||||
|
+ os.remove(source_path)
|
||||||
|
+ self._do_test(bytecode_test)
|
||||||
|
+
|
||||||
|
|
||||||
|
def test_main():
|
||||||
|
support.run_unittest(ModuleFinderTest)
|
14
python3.spec
14
python3.spec
@ -126,7 +126,7 @@
|
|||||||
Summary: Version 3 of the Python programming language aka Python 3000
|
Summary: Version 3 of the Python programming language aka Python 3000
|
||||||
Name: python3
|
Name: python3
|
||||||
Version: %{pybasever}.2
|
Version: %{pybasever}.2
|
||||||
Release: 11%{?dist}
|
Release: 12%{?dist}
|
||||||
License: Python
|
License: Python
|
||||||
Group: Development/Languages
|
Group: Development/Languages
|
||||||
|
|
||||||
@ -635,6 +635,13 @@ Patch187: 00187-change-match_hostname-to-follow-RFC-6125.patch
|
|||||||
# rhbz#1062375
|
# rhbz#1062375
|
||||||
Patch192: 00192-buffer-overflow.patch
|
Patch192: 00192-buffer-overflow.patch
|
||||||
|
|
||||||
|
# 00193
|
||||||
|
#
|
||||||
|
# Skip correct number of *.pyc file bytes in ModuleFinder.load_module
|
||||||
|
# rhbz#1060338
|
||||||
|
# http://bugs.python.org/issue20778
|
||||||
|
Patch193: 00193-skip-correct-num-of-pycfile-bytes-in-modulefinder.patch
|
||||||
|
|
||||||
|
|
||||||
# (New patches go here ^^^)
|
# (New patches go here ^^^)
|
||||||
#
|
#
|
||||||
@ -898,6 +905,7 @@ done
|
|||||||
%patch186 -p1
|
%patch186 -p1
|
||||||
%patch187 -p1
|
%patch187 -p1
|
||||||
%patch192 -p1
|
%patch192 -p1
|
||||||
|
%patch193 -p1
|
||||||
|
|
||||||
# Currently (2010-01-15), http://docs.python.org/library is for 2.6, and there
|
# Currently (2010-01-15), http://docs.python.org/library is for 2.6, and there
|
||||||
# are many differences between 2.6 and the Python 3 library.
|
# are many differences between 2.6 and the Python 3 library.
|
||||||
@ -1747,6 +1755,10 @@ rm -fr %{buildroot}
|
|||||||
# ======================================================
|
# ======================================================
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
* Wed Mar 05 2014 Bohuslav Kabrda <bkabrda@redhat.com> - 3.3.2-12
|
||||||
|
- Fix loading of pyc files by ModuleFinder.load_module.
|
||||||
|
Resolves: rhbz#1060338
|
||||||
|
|
||||||
* Wed Feb 19 2014 Bohuslav Kabrda <bkabrda@redhat.com> - 3.3.2-11
|
* Wed Feb 19 2014 Bohuslav Kabrda <bkabrda@redhat.com> - 3.3.2-11
|
||||||
- Enable loading sqlite extensions.
|
- Enable loading sqlite extensions.
|
||||||
Resolves: rhbz#1066938
|
Resolves: rhbz#1066938
|
||||||
|
Loading…
Reference in New Issue
Block a user