Issue 9599: Add PySys_FormatStdout and PySys_FormatStderr functions (original) (raw)

For my work #9425 (Rewrite import machinery to work with unicode paths), I need a function to write unicode strings to sys.stderr (especially to write messages on import in verbose mode). Attached patch creates PySys_FormatStdout() and PySys_FormatStderr(). It's the same idea than the new function PyErr_WarnFormat() vs PyErr_WarnEx() (added by r83976): similar API but use PyUnicode_FromFormatV().

PySys_FormatStdout() and PySys_FormatStderr() don't truncate the output message. PySys_WriteStdout() and PySys_WriteStderr() truncate the output because they use a static buffer of 1001 bytes, but I don't know if it is an implementation choice (to avoid bugs?) or just a limitation of the implementation.

About the patch:

For #9425, I only need PySys_FormatStderr(), but I added also PySys_FormatStdout() just to be consistent with PySys_Write*() and because it only costs a few line of code.