| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 33824f6 commit 14e461d
22 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -235,7 +235,7 @@ in various ways. There is a separate error indicator for each thread. | |||
| 235 | 235 | ||
| 236 | 236 | Similar to :c:func:`PyErr_SetFromErrnoWithFilenameObject`, but the filename | |
| 237 | 237 | is given as a C string. *filename* is decoded from the filesystem encoding | |
| 238 | - (:func:`sys.getfilesystemencoding`). | ||
| 238 | + (:func:`os.fsdecode`). | ||
| 239 | 239 | ||
| 240 | 240 | ||
| 241 | 241 | .. c:function:: PyObject* PyErr_SetFromWindowsErr(int ierr) | |
@@ -267,7 +267,7 @@ in various ways. There is a separate error indicator for each thread. | |||
| 267 | 267 | ||
| 268 | 268 | Similar to :c:func:`PyErr_SetFromWindowsErrWithFilenameObject`, but the | |
| 269 | 269 | filename is given as a C string. *filename* is decoded from the filesystem | |
| 270 | - encoding (:func:`sys.getfilesystemencoding`). Availability: Windows. | ||
| 270 | + encoding (:func:`os.fsdecode`). Availability: Windows. | ||
| 271 | 271 | ||
| 272 | 272 | ||
| 273 | 273 | .. c:function:: PyObject* PyErr_SetExcFromWindowsErrWithFilenameObject(PyObject *type, int ierr, PyObject *filename) | |
@@ -293,20 +293,27 @@ in various ways. There is a separate error indicator for each thread. | |||
| 293 | 293 | .. versionadded:: 3.3 | |
| 294 | 294 | ||
| 295 | 295 | ||
| 296 | - .. c:function:: void PyErr_SyntaxLocationEx(char *filename, int lineno, int col_offset) | ||
| 296 | + .. c:function:: void PyErr_SyntaxLocationObject(PyObject *filename, int lineno, int col_offset) | ||
| 297 | 297 | ||
| 298 | 298 | Set file, line, and offset information for the current exception. If the | |
| 299 | 299 | current exception is not a :exc:`SyntaxError`, then it sets additional | |
| 300 | 300 | attributes, which make the exception printing subsystem think the exception | |
| 301 | - is a :exc:`SyntaxError`. *filename* is decoded from the filesystem encoding | ||
| 302 | - (:func:`sys.getfilesystemencoding`). | ||
| 301 | + is a :exc:`SyntaxError`. | ||
| 303 | 302 | ||
| 304 | - .. versionadded:: 3.2 | ||
| 303 | + .. versionadded:: 3.4 | ||
| 304 | + | ||
| 305 | + | ||
| 306 | + .. c:function:: void PyErr_SyntaxLocationEx(char *filename, int lineno, int col_offset) | ||
| 307 | + | ||
| 308 | + Like :c:func:`PyErr_SyntaxLocationObject`, but *filename* is a byte string | ||
| 309 | + decoded from the filesystem encoding (:func:`os.fsdecode`). | ||
| 310 | + | ||
| 311 | + .. versionadded:: 3.2 | ||
| 305 | 312 | ||
| 306 | 313 | ||
| 307 | 314 | .. c:function:: void PyErr_SyntaxLocation(char *filename, int lineno) | |
| 308 | 315 | ||
| 309 | - Like :c:func:`PyErr_SyntaxLocationExc`, but the col_offset parameter is | ||
| 316 | + Like :c:func:`PyErr_SyntaxLocationEx`, but the col_offset parameter is | ||
| 310 | 317 | omitted. | |
| 311 | 318 | ||
| 312 | 319 | ||
@@ -355,15 +362,22 @@ in various ways. There is a separate error indicator for each thread. | |||
| 355 | 362 | documentation. There is no C API for warning control. | |
| 356 | 363 | ||
| 357 | 364 | ||
| 358 | - .. c:function:: int PyErr_WarnExplicit(PyObject *category, const char *message, const char *filename, int lineno, const char *module, PyObject *registry) | ||
| 365 | + .. c:function:: int PyErr_WarnExplicitObject(PyObject *category, PyObject *message, PyObject *filename, int lineno, PyObject *module, PyObject *registry) | ||
| 359 | 366 | ||
| 360 | 367 | Issue a warning message with explicit control over all warning attributes. This | |
| 361 | 368 | is a straightforward wrapper around the Python function | |
| 362 | 369 | :func:`warnings.warn_explicit`, see there for more information. The *module* | |
| 363 | 370 | and *registry* arguments may be set to *NULL* to get the default effect | |
| 364 | - described there. *message* and *module* are UTF-8 encoded strings, | ||
| 365 | - *filename* is decoded from the filesystem encoding | ||
| 366 | - (:func:`sys.getfilesystemencoding`). | ||
| 371 | + described there. | ||
| 372 | + | ||
| 373 | + .. versionadded:: 3.4 | ||
| 374 | + | ||
| 375 | + | ||
| 376 | + .. c:function:: int PyErr_WarnExplicit(PyObject *category, const char *message, const char *filename, int lineno, const char *module, PyObject *registry) | ||
| 377 | + | ||
| 378 | + Similar to :c:func:`PyErr_WarnExplicitObject` except that *message* and | ||
| 379 | + *module* are UTF-8 encoded strings, and *filename* is decoded from the | ||
| 380 | + filesystem encoding (:func:`os.fsdecode`). | ||
| 367 | 381 | ||
| 368 | 382 | ||
| 369 | 383 | .. c:function:: int PyErr_WarnFormat(PyObject *category, Py_ssize_t stack_level, const char *format, ...) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -258,26 +258,32 @@ the same library that the Python runtime is using. | |||
| 258 | 258 | *optimize* set to ``-1``. | |
| 259 | 259 | ||
| 260 | 260 | ||
| 261 | - .. c:function:: PyObject* Py_CompileStringExFlags(const char *str, const char *filename, int start, PyCompilerFlags *flags, int optimize) | ||
| 261 | + .. c:function:: PyObject* Py_CompileStringObject(const char *str, PyObject *filename, int start, PyCompilerFlags *flags, int optimize) | ||
| 262 | 262 | ||
| 263 | 263 | Parse and compile the Python source code in *str*, returning the resulting code | |
| 264 | 264 | object. The start token is given by *start*; this can be used to constrain the | |
| 265 | 265 | code which can be compiled and should be :const:`Py_eval_input`, | |
| 266 | 266 | :const:`Py_file_input`, or :const:`Py_single_input`. The filename specified by | |
| 267 | 267 | *filename* is used to construct the code object and may appear in tracebacks or | |
| 268 | - :exc:`SyntaxError` exception messages, it is decoded from the filesystem | ||
| 269 | - encoding (:func:`sys.getfilesystemencoding`). This returns *NULL* if the | ||
| 270 | - code cannot be parsed or compiled. | ||
| 268 | + :exc:`SyntaxError` exception messages. This returns *NULL* if the code | ||
| 269 | + cannot be parsed or compiled. | ||
| 271 | 270 | ||
| 272 | 271 | The integer *optimize* specifies the optimization level of the compiler; a | |
| 273 | 272 | value of ``-1`` selects the optimization level of the interpreter as given by | |
| 274 | 273 | :option:`-O` options. Explicit levels are ``0`` (no optimization; | |
| 275 | 274 | ``__debug__`` is true), ``1`` (asserts are removed, ``__debug__`` is false) | |
| 276 | 275 | or ``2`` (docstrings are removed too). | |
| 277 | 276 | ||
| 278 | - .. versionadded:: 3.2 | ||
| 277 | + .. versionadded:: 3.4 | ||
| 279 | 278 | ||
| 280 | 279 | ||
| 280 | + .. c:function:: PyObject* Py_CompileStringExFlags(const char *str, const char *filename, int start, PyCompilerFlags *flags, int optimize) | ||
| 281 | + | ||
| 282 | + Like :c:func:`Py_CompileStringExFlags`, but *filename* is a byte string | ||
| 283 | + decoded from the filesystem encoding (:func:`os.fsdecode`). | ||
| 284 | + | ||
| 285 | + .. versionadded:: 3.2 | ||
| 286 | + | ||
| 281 | 287 | .. c:function:: PyObject* PyEval_EvalCode(PyObject *co, PyObject *globals, PyObject *locals) | |
| 282 | 288 | ||
| 283 | 289 | This is a simplified interface to :c:func:`PyEval_EvalCodeEx`, with just | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,6 +10,11 @@ PyAPI_FUNC(mod_ty) PyAST_FromNode( | |||
| 10 | 10 | PyCompilerFlags *flags, | |
| 11 | 11 | const char *filename, /* decoded from the filesystem encoding */ | |
| 12 | 12 | PyArena *arena); | |
| 13 | + PyAPI_FUNC(mod_ty) PyAST_FromNodeObject( | ||
| 14 | + const node *n, | ||
| 15 | + PyCompilerFlags *flags, | ||
| 16 | + PyObject *filename, | ||
| 17 | + PyArena *arena); | ||
| 13 | 18 | ||
| 14 | 19 | #ifdef __cplusplus | |
| 15 | 20 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -36,7 +36,20 @@ PyAPI_FUNC(PyCodeObject *) PyAST_CompileEx( | |||
| 36 | 36 | PyCompilerFlags *flags, | |
| 37 | 37 | int optimize, | |
| 38 | 38 | PyArena *arena); | |
| 39 | - PyAPI_FUNC(PyFutureFeatures *) PyFuture_FromAST(struct _mod *, const char *); | ||
| 39 | + PyAPI_FUNC(PyCodeObject *) PyAST_CompileObject( | ||
| 40 | + struct _mod *mod, | ||
| 41 | + PyObject *filename, | ||
| 42 | + PyCompilerFlags *flags, | ||
| 43 | + int optimize, | ||
| 44 | + PyArena *arena); | ||
| 45 | + PyAPI_FUNC(PyFutureFeatures *) PyFuture_FromAST( | ||
| 46 | + struct _mod * mod, | ||
| 47 | + const char *filename /* decoded from the filesystem encoding */ | ||
| 48 | + ); | ||
| 49 | + PyAPI_FUNC(PyFutureFeatures *) PyFuture_FromASTObject( | ||
| 50 | + struct _mod * mod, | ||
| 51 | + PyObject *filename | ||
| 52 | + ); | ||
| 40 | 53 | ||
| 41 | 54 | /* _Py_Mangle is defined in compile.c */ | |
| 42 | 55 | PyAPI_FUNC(PyObject*) _Py_Mangle(PyObject *p, PyObject *name); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -42,10 +42,16 @@ PyAPI_FUNC(node *) PyParser_ParseFile (FILE *, const char *, grammar *, int, | |||
| 42 | 42 | ||
| 43 | 43 | PyAPI_FUNC(node *) PyParser_ParseStringFlags(const char *, grammar *, int, | |
| 44 | 44 | perrdetail *, int); | |
| 45 | - PyAPI_FUNC(node *) PyParser_ParseFileFlags(FILE *, const char *, | ||
| 46 | - const char*, grammar *, | ||
| 47 | - int, char *, char *, | ||
| 48 | - perrdetail *, int); | ||
| 45 | + PyAPI_FUNC(node *) PyParser_ParseFileFlags( | ||
| 46 | + FILE *fp, | ||
| 47 | + const char *filename, /* decoded from the filesystem encoding */ | ||
| 48 | + const char *enc, | ||
| 49 | + grammar *g, | ||
| 50 | + int start, | ||
| 51 | + char *ps1, | ||
| 52 | + char *ps2, | ||
| 53 | + perrdetail *err_ret, | ||
| 54 | + int flags); | ||
| 49 | 55 | PyAPI_FUNC(node *) PyParser_ParseFileFlagsEx( | |
| 50 | 56 | FILE *fp, | |
| 51 | 57 | const char *filename, /* decoded from the filesystem encoding */ | |
@@ -56,18 +62,38 @@ PyAPI_FUNC(node *) PyParser_ParseFileFlagsEx( | |||
| 56 | 62 | char *ps2, | |
| 57 | 63 | perrdetail *err_ret, | |
| 58 | 64 | int *flags); | |
| 65 | + PyAPI_FUNC(node *) PyParser_ParseFileObject( | ||
| 66 | + FILE *fp, | ||
| 67 | + PyObject *filename, | ||
| 68 | + const char *enc, | ||
| 69 | + grammar *g, | ||
| 70 | + int start, | ||
| 71 | + char *ps1, | ||
| 72 | + char *ps2, | ||
| 73 | + perrdetail *err_ret, | ||
| 74 | + int *flags); | ||
| 59 | 75 | ||
| 60 | - PyAPI_FUNC(node *) PyParser_ParseStringFlagsFilename(const char *, | ||
| 61 | - const char *, | ||
| 62 | - grammar *, int, | ||
| 63 | - perrdetail *, int); | ||
| 76 | + PyAPI_FUNC(node *) PyParser_ParseStringFlagsFilename( | ||
| 77 | + const char *s, | ||
| 78 | + const char *filename, /* decoded from the filesystem encoding */ | ||
| 79 | + grammar *g, | ||
| 80 | + int start, | ||
| 81 | + perrdetail *err_ret, | ||
| 82 | + int flags); | ||
| 64 | 83 | PyAPI_FUNC(node *) PyParser_ParseStringFlagsFilenameEx( | |
| 65 | 84 | const char *s, | |
| 66 | 85 | const char *filename, /* decoded from the filesystem encoding */ | |
| 67 | 86 | grammar *g, | |
| 68 | 87 | int start, | |
| 69 | 88 | perrdetail *err_ret, | |
| 70 | 89 | int *flags); | |
| 90 | + PyAPI_FUNC(node *) PyParser_ParseStringObject( | ||
| 91 | + const char *s, | ||
| 92 | + PyObject *filename, | ||
| 93 | + grammar *g, | ||
| 94 | + int start, | ||
| 95 | + perrdetail *err_ret, | ||
| 96 | + int *flags); | ||
| 71 | 97 | ||
| 72 | 98 | /* Note that the following functions are defined in pythonrun.c, | |
| 73 | 99 | not in parsetok.c */ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -301,9 +301,16 @@ PyAPI_FUNC(void) PyErr_SyntaxLocationEx( | |||
| 301 | 301 | const char *filename, /* decoded from the filesystem encoding */ | |
| 302 | 302 | int lineno, | |
| 303 | 303 | int col_offset); | |
| 304 | + PyAPI_FUNC(void) PyErr_SyntaxLocationObject( | ||
| 305 | + PyObject *filename, | ||
| 306 | + int lineno, | ||
| 307 | + int col_offset); | ||
| 304 | 308 | PyAPI_FUNC(PyObject *) PyErr_ProgramText( | |
| 305 | 309 | const char *filename, /* decoded from the filesystem encoding */ | |
| 306 | 310 | int lineno); | |
| 311 | + PyAPI_FUNC(PyObject *) PyErr_ProgramTextObject( | ||
| 312 | + PyObject *filename, | ||
| 313 | + int lineno); | ||
| 307 | 314 | ||
| 308 | 315 | /* The following functions are used to create and modify unicode | |
| 309 | 316 | exceptions from C */ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -66,6 +66,12 @@ PyAPI_FUNC(struct _mod *) PyParser_ASTFromString( | |||
| 66 | 66 | int start, | |
| 67 | 67 | PyCompilerFlags *flags, | |
| 68 | 68 | PyArena *arena); | |
| 69 | + PyAPI_FUNC(struct _mod *) PyParser_ASTFromStringObject( | ||
| 70 | + const char *s, | ||
| 71 | + PyObject *filename, | ||
| 72 | + int start, | ||
| 73 | + PyCompilerFlags *flags, | ||
| 74 | + PyArena *arena); | ||
| 69 | 75 | PyAPI_FUNC(struct _mod *) PyParser_ASTFromFile( | |
| 70 | 76 | FILE *fp, | |
| 71 | 77 | const char *filename, /* decoded from the filesystem encoding */ | |
@@ -76,6 +82,16 @@ PyAPI_FUNC(struct _mod *) PyParser_ASTFromFile( | |||
| 76 | 82 | PyCompilerFlags *flags, | |
| 77 | 83 | int *errcode, | |
| 78 | 84 | PyArena *arena); | |
| 85 | + PyAPI_FUNC(struct _mod *) PyParser_ASTFromFileObject( | ||
| 86 | + FILE *fp, | ||
| 87 | + PyObject *filename, | ||
| 88 | + const char* enc, | ||
| 89 | + int start, | ||
| 90 | + char *ps1, | ||
| 91 | + char *ps2, | ||
| 92 | + PyCompilerFlags *flags, | ||
| 93 | + int *errcode, | ||
| 94 | + PyArena *arena); | ||
| 79 | 95 | #endif | |
| 80 | 96 | ||
| 81 | 97 | #ifndef PyParser_SimpleParseString | |
@@ -117,11 +133,20 @@ PyAPI_FUNC(PyObject *) Py_CompileStringExFlags( | |||
| 117 | 133 | int start, | |
| 118 | 134 | PyCompilerFlags *flags, | |
| 119 | 135 | int optimize); | |
| 136 | + PyAPI_FUNC(PyObject *) Py_CompileStringObject( | ||
| 137 | + const char *str, | ||
| 138 | + PyObject *filename, int start, | ||
| 139 | + PyCompilerFlags *flags, | ||
| 140 | + int optimize); | ||
| 120 | 141 | #endif | |
| 121 | 142 | PyAPI_FUNC(struct symtable *) Py_SymtableString( | |
| 122 | 143 | const char *str, | |
| 123 | 144 | const char *filename, /* decoded from the filesystem encoding */ | |
| 124 | 145 | int start); | |
| 146 | + PyAPI_FUNC(struct symtable *) Py_SymtableStringObject( | ||
| 147 | + const char *str, | ||
| 148 | + PyObject *filename, | ||
| 149 | + int start); | ||
| 125 | 150 | ||
| 126 | 151 | PyAPI_FUNC(void) PyErr_Print(void); | |
| 127 | 152 | PyAPI_FUNC(void) PyErr_PrintEx(int); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -16,7 +16,7 @@ typedef enum _block_type { FunctionBlock, ClassBlock, ModuleBlock } | |||
| 16 | 16 | struct _symtable_entry; | |
| 17 | 17 | ||
| 18 | 18 | struct symtable { | |
| 19 | - const char *st_filename; /* name of file being compiled, | ||
| 19 | + PyObject *st_filename; /* name of file being compiled, | ||
| 20 | 20 | decoded from the filesystem encoding */ | |
| 21 | 21 | struct _symtable_entry *st_cur; /* current symbol table entry */ | |
| 22 | 22 | struct _symtable_entry *st_top; /* symbol table entry for module */ | |
@@ -74,6 +74,10 @@ PyAPI_FUNC(struct symtable *) PySymtable_Build( | |||
| 74 | 74 | mod_ty mod, | |
| 75 | 75 | const char *filename, /* decoded from the filesystem encoding */ | |
| 76 | 76 | PyFutureFeatures *future); | |
| 77 | + PyAPI_FUNC(struct symtable *) PySymtable_BuildObject( | ||
| 78 | + mod_ty mod, | ||
| 79 | + PyObject *filename, | ||
| 80 | + PyFutureFeatures *future); | ||
| 77 | 81 | PyAPI_FUNC(PySTEntryObject *) PySymtable_Lookup(struct symtable *, void *); | |
| 78 | 82 | ||
| 79 | 83 | PyAPI_FUNC(void) PySymtable_Free(struct symtable *); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,6 +17,13 @@ PyAPI_FUNC(int) PyErr_WarnFormat( | |||
| 17 | 17 | Py_ssize_t stack_level, | |
| 18 | 18 | const char *format, /* ASCII-encoded string */ | |
| 19 | 19 | ...); | |
| 20 | + PyAPI_FUNC(int) PyErr_WarnExplicitObject( | ||
| 21 | + PyObject *category, | ||
| 22 | + PyObject *message, | ||
| 23 | + PyObject *filename, | ||
| 24 | + int lineno, | ||
| 25 | + PyObject *module, | ||
| 26 | + PyObject *registry); | ||
| 20 | 27 | PyAPI_FUNC(int) PyErr_WarnExplicit( | |
| 21 | 28 | PyObject *category, | |
| 22 | 29 | const char *message, /* UTF-8 encoded string */ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -22,7 +22,7 @@ | |||
| 22 | 22 | from test.support import ( | |
| 23 | 23 | EnvironmentVarGuard, TESTFN, check_warnings, forget, is_jython, | |
| 24 | 24 | make_legacy_pyc, rmtree, run_unittest, swap_attr, swap_item, temp_umask, | |
| 25 | - unlink, unload, create_empty_file, cpython_only) | ||
| 25 | + unlink, unload, create_empty_file, cpython_only, TESTFN_UNENCODABLE) | ||
| 26 | 26 | from test import script_helper | |
| 27 | 27 | ||
| 28 | 28 | ||
@@ -1055,6 +1055,14 @@ def load_module(*args): | |||
| 1055 | 1055 | finally: | |
| 1056 | 1056 | importlib.SourceLoader.load_module = old_load_module | |
| 1057 | 1057 | ||
| 1058 | + @unittest.skipUnless(TESTFN_UNENCODABLE, 'need TESTFN_UNENCODABLE') | ||
| 1059 | + def test_unencodable_filename(self): | ||
| 1060 | + # Issue #11619: The Python parser and the import machinery must not | ||
| 1061 | + # encode filenames, especially on Windows | ||
| 1062 | + pyname = script_helper.make_script('', TESTFN_UNENCODABLE, 'pass') | ||
| 1063 | + name = pyname[:-3] | ||
| 1064 | + script_helper.assert_python_ok("-c", "mod = __import__(%a)" % name) | ||
| 1065 | + | ||
| 1058 | 1066 | ||
| 1059 | 1067 | if __name__ == '__main__': | |
| 1060 | 1068 | # Test needs to be a package, so we can do relative imports. | |
| Back | FazBrowse Home | New Git URL |
0 commit comments