summaryrefslogtreecommitdiff
path: root/Lib/_pyio.py
diff options
context:
space:
mode:
authorSteve Dower <steve.dower@microsoft.com>2019-05-23 08:45:22 -0700
committerGitHub <noreply@github.com>2019-05-23 08:45:22 -0700
commitb82e17e626f7b1cd98aada0b1ebb65cb9f8fb184 (patch)
tree5370a2a075707cb0b37ce135cad6ffe23da424c4 /Lib/_pyio.py
parente788057a9188ff37e232729815dfda2529079420 (diff)
downloadcpython-git-b82e17e626f7b1cd98aada0b1ebb65cb9f8fb184.tar.gz
bpo-36842: Implement PEP 578 (GH-12613)
Adds sys.audit, sys.addaudithook, io.open_code, and associated C APIs.
Diffstat (limited to 'Lib/_pyio.py')
-rw-r--r--Lib/_pyio.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/Lib/_pyio.py b/Lib/_pyio.py
index be5e4266da..5baca4df82 100644
--- a/Lib/_pyio.py
+++ b/Lib/_pyio.py
@@ -254,6 +254,29 @@ def open(file, mode="r", buffering=-1, encoding=None, errors=None,
result.close()
raise
+# Define a default pure-Python implementation for open_code()
+# that does not allow hooks. Warn on first use. Defined for tests.
+def _open_code_with_warning(path):
+ """Opens the provided file with mode ``'rb'``. This function
+ should be used when the intent is to treat the contents as
+ executable code.
+
+ ``path`` should be an absolute path.
+
+ When supported by the runtime, this function can be hooked
+ in order to allow embedders more control over code files.
+ This functionality is not supported on the current runtime.
+ """
+ import warnings
+ warnings.warn("_pyio.open_code() may not be using hooks",
+ RuntimeWarning, 2)
+ return open(path, "rb")
+
+try:
+ open_code = io.open_code
+except AttributeError:
+ open_code = _open_code_with_warning
+
class DocDescriptor:
"""Helper for builtins.open.__doc__