diff options
author | Guido van Rossum <guido@python.org> | 2007-10-19 23:16:50 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2007-10-19 23:16:50 (GMT) |
commit | ce3a72aec6eaa0293c397c8d0407f7afe0072b2f (patch) | |
tree | 646cf27667087a48b908f330759fb94271b43f60 /Python/import.c | |
parent | 75a902db7859a4751743e98530c5d96a672641be (diff) | |
download | cpython-ce3a72aec6eaa0293c397c8d0407f7afe0072b2f.zip cpython-ce3a72aec6eaa0293c397c8d0407f7afe0072b2f.tar.gz cpython-ce3a72aec6eaa0293c397c8d0407f7afe0072b2f.tar.bz2 |
Patch 1267 by Christian Heimes.
Move the initialization of sys.std{in,out,err} and __builtin__.open
to C code.
This solves the problem that "python -S" wouldn't work.
Diffstat (limited to 'Python/import.c')
-rw-r--r-- | Python/import.c | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/Python/import.c b/Python/import.c index 21dcbd4..323b55a 100644 --- a/Python/import.c +++ b/Python/import.c @@ -91,6 +91,9 @@ static PyObject *extensions = NULL; /* This table is defined in config.c: */ extern struct _inittab _PyImport_Inittab[]; +/* Method from Parser/tokenizer.c */ +extern char * PyTokenizer_FindEncoding(FILE *fp); + struct _inittab *PyImport_Inittab = _PyImport_Inittab; /* these tables define the module suffixes that Python recognizes */ @@ -2558,6 +2561,7 @@ call_find_module(char *name, PyObject *path) struct filedescr *fdp; char pathname[MAXPATHLEN+1]; FILE *fp = NULL; + char *encoding = NULL; pathname[0] = '\0'; if (path == Py_None) @@ -2566,7 +2570,14 @@ call_find_module(char *name, PyObject *path) if (fdp == NULL) return NULL; if (fp != NULL) { - fob = PyFile_FromFile(fp, pathname, fdp->mode, fclose); + if (strchr(fdp->mode, 'b') == NULL) { + /* Python text file, get encoding from tokenizer */ + encoding = PyTokenizer_FindEncoding(fp); + encoding = (encoding != NULL) ? encoding : + (char*)PyUnicode_GetDefaultEncoding(); + } + fob = PyFile_FromFileEx(fp, pathname, fdp->mode, fclose, -1, + (char*)encoding, NULL); if (fob == NULL) { fclose(fp); return NULL; |