Skip to content

Commit

Permalink
DOC: Comment changes in PdfReader (py-pdf#2990)
Browse files Browse the repository at this point in the history
  • Loading branch information
j-t-1 authored Dec 5, 2024
1 parent 3afc3c0 commit 27edc06
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions pypdf/_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ def __init__(
) -> None:
self.strict = strict
self.flattened_pages: Optional[List[PageObject]] = None

#: Storage of parsed PDF objects.
self.resolved_objects: Dict[Tuple[Any, Any], Optional[PdfObject]] = {}

Expand Down Expand Up @@ -430,7 +431,7 @@ def get_object(
idnum = -1
generation = -1 # exception will be raised below
if idnum != indirect_reference.idnum and self.xref_index:
# Xref table probably had bad indexes due to not being zero-indexed
# xref table probably had bad indexes due to not being zero-indexed
if self.strict:
raise PdfReadError(
f"Expected object ID ({indirect_reference.idnum} {indirect_reference.generation}) "
Expand All @@ -441,9 +442,8 @@ def get_object(
elif idnum != indirect_reference.idnum and self.strict:
# some other problem
raise PdfReadError(
f"Expected object ID ({indirect_reference.idnum} "
f"{indirect_reference.generation}) does not match actual "
f"({idnum} {generation})."
f"Expected object ID ({indirect_reference.idnum} {indirect_reference.generation}) "
f"does not match actual ({idnum} {generation})."
)
if self.strict:
assert generation == indirect_reference.generation
Expand Down Expand Up @@ -511,7 +511,7 @@ def get_object(
def read_object_header(self, stream: StreamType) -> Tuple[int, int]:
# Should never be necessary to read out whitespace, since the
# cross-reference table should put us in the right spot to read the
# object header. In reality some files have stupid cross reference
# object header. In reality some files have stupid cross-reference
# tables that are off by whitespace bytes.
extra = False
skip_over_comment(stream)
Expand Down Expand Up @@ -558,7 +558,7 @@ def cache_indirect_object(
return obj

def _replace_object(self, indirect: IndirectObject, obj: PdfObject) -> PdfObject:
# function reserved for future dev
# function reserved for future development
if indirect.pdf != self:
raise ValueError("Cannot update PdfReader with external object")
if (indirect.generation, indirect.idnum) not in self.resolved_objects:
Expand All @@ -580,14 +580,14 @@ def read(self, stream: StreamType) -> None:
startxref = self._find_startxref_pos(stream)
self._startxref = startxref

# check and eventually correct the startxref only in not strict
# check and eventually correct the startxref only if not strict
xref_issue_nr = self._get_xref_issues(stream, startxref)
if xref_issue_nr != 0:
if self.strict and xref_issue_nr:
raise PdfReadError("Broken xref table")
logger_warning(f"incorrect startxref pointer({xref_issue_nr})", __name__)

# read all cross reference tables and their trailers
# read all cross-reference tables and their trailers
self._read_xref_tables_and_trailers(stream, startxref, xref_issue_nr)

# if not zero-indexed, verify that the table is correct; change it if necessary
Expand All @@ -598,7 +598,7 @@ def read(self, stream: StreamType) -> None:
continue
xref_k = sorted(
xref_entry.keys()
) # must ensure ascendant to prevent damage
) # ensure ascending to prevent damage
for id in xref_k:
stream.seek(xref_entry[id], 0)
try:
Expand Down Expand Up @@ -962,8 +962,8 @@ def _read_pdf15_xref_stream(
assert cast(str, xrefstream["/Type"]) == "/XRef"
self.cache_indirect_object(generation, idnum, xrefstream)
stream_data = BytesIO(xrefstream.get_data())
# Index pairs specify the subsections in the dictionary. If
# none create one subsection that spans everything.
# Index pairs specify the subsections in the dictionary.
# If none, create one subsection that spans everything.
idx_pairs = xrefstream.get("/Index", [0, xrefstream.get("/Size")])
entry_sizes = cast(Dict[Any, Any], xrefstream.get("/W"))
assert len(entry_sizes) >= 3
Expand Down Expand Up @@ -1067,7 +1067,7 @@ def _rebuild_xref_table(self, stream: StreamType) -> None:
f" whereas {o.get('/N')} expected",
__name__,
)
except Exception: # could be of many cause
except Exception: # could be multiple causes
pass

stream.seek(0, 0)
Expand Down Expand Up @@ -1174,7 +1174,7 @@ def add_form_topname(self, name: str) -> Optional[DictionaryObject]:
return None
acroform = cast(DictionaryObject, catalog[NameObject("/AcroForm")])
if "/Fields" not in acroform:
# TODO: :No error returns but may be extended for XFA Forms
# TODO: No error but this may be extended for XFA Forms
return None

interim = DictionaryObject()
Expand Down

0 comments on commit 27edc06

Please sign in to comment.