Mercurial > cpython-lru_cache-weakref
comparison Python/pythonrun.c @ 65399:55ed5c524428
Issue #9713, #10114: Parser functions (eg. PyParser_ASTFromFile) expects
filenames encoded to the filesystem encoding with surrogateescape error handler
(to support undecodable bytes), instead of UTF-8 in strict mode.
| author | Victor Stinner <victor.stinner@haypocalc.com> |
|---|---|
| date | Sat, 16 Oct 2010 13:14:10 +0000 |
| parents | 453fd8182c2f |
| children | 9ed68dd6b71f |
comparison
equal
deleted
inserted
replaced
| 65398:76c888fd2380 | 65399:55ed5c524428 |
|---|---|
| 1211 if (m == NULL) | 1211 if (m == NULL) |
| 1212 return -1; | 1212 return -1; |
| 1213 d = PyModule_GetDict(m); | 1213 d = PyModule_GetDict(m); |
| 1214 if (PyDict_GetItemString(d, "__file__") == NULL) { | 1214 if (PyDict_GetItemString(d, "__file__") == NULL) { |
| 1215 PyObject *f; | 1215 PyObject *f; |
| 1216 f = PyUnicode_FromString(filename); | 1216 f = PyUnicode_DecodeFSDefault(filename); |
| 1217 if (f == NULL) | 1217 if (f == NULL) |
| 1218 return -1; | 1218 return -1; |
| 1219 if (PyDict_SetItemString(d, "__file__", f) < 0) { | 1219 if (PyDict_SetItemString(d, "__file__", f) < 0) { |
| 1220 Py_DECREF(f); | 1220 Py_DECREF(f); |
| 1221 return -1; | 1221 return -1; |
| 1966 static void | 1966 static void |
| 1967 err_input(perrdetail *err) | 1967 err_input(perrdetail *err) |
| 1968 { | 1968 { |
| 1969 PyObject *v, *w, *errtype, *errtext; | 1969 PyObject *v, *w, *errtype, *errtext; |
| 1970 PyObject *msg_obj = NULL; | 1970 PyObject *msg_obj = NULL; |
| 1971 PyObject *filename; | |
| 1971 char *msg = NULL; | 1972 char *msg = NULL; |
| 1973 | |
| 1972 errtype = PyExc_SyntaxError; | 1974 errtype = PyExc_SyntaxError; |
| 1973 switch (err->error) { | 1975 switch (err->error) { |
| 1974 case E_ERROR: | 1976 case E_ERROR: |
| 1975 return; | 1977 return; |
| 1976 case E_SYNTAX: | 1978 case E_SYNTAX: |
| 2050 Py_INCREF(Py_None); | 2052 Py_INCREF(Py_None); |
| 2051 } else { | 2053 } else { |
| 2052 errtext = PyUnicode_DecodeUTF8(err->text, strlen(err->text), | 2054 errtext = PyUnicode_DecodeUTF8(err->text, strlen(err->text), |
| 2053 "replace"); | 2055 "replace"); |
| 2054 } | 2056 } |
| 2055 v = Py_BuildValue("(ziiN)", err->filename, | 2057 filename = PyUnicode_DecodeFSDefault(err->filename); |
| 2056 err->lineno, err->offset, errtext); | 2058 if (filename != NULL) |
| 2059 v = Py_BuildValue("(NiiN)", filename, | |
| 2060 err->lineno, err->offset, errtext); | |
| 2061 else | |
| 2062 v = NULL; | |
| 2057 if (v != NULL) { | 2063 if (v != NULL) { |
| 2058 if (msg_obj) | 2064 if (msg_obj) |
| 2059 w = Py_BuildValue("(OO)", msg_obj, v); | 2065 w = Py_BuildValue("(OO)", msg_obj, v); |
| 2060 else | 2066 else |
| 2061 w = Py_BuildValue("(sO)", msg, v); | 2067 w = Py_BuildValue("(sO)", msg, v); |
