aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2020-12-09 22:37:27 +0100
committerGitHub <noreply@github.com>2020-12-09 22:37:27 +0100
commita82f63f5af027a0eab0f0812d750b804368cbd25 (patch)
treeaa8703c8745915d904d05ef132c1aa96fb1fd911 /Python/pylifecycle.c
parentbpo-32381: Remove unused _Py_fopen() function (GH-23711) (diff)
downloadcpython-a82f63f5af027a0eab0f0812d750b804368cbd25.tar.gz
cpython-a82f63f5af027a0eab0f0812d750b804368cbd25.tar.bz2
cpython-a82f63f5af027a0eab0f0812d750b804368cbd25.zip
bpo-32381: Add _PyRun_AnyFileObject() (GH-23723)
pymain_run_file() no longer encodes the filename: pass the filename as an object to the new _PyRun_AnyFileObject() function. Add new private functions: * _PyRun_AnyFileObject() * _PyRun_InteractiveLoopObject() * _Py_FdIsInteractive()
Diffstat (limited to 'Python/pylifecycle.c')
-rw-r--r--Python/pylifecycle.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
index 70824ff6741..6a705b4d2b4 100644
--- a/Python/pylifecycle.c
+++ b/Python/pylifecycle.c
@@ -2739,6 +2739,21 @@ Py_FdIsInteractive(FILE *fp, const char *filename)
}
+int
+_Py_FdIsInteractive(FILE *fp, PyObject *filename)
+{
+ if (isatty((int)fileno(fp))) {
+ return 1;
+ }
+ if (!Py_InteractiveFlag) {
+ return 0;
+ }
+ return (filename == NULL) ||
+ (PyUnicode_CompareWithASCIIString(filename, "<stdin>") == 0) ||
+ (PyUnicode_CompareWithASCIIString(filename, "???") == 0);
+}
+
+
/* Wrappers around sigaction() or signal(). */
PyOS_sighandler_t