Change non-ASCII warning into a SyntaxError.

This commit is contained in:
Martin v. Löwis 2006-02-28 22:41:29 +00:00
parent e4d3a72ab8
commit 6cba25666c
1 changed files with 6 additions and 10 deletions

View File

@ -127,7 +127,6 @@ tok_new(void)
tok->decoding_state = 0; tok->decoding_state = 0;
tok->decoding_erred = 0; tok->decoding_erred = 0;
tok->read_coding_spec = 0; tok->read_coding_spec = 0;
tok->issued_encoding_warning = 0;
tok->encoding = NULL; tok->encoding = NULL;
tok->cont_line = 0; tok->cont_line = 0;
#ifndef PGEN #ifndef PGEN
@ -462,7 +461,7 @@ static char *
decoding_fgets(char *s, int size, struct tok_state *tok) decoding_fgets(char *s, int size, struct tok_state *tok)
{ {
char *line = NULL; char *line = NULL;
int warn = 0, badchar = 0; int badchar = 0;
for (;;) { for (;;) {
if (tok->decoding_state < 0) { if (tok->decoding_state < 0) {
/* We already have a codec associated with /* We already have a codec associated with
@ -473,7 +472,6 @@ decoding_fgets(char *s, int size, struct tok_state *tok)
/* We want a 'raw' read. */ /* We want a 'raw' read. */
line = Py_UniversalNewlineFgets(s, size, line = Py_UniversalNewlineFgets(s, size,
tok->fp, NULL); tok->fp, NULL);
warn = 1;
break; break;
} else { } else {
/* We have not yet determined the encoding. /* We have not yet determined the encoding.
@ -490,7 +488,9 @@ decoding_fgets(char *s, int size, struct tok_state *tok)
} }
} }
#ifndef PGEN #ifndef PGEN
if (warn && line && !tok->issued_encoding_warning && !tok->encoding) { /* The default encoding is ASCII, so make sure we don't have any
non-ASCII bytes in it. */
if (line && !tok->encoding) {
unsigned char *c; unsigned char *c;
for (c = (unsigned char *)line; *c; c++) for (c = (unsigned char *)line; *c; c++)
if (*c > 127) { if (*c > 127) {
@ -508,12 +508,8 @@ decoding_fgets(char *s, int size, struct tok_state *tok)
"but no encoding declared; " "but no encoding declared; "
"see http://www.python.org/peps/pep-0263.html for details", "see http://www.python.org/peps/pep-0263.html for details",
badchar, tok->filename, tok->lineno + 1); badchar, tok->filename, tok->lineno + 1);
/* We don't use PyErr_WarnExplicit() here because PyErr_SetString(PyExc_SyntaxError, buf);
printing the line in question to e.g. a log file return error_ret(tok);
could result in sensitive information being
exposed. */
PyErr_Warn(PyExc_DeprecationWarning, buf);
tok->issued_encoding_warning = 1;
} }
#endif #endif
return line; return line;