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
4 changes: 2 additions & 2 deletions pypdf/_codecs/_codecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,10 @@ def _next_code_decode(self, data: bytes) -> int:
# Reduce data to get rid of the overhead,
# which increases performance on large streams significantly.
self._next_data = self._next_data & 0xFFFFF

return code
except IndexError:
return self.EOD_MARKER
else:
return code

# The following method has been converted to Python from PDFsharp:
# https://github.com/empira/PDFsharp/blob/5fbf6ed14740bc4e16786816882d32e43af3ff5d/src/foundation/src/PDFsharp/src/PdfSharp/Pdf.Filters/LzwDecode.cs
Expand Down
3 changes: 2 additions & 1 deletion pypdf/_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -1044,9 +1044,10 @@ def _read_xref_other_error(
logger_warning("Invalid parent xref., rebuild xref", __name__)
try:
self._rebuild_xref_table(stream)
return None
except Exception:
raise PdfReadError("Cannot rebuild xref")
else:
return None
raise PdfReadError("Could not find xref table at specified location")

def _sanitize_pdf15_xref_stream_index_pairs(
Expand Down
3 changes: 2 additions & 1 deletion pypdf/generic/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,10 @@ def create_string_object(
retval = TextStringObject(decode_pdfdocencoding(string))
retval._original_bytes = string
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it make sense to move this and the following line into the else block as well? They should not raise an UnicodeDecodeError.

retval.autodetect_pdfdocencoding = True
return retval
except UnicodeDecodeError:
return ByteStringObject(string)
else:
return retval
else:
raise TypeError("create_string_object should have str or unicode arg")

Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ ignore = [
"TRY003", # Avoid specifying long messages outside the exception class
"TRY004", # Prefer `TypeError` exception for invalid type
"TRY201", # Use `raise` without specifying exception name
"TRY300", # Consider moving this statement to an `else` block
"TRY301", # Abstract `raise` to an inner function
"UP006", # Non-PEP 585 annotation. As long as we are not on Python 3.11+
"UP007", # Non-PEP 604 annotation. As long as we are not on Python 3.11+
Expand Down
Loading