@@ -127,7 +127,6 @@ tok_new(void)
127127 tok -> decoding_state = 0 ;
128128 tok -> decoding_erred = 0 ;
129129 tok -> read_coding_spec = 0 ;
130- tok -> issued_encoding_warning = 0 ;
131130 tok -> encoding = NULL ;
132131 tok -> cont_line = 0 ;
133132#ifndef PGEN
@@ -462,7 +461,7 @@ static char *
462461decoding_fgets (char * s , int size , struct tok_state * tok )
463462{
464463 char * line = NULL ;
465- int warn = 0 , badchar = 0 ;
464+ int badchar = 0 ;
466465 for (;;) {
467466 if (tok -> decoding_state < 0 ) {
468467 /* We already have a codec associated with
@@ -473,7 +472,6 @@ decoding_fgets(char *s, int size, struct tok_state *tok)
473472 /* We want a 'raw' read. */
474473 line = Py_UniversalNewlineFgets (s , size ,
475474 tok -> fp , NULL );
476- warn = 1 ;
477475 break ;
478476 } else {
479477 /* We have not yet determined the encoding.
@@ -490,7 +488,9 @@ decoding_fgets(char *s, int size, struct tok_state *tok)
490488 }
491489 }
492490#ifndef PGEN
493- if (warn && line && !tok -> issued_encoding_warning && !tok -> encoding ) {
491+ /* The default encoding is ASCII, so make sure we don't have any
492+ non-ASCII bytes in it. */
493+ if (line && !tok -> encoding ) {
494494 unsigned char * c ;
495495 for (c = (unsigned char * )line ; * c ; c ++ )
496496 if (* c > 127 ) {
@@ -508,12 +508,8 @@ decoding_fgets(char *s, int size, struct tok_state *tok)
508508 "but no encoding declared; "
509509 "see http://www.python.org/peps/pep-0263.html for details" ,
510510 badchar , tok -> filename , tok -> lineno + 1 );
511- /* We don't use PyErr_WarnExplicit() here because
512- printing the line in question to e.g. a log file
513- could result in sensitive information being
514- exposed. */
515- PyErr_Warn (PyExc_DeprecationWarning , buf );
516- tok -> issued_encoding_warning = 1 ;
511+ PyErr_SetString (PyExc_SyntaxError , buf );
512+ return error_ret (tok );
517513 }
518514#endif
519515 return line ;
0 commit comments