@@ -545,6 +545,7 @@ decoding_fgets(char *s, int size, struct tok_state *tok)
545545{
546546 char * line = NULL ;
547547 int badchar = 0 ;
548+ PyObject * filename ;
548549 for (;;) {
549550 if (tok -> decoding_state == STATE_NORMAL ) {
550551 /* We already have a codec associated with
@@ -585,12 +586,16 @@ decoding_fgets(char *s, int size, struct tok_state *tok)
585586 if (badchar ) {
586587 /* Need to add 1 to the line number, since this line
587588 has not been counted, yet. */
588- PyErr_Format (PyExc_SyntaxError ,
589- "Non-UTF-8 code starting with '\\x%.2x' "
590- "in file %.200s on line %i, "
591- "but no encoding declared; "
592- "see http://python.org/dev/peps/pep-0263/ for details" ,
593- badchar , tok -> filename , tok -> lineno + 1 );
589+ filename = PyUnicode_DecodeFSDefault (tok -> filename );
590+ if (filename != NULL ) {
591+ PyErr_Format (PyExc_SyntaxError ,
592+ "Non-UTF-8 code starting with '\\x%.2x' "
593+ "in file %.200U on line %i, "
594+ "but no encoding declared; "
595+ "see http://python.org/dev/peps/pep-0263/ for details" ,
596+ badchar , filename , tok -> lineno + 1 );
597+ Py_DECREF (filename );
598+ }
594599 return error_ret (tok );
595600 }
596601#endif
0 commit comments