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()
This commit is contained in:
Victor Stinner 2020-12-09 22:37:27 +01:00 committed by GitHub
parent ca06440207
commit a82f63f5af
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 106 additions and 53 deletions

View file

@ -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