summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_importlib/util.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_importlib/util.py')
-rw-r--r--Lib/test/test_importlib/util.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/Lib/test/test_importlib/util.py b/Lib/test/test_importlib/util.py
index 5aaf277..de6e0b0 100644
--- a/Lib/test/test_importlib/util.py
+++ b/Lib/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
@@ -118,6 +119,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.