3030import os
3131import re
3232import struct
33- import warnings
3433import zlib
3534from io import BytesIO
3635from pathlib import Path
5453 b_ ,
5554 deprecate_no_replacement ,
5655 deprecate_with_replacement ,
56+ logger_warning ,
5757 read_non_whitespace ,
5858 read_previous_line ,
5959 read_until_whitespace ,
7070from .constants import PageAttributes as PG
7171from .constants import PagesAttributes as PA
7272from .constants import TrailerKeys as TK
73- from .errors import PdfReadError , PdfReadWarning , PdfStreamError
73+ from .errors import PdfReadError , PdfStreamError
7474from .generic import (
7575 ArrayObject ,
7676 ContentStream ,
@@ -258,10 +258,10 @@ def __init__(
258258 Dict [Any , Any ]
259259 ] = None # map page indirect_ref number to Page Number
260260 if hasattr (stream , "mode" ) and "b" not in stream .mode : # type: ignore
261- warnings . warn (
261+ logger_warning (
262262 "PdfReader stream/file object is not in binary mode. "
263263 "It may not be read correctly." ,
264- PdfReadWarning ,
264+ __name__ ,
265265 )
266266 if isinstance (stream , (str , Path )):
267267 with open (stream , "rb" ) as fh :
@@ -836,7 +836,7 @@ def _build_destination(
836836 try :
837837 return Destination (title , page , typ , * array ) # type: ignore
838838 except PdfReadError :
839- warnings . warn (f"Unknown destination: { title } { array } " , PdfReadWarning )
839+ logger_warning (f"Unknown destination: { title } { array } " , __name__ )
840840 if self .strict :
841841 raise
842842 # create a link to first Page
@@ -1091,11 +1091,11 @@ def _get_object_from_stream(
10911091 except PdfStreamError as exc :
10921092 # Stream object cannot be read. Normally, a critical error, but
10931093 # Adobe Reader doesn't complain, so continue (in strict mode?)
1094- warnings . warn (
1094+ logger_warning (
10951095 f"Invalid stream (index { i } ) within object "
10961096 f"{ indirect_reference .idnum } { indirect_reference .generation } : "
10971097 f"{ exc } " ,
1098- PdfReadWarning ,
1098+ __name__ ,
10991099 )
11001100
11011101 if self .strict :
@@ -1162,10 +1162,10 @@ def get_object(self, indirect_reference: IndirectObject) -> Optional[PdfObject]:
11621162 retval , indirect_reference .idnum , indirect_reference .generation
11631163 )
11641164 else :
1165- warnings . warn (
1165+ logger_warning (
11661166 f"Object { indirect_reference .idnum } { indirect_reference .generation } "
11671167 "not defined." ,
1168- PdfReadWarning ,
1168+ __name__ ,
11691169 )
11701170 if self .strict :
11711171 raise PdfReadError ("Could not find object." )
@@ -1207,9 +1207,9 @@ def read_object_header(self, stream: StreamType) -> Tuple[int, int]:
12071207 read_non_whitespace (stream )
12081208 stream .seek (- 1 , 1 )
12091209 if extra and self .strict :
1210- warnings . warn (
1210+ logger_warning (
12111211 f"Superfluous whitespace found in object header { idnum } { generation } " , # type: ignore
1212- PdfReadWarning ,
1212+ __name__ ,
12131213 )
12141214 return int (idnum ), int (generation )
12151215
@@ -1250,7 +1250,7 @@ def cache_indirect_object(
12501250 if self .strict :
12511251 raise PdfReadError (msg )
12521252 else :
1253- warnings . warn (msg )
1253+ logger_warning (msg , __name__ )
12541254 self .resolved_objects [(generation , idnum )] = obj
12551255 return obj
12561256
@@ -1276,8 +1276,8 @@ def read(self, stream: StreamType) -> None:
12761276 if self .strict and xref_issue_nr :
12771277 raise PdfReadError ("Broken xref table" )
12781278 else :
1279- warnings . warn (
1280- f"incorrect startxref pointer({ xref_issue_nr } )" , PdfReadWarning
1279+ logger_warning (
1280+ f"incorrect startxref pointer({ xref_issue_nr } )" , __name__
12811281 )
12821282
12831283 # read all cross reference tables and their trailers
@@ -1335,7 +1335,7 @@ def _find_startxref_pos(self, stream: StreamType) -> int:
13351335 if not line .startswith (b"startxref" ):
13361336 raise PdfReadError ("startxref not found" )
13371337 startxref = int (line [9 :].strip ())
1338- warnings . warn ("startxref on same line as offset" , PdfReadWarning )
1338+ logger_warning ("startxref on same line as offset" , __name__ )
13391339 else :
13401340 line = read_previous_line (stream )
13411341 if line [:9 ] != b"startxref" :
@@ -1355,9 +1355,9 @@ def _read_standard_xref_table(self, stream: StreamType) -> None:
13551355 if firsttime and num != 0 :
13561356 self .xref_index = num
13571357 if self .strict :
1358- warnings . warn (
1358+ logger_warning (
13591359 "Xref table not zero-indexed. ID numbers for objects will be corrected." ,
1360- PdfReadWarning ,
1360+ __name__ ,
13611361 )
13621362 # if table not zero indexed, could be due to error from when PDF was created
13631363 # which will lead to mismatched indices later on, only warned and corrected if self.strict==True
@@ -1474,9 +1474,10 @@ def _read_xref_other_error(
14741474 "/Prev=0 in the trailer (try opening with strict=False)"
14751475 )
14761476 else :
1477- warnings . warn (
1477+ logger_warning (
14781478 "/Prev=0 in the trailer - assuming there"
1479- " is no previous xref table"
1479+ " is no previous xref table" ,
1480+ __name__ ,
14801481 )
14811482 return None
14821483 # bad xref character at startxref. Let's see if we can find
@@ -1502,7 +1503,7 @@ def _read_xref_other_error(
15021503 # no xref table found at specified location
15031504 if "/Root" in self .trailer and not self .strict :
15041505 # if Root has been already found, just raise warning
1505- warnings . warn ("Invalid parent xref., rebuild xref" , PdfReadWarning )
1506+ logger_warning ("Invalid parent xref., rebuild xref" , __name__ )
15061507 try :
15071508 self ._rebuild_xref_table (stream )
15081509 return None
0 commit comments