mirror of
https://github.com/python/cpython.git
synced 2025-09-23 00:43:12 +00:00
Accept u"..." literals even when Unicode is disabled. But these
literals must not contain \u, \U or \N escapes. (XXX Should they also not contain non-ASCII characters?)
This commit is contained in:
parent
c88da1faa5
commit
05459c5e5e
1 changed files with 13 additions and 8 deletions
|
@ -1130,19 +1130,12 @@ parsestr(struct compiling *com, char *s)
|
||||||
int first = *s;
|
int first = *s;
|
||||||
int quote = first;
|
int quote = first;
|
||||||
int rawmode = 0;
|
int rawmode = 0;
|
||||||
#ifdef Py_USING_UNICODE
|
|
||||||
int unicode = 0;
|
int unicode = 0;
|
||||||
#endif
|
|
||||||
if (isalpha(quote) || quote == '_') {
|
if (isalpha(quote) || quote == '_') {
|
||||||
if (quote == 'u' || quote == 'U') {
|
if (quote == 'u' || quote == 'U') {
|
||||||
#ifdef Py_USING_UNICODE
|
|
||||||
quote = *++s;
|
quote = *++s;
|
||||||
unicode = 1;
|
unicode = 1;
|
||||||
#else
|
|
||||||
com_error(com, PyExc_SyntaxError,
|
|
||||||
"Unicode literals not supported in this Python");
|
|
||||||
return NULL;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
if (quote == 'r' || quote == 'R') {
|
if (quote == 'r' || quote == 'R') {
|
||||||
quote = *++s;
|
quote = *++s;
|
||||||
|
@ -1250,6 +1243,18 @@ parsestr(struct compiling *com, char *s)
|
||||||
com_error(com, PyExc_ValueError,
|
com_error(com, PyExc_ValueError,
|
||||||
"invalid \\x escape");
|
"invalid \\x escape");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
#ifndef Py_USING_UNICODE
|
||||||
|
case 'u':
|
||||||
|
case 'U':
|
||||||
|
case 'N':
|
||||||
|
if (unicode) {
|
||||||
|
Py_DECREF(v);
|
||||||
|
com_error(com, PyExc_ValueError,
|
||||||
|
"Unicode escapes not legal "
|
||||||
|
"when Unicode disabled");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
default:
|
default:
|
||||||
*p++ = '\\';
|
*p++ = '\\';
|
||||||
*p++ = s[-1];
|
*p++ = s[-1];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue