| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 0cb3e86 commit 3c60833
12 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -49,6 +49,7 @@ typedef struct { | |||
| 49 | 49 | #define CO_FUTURE_ABSOLUTE_IMPORT 0x4000 /* do absolute imports by default */ | |
| 50 | 50 | #define CO_FUTURE_WITH_STATEMENT 0x8000 | |
| 51 | 51 | #define CO_FUTURE_PRINT_FUNCTION 0x10000 | |
| 52 | + #define CO_FUTURE_UNICODE_LITERALS 0x20000 | ||
| 52 | 53 | ||
| 53 | 54 | /* This should be defined if a future statement modifies the syntax. | |
| 54 | 55 | For example, when a keyword is added. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -25,6 +25,7 @@ typedef struct { | |||
| 25 | 25 | #define FUTURE_ABSOLUTE_IMPORT "absolute_import" | |
| 26 | 26 | #define FUTURE_WITH_STATEMENT "with_statement" | |
| 27 | 27 | #define FUTURE_PRINT_FUNCTION "print_function" | |
| 28 | + #define FUTURE_UNICODE_LITERALS "unicode_literals" | ||
| 28 | 29 | ||
| 29 | 30 | ||
| 30 | 31 | struct _mod; /* Declare the existence of this type */ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -28,6 +28,7 @@ typedef struct { | |||
| 28 | 28 | #endif | |
| 29 | 29 | ||
| 30 | 30 | #define PyPARSE_PRINT_IS_FUNCTION 0x0004 | |
| 31 | + #define PyPARSE_UNICODE_LITERALS 0x0008 | ||
| 31 | 32 | ||
| 32 | 33 | ||
| 33 | 34 | ||
@@ -41,11 +42,18 @@ PyAPI_FUNC(node *) PyParser_ParseStringFlags(const char *, grammar *, int, | |||
| 41 | 42 | PyAPI_FUNC(node *) PyParser_ParseFileFlags(FILE *, const char *, grammar *, | |
| 42 | 43 | int, char *, char *, | |
| 43 | 44 | perrdetail *, int); | |
| 45 | + PyAPI_FUNC(node *) PyParser_ParseFileFlagsEx(FILE *, const char *, grammar *, | ||
| 46 | + int, char *, char *, | ||
| 47 | + perrdetail *, int *); | ||
| 44 | 48 | ||
| 45 | 49 | PyAPI_FUNC(node *) PyParser_ParseStringFlagsFilename(const char *, | |
| 46 | 50 | const char *, | |
| 47 | 51 | grammar *, int, | |
| 48 | 52 | perrdetail *, int); | |
| 53 | + PyAPI_FUNC(node *) PyParser_ParseStringFlagsFilenameEx(const char *, | ||
| 54 | + const char *, | ||
| 55 | + grammar *, int, | ||
| 56 | + perrdetail *, int *); | ||
| 49 | 57 | ||
| 50 | 58 | /* Note that he following function is defined in pythonrun.c not parsetok.c. */ | |
| 51 | 59 | PyAPI_FUNC(void) PyParser_SetError(perrdetail *); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,7 +8,8 @@ extern "C" { | |||
| 8 | 8 | #endif | |
| 9 | 9 | ||
| 10 | 10 | #define PyCF_MASK (CO_FUTURE_DIVISION | CO_FUTURE_ABSOLUTE_IMPORT | \ | |
| 11 | - CO_FUTURE_WITH_STATEMENT|CO_FUTURE_PRINT_FUNCTION) | ||
| 11 | + CO_FUTURE_WITH_STATEMENT | CO_FUTURE_PRINT_FUNCTION | \ | ||
| 12 | + CO_FUTURE_UNICODE_LITERALS) | ||
| 12 | 13 | #define PyCF_MASK_OBSOLETE (CO_NESTED) | |
| 13 | 14 | #define PyCF_SOURCE_IS_UTF8 0x0100 | |
| 14 | 15 | #define PyCF_DONT_IMPLY_DEDENT 0x0200 | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -54,6 +54,7 @@ | |||
| 54 | 54 | "absolute_import", | |
| 55 | 55 | "with_statement", | |
| 56 | 56 | "print_function", | |
| 57 | + "unicode_literals", | ||
| 57 | 58 | ] | |
| 58 | 59 | ||
| 59 | 60 | __all__ = ["all_feature_names"] + all_feature_names | |
@@ -68,6 +69,7 @@ | |||
| 68 | 69 | CO_FUTURE_ABSOLUTE_IMPORT = 0x4000 # perform absolute imports by default | |
| 69 | 70 | CO_FUTURE_WITH_STATEMENT = 0x8000 # with statement | |
| 70 | 71 | CO_FUTURE_PRINT_FUNCTION = 0x10000 # print function | |
| 72 | + CO_FUTURE_UNICODE_LITERALS = 0x20000 # unicode string literals | ||
| 71 | 73 | ||
| 72 | 74 | class _Feature: | |
| 73 | 75 | def __init__(self, optionalRelease, mandatoryRelease, compiler_flag): | |
@@ -120,3 +122,7 @@ def __repr__(self): | |||
| 120 | 122 | print_function = _Feature((2, 6, 0, "alpha", 2), | |
| 121 | 123 | (3, 0, 0, "alpha", 0), | |
| 122 | 124 | CO_FUTURE_PRINT_FUNCTION) | |
| 125 | + | ||
| 126 | + unicode_literals = _Feature((2, 6, 0, "alpha", 2), | ||
| 127 | + (3, 0, 0, "alpha", 0), | ||
| 128 | + CO_FUTURE_UNICODE_LITERALS) | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -12,6 +12,8 @@ What's New in Python 2.6 alpha 2? | |||
| 12 | 12 | Core and builtins | |
| 13 | 13 | ----------------- | |
| 14 | 14 | ||
| 15 | + - Patch #2477: Added from __future__ import unicode_literals | ||
| 16 | + | ||
| 15 | 17 | - Added backport of bytearray type. | |
| 16 | 18 | ||
| 17 | 19 | - Issue #2355: add Py3k warning for buffer(). | |
@@ -186,6 +188,12 @@ Build | |||
| 186 | 188 | ||
| 187 | 189 | - Patch #2284: Add -x64 option to rt.bat. | |
| 188 | 190 | ||
| 191 | + C API | ||
| 192 | + ----- | ||
| 193 | + | ||
| 194 | + - Patch #2477: Added PyParser_ParseFileFlagsEx() and | ||
| 195 | + PyParser_ParseStringFlagsFilenameEx() | ||
| 196 | + | ||
| 189 | 197 | What's New in Python 2.6 alpha 1? | |
| 190 | 198 | ================================= | |
| 191 | 199 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -202,14 +202,18 @@ future_hack(parser_state *ps) | |||
| 202 | 202 | ||
| 203 | 203 | for (i = 0; i < NCH(ch); i += 2) { | |
| 204 | 204 | cch = CHILD(ch, i); | |
| 205 | - if (NCH(cch) >= 1 && TYPE(CHILD(cch, 0)) == NAME && | ||
| 206 | - strcmp(STR(CHILD(cch, 0)), "with_statement") == 0) { | ||
| 207 | - ps->p_flags |= CO_FUTURE_WITH_STATEMENT; | ||
| 208 | - break; | ||
| 209 | - } else if (NCH(cch) >= 1 && TYPE(CHILD(cch, 0)) == NAME && | ||
| 210 | - strcmp(STR(CHILD(cch, 0)), "print_function") == 0) { | ||
| 211 | - ps->p_flags |= CO_FUTURE_PRINT_FUNCTION; | ||
| 212 | - break; | ||
| 205 | + if (NCH(cch) >= 1 && TYPE(CHILD(cch, 0)) == NAME) { | ||
| 206 | + char *str_ch = STR(CHILD(cch, 0)); | ||
| 207 | + if (strcmp(str_ch, FUTURE_WITH_STATEMENT) == 0) { | ||
| 208 | + ps->p_flags |= CO_FUTURE_WITH_STATEMENT; | ||
| 209 | + break; | ||
| 210 | + } else if (strcmp(str_ch, FUTURE_PRINT_FUNCTION) == 0) { | ||
| 211 | + ps->p_flags |= CO_FUTURE_PRINT_FUNCTION; | ||
| 212 | + break; | ||
| 213 | + } else if (strcmp(str_ch, FUTURE_UNICODE_LITERALS) == 0) { | ||
| 214 | + ps->p_flags |= CO_FUTURE_UNICODE_LITERALS; | ||
| 215 | + break; | ||
| 216 | + } | ||
| 213 | 217 | } | |
| 214 | 218 | } | |
| 215 | 219 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,7 +14,7 @@ int Py_TabcheckFlag; | |||
| 14 | 14 | ||
| 15 | 15 | ||
| 16 | 16 | /* Forward */ | |
| 17 | - static node *parsetok(struct tok_state *, grammar *, int, perrdetail *, int); | ||
| 17 | + static node *parsetok(struct tok_state *, grammar *, int, perrdetail *, int *); | ||
| 18 | 18 | static void initerr(perrdetail *err_ret, const char* filename); | |
| 19 | 19 | ||
| 20 | 20 | /* Parse input coming from a string. Return error code, print some errors. */ | |
@@ -36,6 +36,16 @@ node * | |||
| 36 | 36 | PyParser_ParseStringFlagsFilename(const char *s, const char *filename, | |
| 37 | 37 | grammar *g, int start, | |
| 38 | 38 | perrdetail *err_ret, int flags) | |
| 39 | + { | ||
| 40 | + int iflags = flags; | ||
| 41 | + return PyParser_ParseStringFlagsFilenameEx(s, filename, g, start, | ||
| 42 | + err_ret, &iflags); | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + node * | ||
| 46 | + PyParser_ParseStringFlagsFilenameEx(const char *s, const char *filename, | ||
| 47 | + grammar *g, int start, | ||
| 48 | + perrdetail *err_ret, int *flags) | ||
| 39 | 49 | { | |
| 40 | 50 | struct tok_state *tok; | |
| 41 | 51 | ||
@@ -69,6 +79,14 @@ PyParser_ParseFile(FILE *fp, const char *filename, grammar *g, int start, | |||
| 69 | 79 | node * | |
| 70 | 80 | PyParser_ParseFileFlags(FILE *fp, const char *filename, grammar *g, int start, | |
| 71 | 81 | char *ps1, char *ps2, perrdetail *err_ret, int flags) | |
| 82 | + { | ||
| 83 | + int iflags = flags; | ||
| 84 | + return PyParser_ParseFileFlagsEx(fp, filename, g, start, ps1, ps2, err_ret, &iflags); | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + node * | ||
| 88 | + PyParser_ParseFileFlagsEx(FILE *fp, const char *filename, grammar *g, int start, | ||
| 89 | + char *ps1, char *ps2, perrdetail *err_ret, int *flags) | ||
| 72 | 90 | { | |
| 73 | 91 | struct tok_state *tok; | |
| 74 | 92 | ||
@@ -85,7 +103,6 @@ PyParser_ParseFileFlags(FILE *fp, const char *filename, grammar *g, int start, | |||
| 85 | 103 | tok->alterror++; | |
| 86 | 104 | } | |
| 87 | 105 | ||
| 88 | - | ||
| 89 | 106 | return parsetok(tok, g, start, err_ret, flags); | |
| 90 | 107 | } | |
| 91 | 108 | ||
@@ -110,7 +127,7 @@ warn(const char *msg, const char *filename, int lineno) | |||
| 110 | 127 | ||
| 111 | 128 | static node * | |
| 112 | 129 | parsetok(struct tok_state *tok, grammar *g, int start, perrdetail *err_ret, | |
| 113 | - int flags) | ||
| 130 | + int *flags) | ||
| 114 | 131 | { | |
| 115 | 132 | parser_state *ps; | |
| 116 | 133 | node *n; | |
@@ -123,8 +140,13 @@ parsetok(struct tok_state *tok, grammar *g, int start, perrdetail *err_ret, | |||
| 123 | 140 | return NULL; | |
| 124 | 141 | } | |
| 125 | 142 | #ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD | |
| 126 | - if (flags & PyPARSE_PRINT_IS_FUNCTION) | ||
| 143 | + if (*flags & PyPARSE_PRINT_IS_FUNCTION) { | ||
| 127 | 144 | ps->p_flags |= CO_FUTURE_PRINT_FUNCTION; | |
| 145 | + } | ||
| 146 | + if (*flags & PyPARSE_UNICODE_LITERALS) { | ||
| 147 | + ps->p_flags |= CO_FUTURE_UNICODE_LITERALS; | ||
| 148 | + } | ||
| 149 | + | ||
| 128 | 150 | #endif | |
| 129 | 151 | ||
| 130 | 152 | for (;;) { | |
@@ -147,7 +169,7 @@ parsetok(struct tok_state *tok, grammar *g, int start, perrdetail *err_ret, | |||
| 147 | 169 | except if a certain flag is given -- | |
| 148 | 170 | codeop.py uses this. */ | |
| 149 | 171 | if (tok->indent && | |
| 150 | - !(flags & PyPARSE_DONT_IMPLY_DEDENT)) | ||
| 172 | + !(*flags & PyPARSE_DONT_IMPLY_DEDENT)) | ||
| 151 | 173 | { | |
| 152 | 174 | tok->pendin = -tok->indent; | |
| 153 | 175 | tok->indent = 0; | |
@@ -191,6 +213,7 @@ parsetok(struct tok_state *tok, grammar *g, int start, perrdetail *err_ret, | |||
| 191 | 213 | else | |
| 192 | 214 | n = NULL; | |
| 193 | 215 | ||
| 216 | + *flags = ps->p_flags; | ||
| 194 | 217 | PyParser_Delete(ps); | |
| 195 | 218 | ||
| 196 | 219 | if (n == NULL) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,6 +18,7 @@ | |||
| 18 | 18 | /* Data structure used internally */ | |
| 19 | 19 | struct compiling { | |
| 20 | 20 | char *c_encoding; /* source encoding */ | |
| 21 | + int c_future_unicode; /* __future__ unicode literals flag */ | ||
| 21 | 22 | PyArena *c_arena; /* arena for allocating memeory */ | |
| 22 | 23 | const char *c_filename; /* filename */ | |
| 23 | 24 | }; | |
@@ -36,7 +37,7 @@ static expr_ty ast_for_testlist_gexp(struct compiling *, const node *); | |||
| 36 | 37 | static expr_ty ast_for_call(struct compiling *, const node *, expr_ty); | |
| 37 | 38 | ||
| 38 | 39 | static PyObject *parsenumber(const char *); | |
| 39 | - static PyObject *parsestr(const char *s, const char *encoding); | ||
| 40 | + static PyObject *parsestr(struct compiling *, const char *); | ||
| 40 | 41 | static PyObject *parsestrplus(struct compiling *, const node *n); | |
| 41 | 42 | ||
| 42 | 43 | #ifndef LINENO | |
@@ -198,6 +199,7 @@ PyAST_FromNode(const node *n, PyCompilerFlags *flags, const char *filename, | |||
| 198 | 199 | } else { | |
| 199 | 200 | c.c_encoding = NULL; | |
| 200 | 201 | } | |
| 202 | + c.c_future_unicode = flags && flags->cf_flags & CO_FUTURE_UNICODE_LITERALS; | ||
| 201 | 203 | c.c_arena = arena; | |
| 202 | 204 | c.c_filename = filename; | |
| 203 | 205 | ||
@@ -3247,13 +3249,13 @@ decode_unicode(const char *s, size_t len, int rawmode, const char *encoding) | |||
| 3247 | 3249 | * parsestr parses it, and returns the decoded Python string object. | |
| 3248 | 3250 | */ | |
| 3249 | 3251 | static PyObject * | |
| 3250 | - parsestr(const char *s, const char *encoding) | ||
| 3252 | + parsestr(struct compiling *c, const char *s) | ||
| 3251 | 3253 | { | |
| 3252 | 3254 | size_t len; | |
| 3253 | 3255 | int quote = Py_CHARMASK(*s); | |
| 3254 | 3256 | int rawmode = 0; | |
| 3255 | 3257 | int need_encoding; | |
| 3256 | - int unicode = 0; | ||
| 3258 | + int unicode = c->c_future_unicode; | ||
| 3257 | 3259 | ||
| 3258 | 3260 | if (isalpha(quote) || quote == '_') { | |
| 3259 | 3261 | if (quote == 'u' || quote == 'U') { | |
@@ -3262,6 +3264,7 @@ parsestr(const char *s, const char *encoding) | |||
| 3262 | 3264 | } | |
| 3263 | 3265 | if (quote == 'b' || quote == 'B') { | |
| 3264 | 3266 | quote = *++s; | |
| 3267 | + unicode = 0; | ||
| 3265 | 3268 | } | |
| 3266 | 3269 | if (quote == 'r' || quote == 'R') { | |
| 3267 | 3270 | quote = *++s; | |
@@ -3293,12 +3296,12 @@ parsestr(const char *s, const char *encoding) | |||
| 3293 | 3296 | } | |
| 3294 | 3297 | #ifdef Py_USING_UNICODE | |
| 3295 | 3298 | if (unicode || Py_UnicodeFlag) { | |
| 3296 | - return decode_unicode(s, len, rawmode, encoding); | ||
| 3299 | + return decode_unicode(s, len, rawmode, c->c_encoding); | ||
| 3297 | 3300 | } | |
| 3298 | 3301 | #endif | |
| 3299 | - need_encoding = (encoding != NULL && | ||
| 3300 | - strcmp(encoding, "utf-8") != 0 && | ||
| 3301 | - strcmp(encoding, "iso-8859-1") != 0); | ||
| 3302 | + need_encoding = (c->c_encoding != NULL && | ||
| 3303 | + strcmp(c->c_encoding, "utf-8") != 0 && | ||
| 3304 | + strcmp(c->c_encoding, "iso-8859-1") != 0); | ||
| 3302 | 3305 | if (rawmode || strchr(s, '\\') == NULL) { | |
| 3303 | 3306 | if (need_encoding) { | |
| 3304 | 3307 | #ifndef Py_USING_UNICODE | |
@@ -3310,7 +3313,7 @@ parsestr(const char *s, const char *encoding) | |||
| 3310 | 3313 | PyObject *v, *u = PyUnicode_DecodeUTF8(s, len, NULL); | |
| 3311 | 3314 | if (u == NULL) | |
| 3312 | 3315 | return NULL; | |
| 3313 | - v = PyUnicode_AsEncodedString(u, encoding, NULL); | ||
| 3316 | + v = PyUnicode_AsEncodedString(u, c->c_encoding, NULL); | ||
| 3314 | 3317 | Py_DECREF(u); | |
| 3315 | 3318 | return v; | |
| 3316 | 3319 | #endif | |
@@ -3320,7 +3323,7 @@ parsestr(const char *s, const char *encoding) | |||
| 3320 | 3323 | } | |
| 3321 | 3324 | ||
| 3322 | 3325 | return PyString_DecodeEscape(s, len, NULL, unicode, | |
| 3323 | - need_encoding ? encoding : NULL); | ||
| 3326 | + need_encoding ? c->c_encoding : NULL); | ||
| 3324 | 3327 | } | |
| 3325 | 3328 | ||
| 3326 | 3329 | /* Build a Python string object out of a STRING atom. This takes care of | |
@@ -3333,11 +3336,11 @@ parsestrplus(struct compiling *c, const node *n) | |||
| 3333 | 3336 | PyObject *v; | |
| 3334 | 3337 | int i; | |
| 3335 | 3338 | REQ(CHILD(n, 0), STRING); | |
| 3336 | - if ((v = parsestr(STR(CHILD(n, 0)), c->c_encoding)) != NULL) { | ||
| 3339 | + if ((v = parsestr(c, STR(CHILD(n, 0)))) != NULL) { | ||
| 3337 | 3340 | /* String literal concatenation */ | |
| 3338 | 3341 | for (i = 1; i < NCH(n); i++) { | |
| 3339 | 3342 | PyObject *s; | |
| 3340 | - s = parsestr(STR(CHILD(n, i)), c->c_encoding); | ||
| 3343 | + s = parsestr(c, STR(CHILD(n, i))); | ||
| 3341 | 3344 | if (s == NULL) | |
| 3342 | 3345 | goto onError; | |
| 3343 | 3346 | if (PyString_Check(v) && PyString_Check(s)) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -35,6 +35,8 @@ future_check_features(PyFutureFeatures *ff, stmt_ty s, const char *filename) | |||
| 35 | 35 | ff->ff_features |= CO_FUTURE_WITH_STATEMENT; | |
| 36 | 36 | } else if (strcmp(feature, FUTURE_PRINT_FUNCTION) == 0) { | |
| 37 | 37 | ff->ff_features |= CO_FUTURE_PRINT_FUNCTION; | |
| 38 | + } else if (strcmp(feature, FUTURE_UNICODE_LITERALS) == 0) { | ||
| 39 | + ff->ff_features |= CO_FUTURE_UNICODE_LITERALS; | ||
| 38 | 40 | } else if (strcmp(feature, "braces") == 0) { | |
| 39 | 41 | PyErr_SetString(PyExc_SyntaxError, | |
| 40 | 42 | "not a chance"); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments