summaryrefslogtreecommitdiffstats
path: root/Python/bltinmodule.c
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2001-08-17 22:11:27 (GMT)
committerTim Peters <tim.peters@gmail.com>2001-08-17 22:11:27 (GMT)
commit6cd6a82db93fa37a13d0b5312ce6510c4d6967de (patch)
treec43eca432a18a364fb1c004d4dfcfe904fa7cefd /Python/bltinmodule.c
parent10d72552495a1967af7174f6ed52eb3340799c76 (diff)
downloadcpython-6cd6a82db93fa37a13d0b5312ce6510c4d6967de.zip
cpython-6cd6a82db93fa37a13d0b5312ce6510c4d6967de.tar.gz
cpython-6cd6a82db93fa37a13d0b5312ce6510c4d6967de.tar.bz2
A fiddled version of the rest of Michael Hudson's SF patch
#449043 supporting __future__ in simulated shells which implements PEP 264.
Diffstat (limited to 'Python/bltinmodule.c')
-rw-r--r--Python/bltinmodule.c34
1 files changed, 26 insertions, 8 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index d0f934f..9a179a1 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -377,10 +377,14 @@ builtin_compile(PyObject *self, PyObject *args)
char *filename;
char *startstr;
int start;
+ int dont_inherit = 0;
+ int supplied_flags = 0;
PyCompilerFlags cf;
- if (!PyArg_ParseTuple(args, "sss:compile", &str, &filename, &startstr))
+ if (!PyArg_ParseTuple(args, "sss|ii:compile", &str, &filename,
+ &startstr, &supplied_flags, &dont_inherit))
return NULL;
+
if (strcmp(startstr, "exec") == 0)
start = Py_file_input;
else if (strcmp(startstr, "eval") == 0)
@@ -392,21 +396,35 @@ builtin_compile(PyObject *self, PyObject *args)
"compile() arg 3 must be 'exec' or 'eval' or 'single'");
return NULL;
}
- cf.cf_flags = 0;
- if (PyEval_MergeCompilerFlags(&cf))
- return Py_CompileStringFlags(str, filename, start, &cf);
- else
- return Py_CompileString(str, filename, start);
+
+ if (supplied_flags & ~(PyCF_MASK | PyCF_MASK_OBSOLETE)) {
+ PyErr_SetString(PyExc_ValueError,
+ "compile(): unrecognised flags");
+ return NULL;
+ }
+ /* XXX Warn if (supplied_flags & PyCF_MASK_OBSOLETE) != 0? */
+
+ cf.cf_flags = supplied_flags;
+ if (!dont_inherit) {
+ PyEval_MergeCompilerFlags(&cf);
+ }
+ return Py_CompileStringFlags(str, filename, start, &cf);
}
static char compile_doc[] =
-"compile(source, filename, mode) -> code object\n\
+"compile(source, filename, mode[, flags[, dont_inherit]]) -> code object\n\
\n\
Compile the source string (a Python module, statement or expression)\n\
into a code object that can be executed by the exec statement or eval().\n\
The filename will be used for run-time error messages.\n\
The mode must be 'exec' to compile a module, 'single' to compile a\n\
-single (interactive) statement, or 'eval' to compile an expression.";
+single (interactive) statement, or 'eval' to compile an expression.\n\
+The flags argument, if present, controls which future statements influence\n\
+the compilation of the code.\n\
+The dont_inherit argument, if non-zero, stops the compilation inheriting\n\
+the effects of any future statements in effect in the code calling\n\
+compile; if absent or zero these statements do influence the compilation,\n\
+in addition to any features explicitly specified.";
static PyObject *