Mass checkin of universal newline support.

Highlights: import and friends will understand any of \r, \n and \r\n
as end of line. Python file input will do the same if you use mode 'U'.
Everything can be disabled by configuring with --without-universal-newlines.

See PEP278 for details.
This commit is contained in:
Jack Jansen 2002-04-14 20:12:41 +00:00
parent dcd2dc2fff
commit 7b8c7546eb
15 changed files with 390 additions and 35 deletions

View file

@ -594,7 +594,7 @@ builtin_execfile(PyObject *self, PyObject *args)
if (exists) {
Py_BEGIN_ALLOW_THREADS
fp = fopen(filename, "r");
fp = fopen(filename, "r" PY_STDIOTEXTMODE);
Py_END_ALLOW_THREADS
if (fp == NULL) {

View file

@ -646,14 +646,14 @@ PyErr_ProgramText(char *filename, int lineno)
if (filename == NULL || lineno <= 0)
return NULL;
fp = fopen(filename, "r");
fp = fopen(filename, "r" PY_STDIOTEXTMODE);
if (fp == NULL)
return NULL;
for (i = 0; i < lineno; i++) {
char *pLastChar = &linebuf[sizeof(linebuf) - 2];
do {
*pLastChar = '\0';
if (fgets(linebuf, sizeof linebuf, fp) == NULL)
if (Py_UniversalNewlineFgets(linebuf, sizeof linebuf, fp, NULL) == NULL)
break;
/* fgets read *something*; if it didn't get as
far as pLastChar, it must have found a newline

View file

@ -81,15 +81,15 @@ struct filedescr * _PyImport_Filetab = NULL;
#ifdef RISCOS
static const struct filedescr _PyImport_StandardFiletab[] = {
{"/py", "r", PY_SOURCE},
{"/py", "r" PY_STDIOTEXTMODE, PY_SOURCE},
{"/pyc", "rb", PY_COMPILED},
{0, 0}
};
#else
static const struct filedescr _PyImport_StandardFiletab[] = {
{".py", "r", PY_SOURCE},
{".py", "r" PY_STDIOTEXTMODE, PY_SOURCE},
#ifdef MS_WIN32
{".pyw", "r", PY_SOURCE},
{".pyw", "r" PY_STDIOTEXTMODE, PY_SOURCE},
#endif
{".pyc", "rb", PY_COMPILED},
{0, 0}

View file

@ -155,7 +155,7 @@ tb_displayline(PyObject *f, char *filename, int lineno, char *name)
/* This is needed by Emacs' compile command */
#define FMT " File \"%.500s\", line %d, in %.500s\n"
#endif
xfp = fopen(filename, "r");
xfp = fopen(filename, "r" PY_STDIOTEXTMODE);
if (xfp == NULL) {
/* Search tail of filename in sys.path before giving up */
PyObject *path;
@ -186,7 +186,7 @@ tb_displayline(PyObject *f, char *filename, int lineno, char *name)
if (len > 0 && namebuf[len-1] != SEP)
namebuf[len++] = SEP;
strcpy(namebuf+len, tail);
xfp = fopen(namebuf, "r");
xfp = fopen(namebuf, "r" PY_STDIOTEXTMODE);
if (xfp != NULL) {
filename = namebuf;
break;
@ -203,7 +203,7 @@ tb_displayline(PyObject *f, char *filename, int lineno, char *name)
char* pLastChar = &linebuf[sizeof(linebuf)-2];
do {
*pLastChar = '\0';
if (fgets(linebuf, sizeof linebuf, xfp) == NULL)
if (Py_UniversalNewlineFgets(linebuf, sizeof linebuf, xfp, NULL) == NULL)
break;
/* fgets read *something*; if it didn't get as
far as pLastChar, it must have found a newline