@@ -642,6 +642,7 @@ def read_doc(self, docname: str, *, _cache: bool = True) -> None:
642
642
filename = env .doc2path (docname )
643
643
644
644
# set up error_handler for the target document
645
+ # xref RemovedInSphinx90Warning
645
646
error_handler = _UnicodeDecodeErrorHandler (docname )
646
647
codecs .register_error ('sphinx' , error_handler ) # type: ignore[arg-type]
647
648
@@ -903,20 +904,21 @@ def __init__(self, docname: str, /) -> None:
903
904
self .docname = docname
904
905
905
906
def __call__ (self , error : UnicodeDecodeError ) -> tuple [str , int ]:
906
- line_start = error .object .rfind (b'\n ' , 0 , error .start )
907
- line_end = error .object .find (b'\n ' , error .start )
907
+ obj = error .object
908
+ line_start = obj .rfind (b'\n ' , 0 , error .start )
909
+ line_end = obj .find (b'\n ' , error .start )
908
910
if line_end == - 1 :
909
- line_end = len (error . object )
910
- line_num = error . object .count (b'\n ' , 0 , error .start ) + 1
911
+ line_end = len (obj )
912
+ line_num = obj .count (b'\n ' , 0 , error .start ) + 1
911
913
logger .warning (
912
- __ ('undecodable source characters, replacing with "?": %r' ),
913
- (
914
- error .object [line_start + 1 : error .start ]
915
- + b'>>>'
916
- + error .object [error .start : error .end ]
917
- + b'<<<'
918
- + error .object [error .end : line_end ]
914
+ __ (
915
+ "undecodable source characters, replacing with '?': '%s>>>%s<<<%s'. "
916
+ 'This will become an error in Sphinx 9.0.'
917
+ # xref RemovedInSphinx90Warning
919
918
),
919
+ obj [line_start + 1 : error .start ].decode (errors = 'backslashreplace' ),
920
+ obj [error .start : error .end ].decode (errors = 'backslashreplace' ),
921
+ obj [error .end : line_end ].decode (errors = 'backslashreplace' ),
920
922
location = (self .docname , line_num ),
921
923
)
922
924
return '?' , error .end
0 commit comments