summaryrefslogtreecommitdiffstats
path: root/Python/pythonrun.c
diff options
context:
space:
mode:
authorChristian Heimes <christian@cheimes.de>2008-03-26 22:01:37 (GMT)
committerChristian Heimes <christian@cheimes.de>2008-03-26 22:01:37 (GMT)
commit3c60833e1e53f6239825b44f76fa22172feb1790 (patch)
treea8ebf8db7f226aaaa1a144e1b6361281374a169a /Python/pythonrun.c
parent0cb3e86c472828720bb36a8335f10b81389fb668 (diff)
downloadcpython-3c60833e1e53f6239825b44f76fa22172feb1790.zip
cpython-3c60833e1e53f6239825b44f76fa22172feb1790.tar.gz
cpython-3c60833e1e53f6239825b44f76fa22172feb1790.tar.bz2
Patch #2477: Added from __future__ import unicode_literals
The new PyParser_*Ex() functions are based on Neal's suggestion and initial patch. The new __future__ feature makes all '' and r'' unicode strings. b'' and br'' stay (byte) strings.
Diffstat (limited to 'Python/pythonrun.c')
-rw-r--r--Python/pythonrun.c30
1 files changed, 23 insertions, 7 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index 226fee3..423aae1 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -774,8 +774,11 @@ PyRun_InteractiveLoopFlags(FILE *fp, const char *filename, PyCompilerFlags *flag
#define PARSER_FLAGS(flags) \
((flags) ? ((((flags)->cf_flags & PyCF_DONT_IMPLY_DEDENT) ? \
PyPARSE_DONT_IMPLY_DEDENT : 0) \
- | ((flags)->cf_flags & CO_FUTURE_PRINT_FUNCTION ? \
- PyPARSE_PRINT_IS_FUNCTION : 0)) : 0)
+ | (((flags)->cf_flags & CO_FUTURE_PRINT_FUNCTION) ? \
+ PyPARSE_PRINT_IS_FUNCTION : 0) \
+ | (((flags)->cf_flags & CO_FUTURE_UNICODE_LITERALS) ? \
+ PyPARSE_UNICODE_LITERALS : 0) \
+ ) : 0)
#endif
int
@@ -1390,11 +1393,12 @@ Py_SymtableString(const char *str, const char *filename, int start)
{
struct symtable *st;
mod_ty mod;
+ PyCompilerFlags flags;
PyArena *arena = PyArena_New();
if (arena == NULL)
return NULL;
- mod = PyParser_ASTFromString(str, filename, start, NULL, arena);
+ mod = PyParser_ASTFromString(str, filename, start, &flags, arena);
if (mod == NULL) {
PyArena_Free(arena);
return NULL;
@@ -1411,10 +1415,16 @@ PyParser_ASTFromString(const char *s, const char *filename, int start,
{
mod_ty mod;
perrdetail err;
- node *n = PyParser_ParseStringFlagsFilename(s, filename,
+ int iflags;
+ iflags = PARSER_FLAGS(flags);
+
+ node *n = PyParser_ParseStringFlagsFilenameEx(s, filename,
&_PyParser_Grammar, start, &err,
- PARSER_FLAGS(flags));
+ &iflags);
if (n) {
+ if (flags) {
+ flags->cf_flags |= iflags & PyCF_MASK;
+ }
mod = PyAST_FromNode(n, flags, filename, arena);
PyNode_Free(n);
return mod;
@@ -1432,9 +1442,15 @@ PyParser_ASTFromFile(FILE *fp, const char *filename, int start, char *ps1,
{
mod_ty mod;
perrdetail err;
- node *n = PyParser_ParseFileFlags(fp, filename, &_PyParser_Grammar,
- start, ps1, ps2, &err, PARSER_FLAGS(flags));
+ int iflags;
+
+ iflags = PARSER_FLAGS(flags);
+ node *n = PyParser_ParseFileFlagsEx(fp, filename, &_PyParser_Grammar,
+ start, ps1, ps2, &err, &iflags);
if (n) {
+ if (flags) {
+ flags->cf_flags |= iflags & PyCF_MASK;
+ }
mod = PyAST_FromNode(n, flags, filename, arena);
PyNode_Free(n);
return mod;