aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib-python/3/test/test_importlib/util.py')
-rw-r--r--lib-python/3/test/test_importlib/util.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/lib-python/3/test/test_importlib/util.py b/lib-python/3/test/test_importlib/util.py
index a26f3119fd..fb86d77dd0 100644
--- a/lib-python/3/test/test_importlib/util.py
+++ b/lib-python/3/test/test_importlib/util.py
@@ -7,6 +7,7 @@ import importlib
from importlib import machinery, util, invalidate_caches
from importlib.abc import ResourceReader
import io
+import marshal
import os
import os.path
from pathlib import Path, PurePath
@@ -123,6 +124,16 @@ def submodule(parent, name, pkg_dir, content=''):
return '{}.{}'.format(parent, name), path
+def _get_code_from_pyc(pyc_path):
+ """Reads a pyc file and returns the unmarshalled code object within.
+
+ No header validation is performed.
+ """
+ with open(pyc_path, 'rb') as pyc_f:
+ pyc_f.seek(16)
+ return marshal.load(pyc_f)
+
+
@contextlib.contextmanager
def uncache(*names):
"""Uncache a module from sys.modules.