summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1995-07-07 22:43:42 (GMT)
committerGuido van Rossum <guido@python.org>1995-07-07 22:43:42 (GMT)
commit872537cc86080d5f816c2e6f81906a7cb8c0a468 (patch)
treeca5edd9d06893774895af9541a2cc29587a1a631
parent064a62bc8a5b4e766dedc7afa83dc9b23267fccc (diff)
downloadcpython-872537cc86080d5f816c2e6f81906a7cb8c0a468.zip
cpython-872537cc86080d5f816c2e6f81906a7cb8c0a468.tar.gz
cpython-872537cc86080d5f816c2e6f81906a7cb8c0a468.tar.bz2
added locals() and globals(); [raw_]input() uses readline()
-rw-r--r--Python/bltinmodule.c68
1 files changed, 67 insertions, 1 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index 0dc6f00..7a55b51 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -266,9 +266,11 @@ builtin_compile(self, args)
start = file_input;
else if (strcmp(startstr, "eval") == 0)
start = eval_input;
+ else if (strcmp(startstr, "single") == 0)
+ start = single_input;
else {
err_setstr(ValueError,
- "compile() mode must be 'exec' or 'eval'");
+ "compile() mode must be 'exec' or 'eval' or 'single'");
return NULL;
}
return compile_string(str, filename, start);
@@ -462,6 +464,20 @@ builtin_getattr(self, args)
}
static object *
+builtin_globals(self, args)
+ object *self;
+ object *args;
+{
+ object *d;
+
+ if (!newgetargs(args, ""))
+ return NULL;
+ d = getglobals();
+ INCREF(d);
+ return d;
+}
+
+static object *
builtin_hasattr(self, args)
object *self;
object *args;
@@ -780,6 +796,20 @@ builtin_len(self, args)
}
static object *
+builtin_locals(self, args)
+ object *self;
+ object *args;
+{
+ object *d;
+
+ if (!newgetargs(args, ""))
+ return NULL;
+ d = getlocals();
+ INCREF(d);
+ return d;
+}
+
+static object *
builtin_long(self, args)
object *self;
object *args;
@@ -1058,6 +1088,8 @@ builtin_xrange(self, args)
return newrangeobject(ilow, n, istep, 1);
}
+extern char *my_readline PROTO((char *));
+
static object *
builtin_raw_input(self, args)
object *self;
@@ -1068,6 +1100,38 @@ builtin_raw_input(self, args)
if (!newgetargs(args, "|O:[raw_]input", &v))
return NULL;
+ if (getfilefile(sysget("stdin")) == stdin &&
+ getfilefile(sysget("stdout")) == stdout) {
+ object *po;
+ char *prompt;
+ char *s;
+ object *result;
+ if (v != NULL) {
+ po = strobject(v);
+ if (po == NULL)
+ return NULL;
+ prompt = getstringvalue(po);
+ }
+ else {
+ po = NULL;
+ prompt = "";
+ }
+ s = my_readline(prompt);
+ XDECREF(po);
+ if (s == NULL) {
+ err_set(KeyboardInterrupt);
+ return NULL;
+ }
+ if (*s == '\0') {
+ err_set(EOFError);
+ result = NULL;
+ }
+ else { /* strip trailing '\n' */
+ result = newsizedstringobject(s, strlen(s)-1);
+ }
+ free(s);
+ return result;
+ }
if (v != NULL) {
f = sysget("stdout");
if (f == NULL) {
@@ -1328,6 +1392,7 @@ static struct methodlist builtin_methods[] = {
{"filter", builtin_filter, 1},
{"float", builtin_float, 1},
{"getattr", builtin_getattr, 1},
+ {"globals", builtin_globals, 1},
{"hasattr", builtin_hasattr, 1},
{"hash", builtin_hash, 1},
{"hex", builtin_hex, 1},
@@ -1335,6 +1400,7 @@ static struct methodlist builtin_methods[] = {
{"input", builtin_input, 1},
{"int", builtin_int, 1},
{"len", builtin_len, 1},
+ {"locals", builtin_locals, 1},
{"long", builtin_long, 1},
{"map", builtin_map, 1},
{"max", builtin_max, 1},