Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pypdf/_cmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,15 @@ def _parse_encoding(
else:
raise Exception("not found")
except Exception:
logger_error(f"Advanced encoding {enc} not implemented yet", __name__)
logger_error("Advanced encoding %(encoding)s not implemented yet", source=__name__, encoding=enc)
encoding = enc
elif isinstance(enc, DictionaryObject) and "/BaseEncoding" in enc:
try:
encoding = charset_encoding[cast(str, enc["/BaseEncoding"])].copy()
except Exception:
logger_error(
f"Advanced encoding {encoding} not implemented yet",
__name__,
"Advanced encoding %(encoding)s not implemented yet",
source=__name__, encoding=encoding
)
encoding = charset_encoding["/StandardEncoding"].copy()
else:
Expand Down
4 changes: 2 additions & 2 deletions pypdf/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ def deprecation_no_replacement(name: str, removed_in: str) -> None:
deprecation(f"{name} is deprecated and was removed in pypdf {removed_in}.")


def logger_error(msg: str, src: str) -> None:
def logger_error(message: str, *, source: str, **values: Any) -> None:
"""
Use this instead of logger.error directly.

Expand All @@ -449,7 +449,7 @@ def logger_error(msg: str, src: str) -> None:
See the docs on when to use which:
https://pypdf.readthedocs.io/en/latest/user/suppress-warnings.html
"""
logging.getLogger(src).error(msg)
logging.getLogger(source).error(message, values)


def logger_warning(msg: str, src: str) -> None:
Expand Down
13 changes: 13 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
deprecate_with_replacement,
deprecation_no_replacement,
format_iso8824_date,
logger_error,
mark_location,
matrix_multiply,
parse_iso8824_date,
Expand All @@ -33,6 +34,7 @@
skip_over_whitespace,
)
from pypdf.errors import DeprecationError, PdfReadError, PdfStreamError
from pypdf.generic import DictionaryObject, NameObject, TextStringObject

from . import is_sublist

Expand Down Expand Up @@ -331,6 +333,17 @@ def foo() -> None:
foo()


def test_logger_error(caplog):
enc = NameObject("/Invalid")
message:str = "Advanced encoding %(encoding)s not implemented yet"
logger_error(message, source=__name__, encoding=enc)
assert "Advanced encoding /Invalid not implemented yet" in caplog.text
encoding = DictionaryObject({NameObject("/key"): TextStringObject("value")})
message = "Advanced encoding %(encoding)s not implemented yet"
logger_error(message, source=__name__, encoding=encoding)
assert "Advanced encoding {'/key': 'value'} not implemented yet" in caplog.text


def test_rename_kwargs():
def deprecation_bookmark_nofail(**aliases: str) -> Callable:
"""
Expand Down
Loading