Index: Python/pythonrun.c =================================================================== --- Python/pythonrun.c (revision 53285) +++ Python/pythonrun.c (working copy) @@ -723,18 +723,18 @@ } /* compute parser flags based on compiler flags */ +#if 0 #define PARSER_FLAGS(flags) \ ((flags) ? ((((flags)->cf_flags & PyCF_DONT_IMPLY_DEDENT) ? \ PyPARSE_DONT_IMPLY_DEDENT : 0)) : 0) +#endif -#if 0 /* Keep an example of flags with future keyword support. */ #define PARSER_FLAGS(flags) \ ((flags) ? ((((flags)->cf_flags & PyCF_DONT_IMPLY_DEDENT) ? \ PyPARSE_DONT_IMPLY_DEDENT : 0) \ - | ((flags)->cf_flags & CO_FUTURE_WITH_STATEMENT ? \ - PyPARSE_WITH_IS_KEYWORD : 0)) : 0) -#endif + | ((flags)->cf_flags & CO_FUTURE_PRINT_FUNCTION ? \ + PyPARSE_PRINT_IS_FUNCTION : 0)) : 0) int PyRun_InteractiveOneFlags(FILE *fp, const char *filename, PyCompilerFlags *flags) Index: Python/future.c =================================================================== --- Python/future.c (revision 53285) +++ Python/future.c (working copy) @@ -33,6 +33,8 @@ ff->ff_features |= CO_FUTURE_ABSOLUTE_IMPORT; } else if (strcmp(feature, FUTURE_WITH_STATEMENT) == 0) { ff->ff_features |= CO_FUTURE_WITH_STATEMENT; + } else if (strcmp(feature, FUTURE_PRINT_FUNCTION) == 0) { + ff->ff_features |= CO_FUTURE_PRINT_FUNCTION; } else if (strcmp(feature, "braces") == 0) { PyErr_SetString(PyExc_SyntaxError, "not a chance"); Index: Python/bltinmodule.c =================================================================== --- Python/bltinmodule.c (revision 53285) +++ Python/bltinmodule.c (working copy) @@ -1410,7 +1422,73 @@ equivalent to (x**y) % z, but may be more efficient (e.g. for longs)."); +static PyObject * +builtin_print(PyObject *self, PyObject *args, PyObject *kwds) +{ + static char *kwlist[] = {"sep", "end", "file", 0}; + PyObject *dummy_args = PyTuple_New(0); + PyObject *sep = NULL, *end = NULL, *file = NULL; + int i, err; + if (dummy_args == NULL) + return NULL; + if (!PyArg_ParseTupleAndKeywords(dummy_args, kwds, "|OOO:Print", + kwlist, &sep, &end, &file)) + return NULL; + if (file == NULL || file == Py_None) + file = PySys_GetObject("stdout"); + + if (sep && sep != Py_None && !PyString_Check(sep) && + !PyUnicode_Check(sep)) { + PyErr_Format(PyExc_TypeError, + "sep must be None, str or unicode, not %.200s", + sep->ob_type->tp_name); + return NULL; + } + if (end && end != Py_None && !PyString_Check(end) && + !PyUnicode_Check(end)) { + PyErr_Format(PyExc_TypeError, + "end must be None, str or unicode, not %.200s", + end->ob_type->tp_name); + return NULL; + } + + for (i = 0; i < PyTuple_Size(args); i++) { + if (i > 0) { + if (sep == NULL || sep == Py_None) + err = PyFile_WriteString(" ", file); + else + err = PyFile_WriteObject(sep, file, + Py_PRINT_RAW); + if (err) + return NULL; + } + err = PyFile_WriteObject(PyTuple_GetItem(args, i), file, + Py_PRINT_RAW); + if (err) + return NULL; + } + + if (end == NULL || end == Py_None) + err = PyFile_WriteString("\n", file); + else + err = PyFile_WriteObject(end, file, Py_PRINT_RAW); + if (err) + return NULL; + + Py_RETURN_NONE; +} + +PyDoc_STRVAR(print_doc, +"Print(value, ..., file=None, sep=' ', end='\\n')\n\ +\n\ +Prints the values to a stream, or to sys.stdout by default.\n\ +Optional keyword arguments:\n\ +file: a file-like object (stream); defaults to the current sys.stdout.\n\ +sep: string inserted between values, default a space.\n\ +end: string appended after the last value, default a newline."); + + /* Return number of items in range (lo, hi, step), when arguments are * PyInt or PyLong objects. step > 0 required. Return a value < 0 if * & only if the true value is too large to fit in a signed long. @@ -2263,6 +2341,7 @@ {"open", (PyCFunction)builtin_open, METH_VARARGS | METH_KEYWORDS, open_doc}, {"ord", builtin_ord, METH_O, ord_doc}, {"pow", builtin_pow, METH_VARARGS, pow_doc}, + {"print", builtin_print, METH_VARARGS | METH_KEYWORDS, print_doc}, {"range", builtin_range, METH_VARARGS, range_doc}, {"raw_input", builtin_raw_input, METH_VARARGS, raw_input_doc}, {"reduce", builtin_reduce, METH_VARARGS, reduce_doc}, Index: Include/code.h =================================================================== --- Include/code.h (revision 53285) +++ Include/code.h (working copy) @@ -48,11 +48,12 @@ #define CO_FUTURE_DIVISION 0x2000 #define CO_FUTURE_ABSOLUTE_IMPORT 0x4000 /* do absolute imports by default */ #define CO_FUTURE_WITH_STATEMENT 0x8000 +#define CO_FUTURE_PRINT_FUNCTION 0x10000 /* This should be defined if a future statement modifies the syntax. For example, when a keyword is added. */ -#if 0 +#if 1 #define PY_PARSER_REQUIRES_FUTURE_KEYWORD #endif Index: Include/parsetok.h =================================================================== --- Include/parsetok.h (revision 53285) +++ Include/parsetok.h (working copy) @@ -27,6 +27,9 @@ #define PyPARSE_WITH_IS_KEYWORD 0x0003 #endif +#define PyPARSE_PRINT_IS_FUNCTION 0x0004 + + PyAPI_FUNC(node *) PyParser_ParseString(const char *, grammar *, int, perrdetail *); PyAPI_FUNC(node *) PyParser_ParseFile (FILE *, const char *, grammar *, int, Index: Include/pythonrun.h =================================================================== --- Include/pythonrun.h (revision 53285) +++ Include/pythonrun.h (working copy) @@ -8,7 +8,7 @@ #endif #define PyCF_MASK (CO_FUTURE_DIVISION | CO_FUTURE_ABSOLUTE_IMPORT | \ - CO_FUTURE_WITH_STATEMENT) + CO_FUTURE_WITH_STATEMENT|CO_FUTURE_PRINT_FUNCTION) #define PyCF_MASK_OBSOLETE (CO_NESTED) #define PyCF_SOURCE_IS_UTF8 0x0100 #define PyCF_DONT_IMPLY_DEDENT 0x0200 Index: Include/compile.h =================================================================== --- Include/compile.h (revision 53285) +++ Include/compile.h (working copy) @@ -24,6 +24,7 @@ #define FUTURE_DIVISION "division" #define FUTURE_ABSOLUTE_IMPORT "absolute_import" #define FUTURE_WITH_STATEMENT "with_statement" +#define FUTURE_PRINT_FUNCTION "print_function" struct _mod; /* Declare the existence of this type */ PyAPI_FUNC(PyCodeObject *) PyAST_Compile(struct _mod *, const char *, Index: Parser/parsetok.c =================================================================== --- Parser/parsetok.c (revision 53285) +++ Parser/parsetok.c (working copy) @@ -123,8 +123,8 @@ return NULL; } #ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD - if (flags & PyPARSE_WITH_IS_KEYWORD) - ps->p_flags |= CO_FUTURE_WITH_STATEMENT; + if (flags & PyPARSE_PRINT_IS_FUNCTION) + ps->p_flags |= CO_FUTURE_PRINT_FUNCTION; #endif for (;;) { @@ -173,6 +173,7 @@ len == 6 && str[0] == 'i' && strcmp(str, "import") == 0) handling_import = 1; +#if 0 /* Warn about with as NAME */ if (type == NAME && !(ps->p_flags & CO_FUTURE_WITH_STATEMENT)) { @@ -188,6 +189,7 @@ len == 4 && str[0] == 'w' && strcmp(str, "with") == 0) handling_with = 1; #endif +#endif if (a >= tok->line_start) col_offset = a - tok->line_start; else Index: Parser/parser.c =================================================================== --- Parser/parser.c (revision 53285) +++ Parser/parser.c (working copy) @@ -149,13 +152,20 @@ strcmp(l->lb_str, s) != 0) continue; #ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD + if ((ps->p_flags & CO_FUTURE_PRINT_FUNCTION) && + s[0] == 'p' && strcmp(s, "print") == 0) { + break; /* no longer a keyword */ + } +#if 0 if (!(ps->p_flags & CO_FUTURE_WITH_STATEMENT)) { if (s[0] == 'w' && strcmp(s, "with") == 0) break; /* not a keyword yet */ else if (s[0] == 'a' && strcmp(s, "as") == 0) break; /* not a keyword yet */ - } + + } #endif +#endif D(printf("It's a keyword\n")); return n - i; } @@ -208,6 +218,10 @@ strcmp(STR(CHILD(cch, 0)), "with_statement") == 0) { ps->p_flags |= CO_FUTURE_WITH_STATEMENT; break; + } else if (NCH(cch) >= 1 && TYPE(CHILD(cch, 0)) == NAME && + strcmp(STR(CHILD(cch, 0)), "print_function") == 0) { + ps->p_flags |= CO_FUTURE_PRINT_FUNCTION; + break; } } } Index: Lib/__future__.py =================================================================== --- Lib/__future__.py (revision 53285) +++ Lib/__future__.py (working copy) @@ -53,6 +53,7 @@ "division", "absolute_import", "with_statement", + "print_function", ] __all__ = ["all_feature_names"] + all_feature_names @@ -66,6 +67,7 @@ CO_FUTURE_DIVISION = 0x2000 # division CO_FUTURE_ABSOLUTE_IMPORT = 0x4000 # perform absolute imports by default CO_FUTURE_WITH_STATEMENT = 0x8000 # with statement +CO_FUTURE_PRINT_FUNCTION = 0x10000 # with statement class _Feature: def __init__(self, optionalRelease, mandatoryRelease, compiler_flag): @@ -114,3 +116,7 @@ with_statement = _Feature((2, 5, 0, "alpha", 1), (2, 6, 0, "alpha", 0), CO_FUTURE_WITH_STATEMENT) + +print_function = _Feature((2, 6, 0, "alpha", 1), + (3, 0, 0, "alpha", 0), + CO_FUTURE_PRINT_FUNCTION)