Skip to content

Commit

Permalink
STY: Move is_encrypted below __init__ in PdfWriter (#2659)
Browse files Browse the repository at this point in the history
Plus tiny documentation changes
  • Loading branch information
j-t-1 committed May 20, 2024
1 parent 1117278 commit f6fca0c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions pypdf/_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def _info(self) -> Optional[DictionaryObject]:
Provide access to "/Info". standardized with PdfWriter.
Returns:
/Info Dictionary ; None if the entry does not exists
/Info Dictionary; None if the entry does not exist
"""
info = self.trailer.get(TK.INFO, None)
if info is None:
Expand All @@ -183,7 +183,7 @@ def _ID(self) -> Optional[ArrayObject]:
Provide access to "/ID". standardized with PdfWriter.
Returns:
/ID array ; None if the entry does not exists
/ID array; None if the entry does not exist
"""
id = self.trailer.get(TK.ID, None)
return None if id is None else cast(ArrayObject, id.get_object())
Expand Down
24 changes: 12 additions & 12 deletions pypdf/_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,17 +154,6 @@ class PdfWriter(PdfDocCommon):
Typically data is added from a :class:`PdfReader<pypdf.PdfReader>`.
"""

# for commonality
@property
def is_encrypted(self) -> bool:
"""
Read-only boolean property showing whether this PDF file is encrypted.
Note that this property, if true, will remain true even after the
:meth:`decrypt()<pypdf.PdfReader.decrypt>` method is called.
"""
return False

def __init__(
self,
fileobj: Union[None, PdfReader, StrByteType, Path] = "",
Expand Down Expand Up @@ -252,6 +241,17 @@ def _get_clone_from(
self._encrypt_entry: Optional[DictionaryObject] = None
self._ID: Union[ArrayObject, None] = None

# for commonality
@property
def is_encrypted(self) -> bool:
"""
Read-only boolean property showing whether this PDF file is encrypted.
Note that this property, if true, will remain true even after the
:meth:`decrypt()<pypdf.PdfReader.decrypt>` method is called.
"""
return False

@property
def root_object(self) -> DictionaryObject:
"""
Expand Down Expand Up @@ -2471,7 +2471,7 @@ def merge(
elif isinstance(dest["/Page"], NullObject):
pass
elif isinstance(dest["/Page"], int):
# the page reference is a page number normally not iaw Pdf Reference
# the page reference is a page number normally not a PDF Reference
# page numbers as int are normally accepted only in external goto
p = reader.pages[dest["/Page"]]
assert p.indirect_reference is not None
Expand Down

0 comments on commit f6fca0c

Please sign in to comment.