comparison Python/pythonrun.c @ 46118:c78d3586c474 legacy-trunk

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.
author Christian Heimes <christian@cheimes.de>
date Wed, 26 Mar 2008 22:01:37 +0000
parents 5341b30b1812
children d00ded8b2677
comparison
equal deleted inserted replaced
46117:dce9d2d92c88 46118:c78d3586c474
772 #if 1 772 #if 1
773 /* Keep an example of flags with future keyword support. */ 773 /* Keep an example of flags with future keyword support. */
774 #define PARSER_FLAGS(flags) \ 774 #define PARSER_FLAGS(flags) \
775 ((flags) ? ((((flags)->cf_flags & PyCF_DONT_IMPLY_DEDENT) ? \ 775 ((flags) ? ((((flags)->cf_flags & PyCF_DONT_IMPLY_DEDENT) ? \
776 PyPARSE_DONT_IMPLY_DEDENT : 0) \ 776 PyPARSE_DONT_IMPLY_DEDENT : 0) \
777 | ((flags)->cf_flags & CO_FUTURE_PRINT_FUNCTION ? \ 777 | (((flags)->cf_flags & CO_FUTURE_PRINT_FUNCTION) ? \
778 PyPARSE_PRINT_IS_FUNCTION : 0)) : 0) 778 PyPARSE_PRINT_IS_FUNCTION : 0) \
779 | (((flags)->cf_flags & CO_FUTURE_UNICODE_LITERALS) ? \
780 PyPARSE_UNICODE_LITERALS : 0) \
781 ) : 0)
779 #endif 782 #endif
780 783
781 int 784 int
782 PyRun_InteractiveOneFlags(FILE *fp, const char *filename, PyCompilerFlags *flags) 785 PyRun_InteractiveOneFlags(FILE *fp, const char *filename, PyCompilerFlags *flags)
783 { 786 {
1388 struct symtable * 1391 struct symtable *
1389 Py_SymtableString(const char *str, const char *filename, int start) 1392 Py_SymtableString(const char *str, const char *filename, int start)
1390 { 1393 {
1391 struct symtable *st; 1394 struct symtable *st;
1392 mod_ty mod; 1395 mod_ty mod;
1396 PyCompilerFlags flags;
1393 PyArena *arena = PyArena_New(); 1397 PyArena *arena = PyArena_New();
1394 if (arena == NULL) 1398 if (arena == NULL)
1395 return NULL; 1399 return NULL;
1396 1400
1397 mod = PyParser_ASTFromString(str, filename, start, NULL, arena); 1401 mod = PyParser_ASTFromString(str, filename, start, &flags, arena);
1398 if (mod == NULL) { 1402 if (mod == NULL) {
1399 PyArena_Free(arena); 1403 PyArena_Free(arena);
1400 return NULL; 1404 return NULL;
1401 } 1405 }
1402 st = PySymtable_Build(mod, filename, 0); 1406 st = PySymtable_Build(mod, filename, 0);
1409 PyParser_ASTFromString(const char *s, const char *filename, int start, 1413 PyParser_ASTFromString(const char *s, const char *filename, int start,
1410 PyCompilerFlags *flags, PyArena *arena) 1414 PyCompilerFlags *flags, PyArena *arena)
1411 { 1415 {
1412 mod_ty mod; 1416 mod_ty mod;
1413 perrdetail err; 1417 perrdetail err;
1414 node *n = PyParser_ParseStringFlagsFilename(s, filename, 1418 int iflags;
1419 iflags = PARSER_FLAGS(flags);
1420
1421 node *n = PyParser_ParseStringFlagsFilenameEx(s, filename,
1415 &_PyParser_Grammar, start, &err, 1422 &_PyParser_Grammar, start, &err,
1416 PARSER_FLAGS(flags)); 1423 &iflags);
1417 if (n) { 1424 if (n) {
1425 if (flags) {
1426 flags->cf_flags |= iflags & PyCF_MASK;
1427 }
1418 mod = PyAST_FromNode(n, flags, filename, arena); 1428 mod = PyAST_FromNode(n, flags, filename, arena);
1419 PyNode_Free(n); 1429 PyNode_Free(n);
1420 return mod; 1430 return mod;
1421 } 1431 }
1422 else { 1432 else {
1430 char *ps2, PyCompilerFlags *flags, int *errcode, 1440 char *ps2, PyCompilerFlags *flags, int *errcode,
1431 PyArena *arena) 1441 PyArena *arena)
1432 { 1442 {
1433 mod_ty mod; 1443 mod_ty mod;
1434 perrdetail err; 1444 perrdetail err;
1435 node *n = PyParser_ParseFileFlags(fp, filename, &_PyParser_Grammar, 1445 int iflags;
1436 start, ps1, ps2, &err, PARSER_FLAGS(flags)); 1446
1447 iflags = PARSER_FLAGS(flags);
1448 node *n = PyParser_ParseFileFlagsEx(fp, filename, &_PyParser_Grammar,
1449 start, ps1, ps2, &err, &iflags);
1437 if (n) { 1450 if (n) {
1451 if (flags) {
1452 flags->cf_flags |= iflags & PyCF_MASK;
1453 }
1438 mod = PyAST_FromNode(n, flags, filename, arena); 1454 mod = PyAST_FromNode(n, flags, filename, arena);
1439 PyNode_Free(n); 1455 PyNode_Free(n);
1440 return mod; 1456 return mod;
1441 } 1457 }
1442 else { 1458 else {