Mercurial > cpython-lru_cache-weakref
comparison Python/future.c @ 85417:df2fdd42b375
Close #11619: The parser and the import machinery do not encode Unicode
filenames anymore on Windows.
| author | Victor Stinner <victor.stinner@gmail.com> |
|---|---|
| date | Mon, 26 Aug 2013 22:28:21 +0200 |
| parents | 0e253370863f |
| children |
comparison
equal
deleted
inserted
replaced
| 85416:8fb3a6f9b0a4 | 85417:df2fdd42b375 |
|---|---|
| 9 #define UNDEFINED_FUTURE_FEATURE "future feature %.100s is not defined" | 9 #define UNDEFINED_FUTURE_FEATURE "future feature %.100s is not defined" |
| 10 #define ERR_LATE_FUTURE \ | 10 #define ERR_LATE_FUTURE \ |
| 11 "from __future__ imports must occur at the beginning of the file" | 11 "from __future__ imports must occur at the beginning of the file" |
| 12 | 12 |
| 13 static int | 13 static int |
| 14 future_check_features(PyFutureFeatures *ff, stmt_ty s, const char *filename) | 14 future_check_features(PyFutureFeatures *ff, stmt_ty s, PyObject *filename) |
| 15 { | 15 { |
| 16 int i; | 16 int i; |
| 17 asdl_seq *names; | 17 asdl_seq *names; |
| 18 | 18 |
| 19 assert(s->kind == ImportFrom_kind); | 19 assert(s->kind == ImportFrom_kind); |
| 41 } else if (strcmp(feature, FUTURE_BARRY_AS_BDFL) == 0) { | 41 } else if (strcmp(feature, FUTURE_BARRY_AS_BDFL) == 0) { |
| 42 ff->ff_features |= CO_FUTURE_BARRY_AS_BDFL; | 42 ff->ff_features |= CO_FUTURE_BARRY_AS_BDFL; |
| 43 } else if (strcmp(feature, "braces") == 0) { | 43 } else if (strcmp(feature, "braces") == 0) { |
| 44 PyErr_SetString(PyExc_SyntaxError, | 44 PyErr_SetString(PyExc_SyntaxError, |
| 45 "not a chance"); | 45 "not a chance"); |
| 46 PyErr_SyntaxLocationEx(filename, s->lineno, s->col_offset); | 46 PyErr_SyntaxLocationObject(filename, s->lineno, s->col_offset); |
| 47 return 0; | 47 return 0; |
| 48 } else { | 48 } else { |
| 49 PyErr_Format(PyExc_SyntaxError, | 49 PyErr_Format(PyExc_SyntaxError, |
| 50 UNDEFINED_FUTURE_FEATURE, feature); | 50 UNDEFINED_FUTURE_FEATURE, feature); |
| 51 PyErr_SyntaxLocationEx(filename, s->lineno, s->col_offset); | 51 PyErr_SyntaxLocationObject(filename, s->lineno, s->col_offset); |
| 52 return 0; | 52 return 0; |
| 53 } | 53 } |
| 54 } | 54 } |
| 55 return 1; | 55 return 1; |
| 56 } | 56 } |
| 57 | 57 |
| 58 static int | 58 static int |
| 59 future_parse(PyFutureFeatures *ff, mod_ty mod, const char *filename) | 59 future_parse(PyFutureFeatures *ff, mod_ty mod, PyObject *filename) |
| 60 { | 60 { |
| 61 int i, done = 0, prev_line = 0; | 61 int i, done = 0, prev_line = 0; |
| 62 stmt_ty first; | 62 stmt_ty first; |
| 63 | 63 |
| 64 if (!(mod->kind == Module_kind || mod->kind == Interactive_kind)) | 64 if (!(mod->kind == Module_kind || mod->kind == Interactive_kind)) |
| 99 if (modname && | 99 if (modname && |
| 100 !PyUnicode_CompareWithASCIIString(modname, "__future__")) { | 100 !PyUnicode_CompareWithASCIIString(modname, "__future__")) { |
| 101 if (done) { | 101 if (done) { |
| 102 PyErr_SetString(PyExc_SyntaxError, | 102 PyErr_SetString(PyExc_SyntaxError, |
| 103 ERR_LATE_FUTURE); | 103 ERR_LATE_FUTURE); |
| 104 PyErr_SyntaxLocationEx(filename, s->lineno, s->col_offset); | 104 PyErr_SyntaxLocationObject(filename, s->lineno, s->col_offset); |
| 105 return 0; | 105 return 0; |
| 106 } | 106 } |
| 107 if (!future_check_features(ff, s, filename)) | 107 if (!future_check_features(ff, s, filename)) |
| 108 return 0; | 108 return 0; |
| 109 ff->ff_lineno = s->lineno; | 109 ff->ff_lineno = s->lineno; |
| 119 return 1; | 119 return 1; |
| 120 } | 120 } |
| 121 | 121 |
| 122 | 122 |
| 123 PyFutureFeatures * | 123 PyFutureFeatures * |
| 124 PyFuture_FromAST(mod_ty mod, const char *filename) | 124 PyFuture_FromASTObject(mod_ty mod, PyObject *filename) |
| 125 { | 125 { |
| 126 PyFutureFeatures *ff; | 126 PyFutureFeatures *ff; |
| 127 | 127 |
| 128 ff = (PyFutureFeatures *)PyObject_Malloc(sizeof(PyFutureFeatures)); | 128 ff = (PyFutureFeatures *)PyObject_Malloc(sizeof(PyFutureFeatures)); |
| 129 if (ff == NULL) { | 129 if (ff == NULL) { |
| 137 PyObject_Free(ff); | 137 PyObject_Free(ff); |
| 138 return NULL; | 138 return NULL; |
| 139 } | 139 } |
| 140 return ff; | 140 return ff; |
| 141 } | 141 } |
| 142 | |
| 143 | |
| 144 PyFutureFeatures * | |
| 145 PyFuture_FromAST(mod_ty mod, const char *filename_str) | |
| 146 { | |
| 147 PyFutureFeatures *ff; | |
| 148 PyObject *filename; | |
| 149 | |
| 150 filename = PyUnicode_DecodeFSDefault(filename_str); | |
| 151 if (filename == NULL) | |
| 152 return NULL; | |
| 153 ff = PyFuture_FromASTObject(mod, filename); | |
| 154 Py_DECREF(filename); | |
| 155 return ff; | |
| 156 } |
