diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2014-06-01 19:13:39 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2014-06-01 19:13:39 (GMT) |
commit | 79fa98af9e3a37ee1e98094c55d8574c20c9d9a5 (patch) | |
tree | 547b06ab2d3585fb3f8568ff993b6e4637cb36d4 /Python/ast.c | |
parent | e75a555073abc75e4eb1db923a1929d3b500e5e5 (diff) | |
download | cpython-79fa98af9e3a37ee1e98094c55d8574c20c9d9a5.zip cpython-79fa98af9e3a37ee1e98094c55d8574c20c9d9a5.tar.gz cpython-79fa98af9e3a37ee1e98094c55d8574c20c9d9a5.tar.bz2 |
Issue #19656: Running Python with the -3 option now also warns about
non-ascii bytes literals.
Diffstat (limited to 'Python/ast.c')
-rw-r--r-- | Python/ast.c | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/Python/ast.c b/Python/ast.c index fc6f002..80e6354 100644 --- a/Python/ast.c +++ b/Python/ast.c @@ -37,7 +37,7 @@ static expr_ty ast_for_testlist_comp(struct compiling *, const node *); static expr_ty ast_for_call(struct compiling *, const node *, expr_ty); static PyObject *parsenumber(struct compiling *, const char *); -static PyObject *parsestr(struct compiling *, const char *); +static PyObject *parsestr(struct compiling *, const node *n, const char *); static PyObject *parsestrplus(struct compiling *, const node *n); #ifndef LINENO @@ -3444,13 +3444,14 @@ decode_unicode(struct compiling *c, const char *s, size_t len, int rawmode, cons * parsestr parses it, and returns the decoded Python string object. */ static PyObject * -parsestr(struct compiling *c, const char *s) +parsestr(struct compiling *c, const node *n, const char *s) { - size_t len; + size_t len, i; int quote = Py_CHARMASK(*s); int rawmode = 0; int need_encoding; int unicode = c->c_future_unicode; + int bytes = 0; if (isalpha(quote) || quote == '_') { if (quote == 'u' || quote == 'U') { @@ -3460,6 +3461,7 @@ parsestr(struct compiling *c, const char *s) if (quote == 'b' || quote == 'B') { quote = *++s; unicode = 0; + bytes = 1; } if (quote == 'r' || quote == 'R') { quote = *++s; @@ -3489,6 +3491,16 @@ parsestr(struct compiling *c, const char *s) return NULL; } } + if (Py_Py3kWarningFlag && bytes) { + for (i = 0; i < len; i++) { + if ((unsigned char)s[i] > 127) { + if (!ast_warn(c, n, + "non-ascii bytes literals not supported in 3.x")) + return NULL; + break; + } + } + } #ifdef Py_USING_UNICODE if (unicode || Py_UnicodeFlag) { return decode_unicode(c, s, len, rawmode, c->c_encoding); @@ -3531,11 +3543,11 @@ parsestrplus(struct compiling *c, const node *n) PyObject *v; int i; REQ(CHILD(n, 0), STRING); - if ((v = parsestr(c, STR(CHILD(n, 0)))) != NULL) { + if ((v = parsestr(c, n, STR(CHILD(n, 0)))) != NULL) { /* String literal concatenation */ for (i = 1; i < NCH(n); i++) { PyObject *s; - s = parsestr(c, STR(CHILD(n, i))); + s = parsestr(c, n, STR(CHILD(n, i))); if (s == NULL) goto onError; if (PyString_Check(v) && PyString_Check(s)) { |