Merged revisions 61952-61953 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r61952 | mark.dickinson | 2008-03-26 22:41:36 +0100 (Wed, 26 Mar 2008) | 2 lines

  Typo: "objects reference count" -> "object's reference count"
........
  r61953 | christian.heimes | 2008-03-26 23:01:37 +0100 (Wed, 26 Mar 2008) | 4 lines

  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.
........
diff --git a/Python/ast.c b/Python/ast.c
index be25ac3..759dd73 100644
--- a/Python/ast.c
+++ b/Python/ast.c
@@ -35,7 +35,7 @@
 static expr_ty ast_for_call(struct compiling *, const node *, expr_ty);
 
 static PyObject *parsenumber(const char *);
-static PyObject *parsestr(const node *n, const char *encoding, int *bytesmode);
+static PyObject *parsestr(struct compiling *, const node *n, int *bytesmode);
 static PyObject *parsestrplus(struct compiling *, const node *n,
                               int *bytesmode);
 
@@ -3191,14 +3191,13 @@
  * parsestr parses it, and returns the decoded Python string object.
  */
 static PyObject *
-parsestr(const node *n, const char *encoding, int *bytesmode)
+parsestr(struct compiling *c, const node *n, int *bytesmode)
 {
     size_t len;
     const char *s = STR(n);
     int quote = Py_CHARMASK(*s);
     int rawmode = 0;
     int need_encoding;
-
     if (isalpha(quote)) {
         if (quote == 'b' || quote == 'B') {
             quote = *++s;
@@ -3233,7 +3232,7 @@
         }
     }
     if (!*bytesmode && !rawmode) {
-        return decode_unicode(s, len, rawmode, encoding);
+        return decode_unicode(s, len, rawmode, c->c_encoding);
     }
     if (*bytesmode) {
         /* Disallow non-ascii characters (but not escapes) */
@@ -3246,28 +3245,27 @@
             }
         }
     }
-    need_encoding = (!*bytesmode && encoding != NULL &&
-                     strcmp(encoding, "utf-8") != 0 &&
-                     strcmp(encoding, "iso-8859-1") != 0);
+    need_encoding = (!*bytesmode && c->c_encoding != NULL &&
+                     strcmp(c->c_encoding, "utf-8") != 0 &&
+                     strcmp(c->c_encoding, "iso-8859-1") != 0);
     if (rawmode || strchr(s, '\\') == NULL) {
         if (need_encoding) {
             PyObject *v, *u = PyUnicode_DecodeUTF8(s, len, NULL);
             if (u == NULL || !*bytesmode)
                 return u;
-            v = PyUnicode_AsEncodedString(u, encoding, NULL);
+            v = PyUnicode_AsEncodedString(u, c->c_encoding, NULL);
             Py_DECREF(u);
             return v;
         } else if (*bytesmode) {
             return PyString_FromStringAndSize(s, len);
-        } else if (strcmp(encoding, "utf-8") == 0) {
+        } else if (strcmp(c->c_encoding, "utf-8") == 0) {
             return PyUnicode_FromStringAndSize(s, len);
 	} else {
             return PyUnicode_DecodeLatin1(s, len, NULL);
         }
     }
-
     return PyString_DecodeEscape(s, len, NULL, 1,
-                                 need_encoding ? encoding : NULL);
+                                 need_encoding ? c->c_encoding : NULL);
 }
 
 /* Build a Python string object out of a STRING+ atom.  This takes care of
@@ -3280,13 +3278,13 @@
     PyObject *v;
     int i;
     REQ(CHILD(n, 0), STRING);
-    v = parsestr(CHILD(n, 0), c->c_encoding, bytesmode);
+    v = parsestr(c, CHILD(n, 0), bytesmode);
     if (v != NULL) {
         /* String literal concatenation */
         for (i = 1; i < NCH(n); i++) {
             PyObject *s;
             int subbm = 0;
-            s = parsestr(CHILD(n, i), c->c_encoding, &subbm);
+            s = parsestr(c, CHILD(n, i), &subbm);
             if (s == NULL)
                 goto onError;
             if (*bytesmode != subbm) {
diff --git a/Python/future.c b/Python/future.c
index d6333ff..a5bee0c 100644
--- a/Python/future.c
+++ b/Python/future.c
@@ -35,6 +35,8 @@
 			continue;
 		} else if (strcmp(feature, FUTURE_PRINT_FUNCTION) == 0) {
 			continue;
+		} else if (strcmp(feature, FUTURE_UNICODE_LITERALS) == 0) {
+			continue;
 		} else if (strcmp(feature, "braces") == 0) {
 			PyErr_SetString(PyExc_SyntaxError,
 					"not a chance");
diff --git a/Python/import.c b/Python/import.c
index d201dae..33cb81c 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -821,12 +821,13 @@
 {
 	PyCodeObject *co = NULL;
 	mod_ty mod;
+	PyCompilerFlags flags;
 	PyArena *arena = PyArena_New();
 	if (arena == NULL)
 		return NULL;
 
 	mod = PyParser_ASTFromFile(fp, pathname, NULL,
-				   Py_file_input, 0, 0, 0, 
+				   Py_file_input, 0, 0, &flags, 
 				   NULL, arena);
 	if (mod) {
 		co = PyAST_Compile(mod, pathname, NULL, arena);
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index d65d12d..5c17b69 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -1563,11 +1563,12 @@
 {
 	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;
@@ -1584,10 +1585,16 @@
 {
 	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;
@@ -1606,10 +1613,16 @@
 {
 	mod_ty mod;
 	perrdetail err;
-	node *n = PyParser_ParseFileFlags(fp, filename, enc,
+	int iflags;
+
+	iflags = PARSER_FLAGS(flags);
+	node *n = PyParser_ParseFileFlagsEx(fp, filename, enc,
 					  &_PyParser_Grammar,
-				start, ps1, ps2, &err, PARSER_FLAGS(flags));
+				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;