diff options
author | Martin v. Löwis <martin@v.loewis.de> | 2007-09-04 09:18:06 (GMT) |
---|---|---|
committer | Martin v. Löwis <martin@v.loewis.de> | 2007-09-04 09:18:06 (GMT) |
commit | 85bcc66bb492931b6ca3de21ca53ca53b754be33 (patch) | |
tree | 3e46f8d106d8ac338238c146480568dd4a3c0083 /Python | |
parent | 53de1902e7a9788d2d4b917b1b14b2a76171f0f4 (diff) | |
download | cpython-85bcc66bb492931b6ca3de21ca53ca53b754be33.zip cpython-85bcc66bb492931b6ca3de21ca53ca53b754be33.tar.gz cpython-85bcc66bb492931b6ca3de21ca53ca53b754be33.tar.bz2 |
Convert code from sys.stdin.encoding to UTF-8 in
interactive mode. Fixes #1100.
Diffstat (limited to 'Python')
-rw-r--r-- | Python/import.c | 3 | ||||
-rw-r--r-- | Python/pythonrun.c | 29 |
2 files changed, 24 insertions, 8 deletions
diff --git a/Python/import.c b/Python/import.c index 7283783..c2f42e9 100644 --- a/Python/import.c +++ b/Python/import.c @@ -809,7 +809,8 @@ parse_source_module(const char *pathname, FILE *fp) if (arena == NULL) return NULL; - mod = PyParser_ASTFromFile(fp, pathname, Py_file_input, 0, 0, 0, + mod = PyParser_ASTFromFile(fp, pathname, NULL, + Py_file_input, 0, 0, 0, NULL, arena); if (mod) { co = PyAST_Compile(mod, pathname, NULL, arena); diff --git a/Python/pythonrun.c b/Python/pythonrun.c index eeed820..d89f5f9 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -744,12 +744,22 @@ PyRun_InteractiveLoopFlags(FILE *fp, const char *filename, PyCompilerFlags *flag int PyRun_InteractiveOneFlags(FILE *fp, const char *filename, PyCompilerFlags *flags) { - PyObject *m, *d, *v, *w; + PyObject *m, *d, *v, *w, *oenc = NULL; mod_ty mod; PyArena *arena; - char *ps1 = "", *ps2 = ""; + char *ps1 = "", *ps2 = "", *enc = NULL; int errcode = 0; + if (fp == stdin) { + /* Fetch encoding from sys.stdin */ + v = PySys_GetObject("stdin"); + if (!v) + return -1; + oenc = PyObject_GetAttrString(v, "encoding"); + if (!oenc) + return -1; + enc = PyUnicode_AsString(oenc); + } v = PySys_GetObject("ps1"); if (v != NULL) { v = PyObject_Str(v); @@ -770,13 +780,15 @@ PyRun_InteractiveOneFlags(FILE *fp, const char *filename, PyCompilerFlags *flags if (arena == NULL) { Py_XDECREF(v); Py_XDECREF(w); + Py_XDECREF(oenc); return -1; } - mod = PyParser_ASTFromFile(fp, filename, + mod = PyParser_ASTFromFile(fp, filename, enc, Py_single_input, ps1, ps2, flags, &errcode, arena); Py_XDECREF(v); Py_XDECREF(w); + Py_XDECREF(oenc); if (mod == NULL) { PyArena_Free(arena); if (errcode == E_EOF) { @@ -1254,7 +1266,7 @@ PyRun_FileExFlags(FILE *fp, const char *filename, int start, PyObject *globals, if (arena == NULL) return NULL; - mod = PyParser_ASTFromFile(fp, filename, start, 0, 0, + mod = PyParser_ASTFromFile(fp, filename, NULL, start, 0, 0, flags, NULL, arena); if (closeit) fclose(fp); @@ -1379,13 +1391,15 @@ PyParser_ASTFromString(const char *s, const char *filename, int start, } mod_ty -PyParser_ASTFromFile(FILE *fp, const char *filename, int start, char *ps1, +PyParser_ASTFromFile(FILE *fp, const char *filename, const char* enc, + int start, char *ps1, char *ps2, PyCompilerFlags *flags, int *errcode, PyArena *arena) { mod_ty mod; perrdetail err; - node *n = PyParser_ParseFileFlags(fp, filename, &_PyParser_Grammar, + node *n = PyParser_ParseFileFlags(fp, filename, enc, + &_PyParser_Grammar, start, ps1, ps2, &err, PARSER_FLAGS(flags)); if (n) { mod = PyAST_FromNode(n, flags, filename, arena); @@ -1406,7 +1420,8 @@ node * PyParser_SimpleParseFileFlags(FILE *fp, const char *filename, int start, int flags) { perrdetail err; - node *n = PyParser_ParseFileFlags(fp, filename, &_PyParser_Grammar, + node *n = PyParser_ParseFileFlags(fp, filename, NULL, + &_PyParser_Grammar, start, NULL, NULL, &err, flags); if (n == NULL) err_input(&err); |