Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STY: Docstring formatting #1033

Merged
merged 4 commits into from
Jun 28, 2022
Merged
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
163 changes: 102 additions & 61 deletions PyPDF2/_encryption.py

Large diffs are not rendered by default.

35 changes: 11 additions & 24 deletions PyPDF2/_merger.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,7 @@


class _MergedPage:
"""
_MergedPage is used internally by PdfMerger to collect necessary
information on each page that is being merged.
"""
"""Collect necessary information on each page that is being merged."""

def __init__(self, pagedata: PageObject, src: PdfReader, id: int) -> None:
self.src = src
Expand All @@ -75,9 +72,10 @@ def __init__(self, pagedata: PageObject, src: PdfReader, id: int) -> None:

class PdfMerger:
"""
Initializes a ``PdfMerger`` object. ``PdfMerger`` merges multiple
PDFs into a single PDF. It can concatenate, slice, insert, or any
combination of the above.
Initialize a ``PdfMerger`` object.

``PdfMerger`` merges multiple PDFs into a single PDF.
It can concatenate, slice, insert, or any combination of the above.

See the functions :meth:`merge()<merge>` (or :meth:`append()<append>`)
and :meth:`write()<write>` for usage information.
Expand Down Expand Up @@ -105,7 +103,7 @@ def merge(
import_bookmarks: bool = True,
) -> None:
"""
Merges the pages from the given file into the output file at the
Merge the pages from the given file into the output file at the
specified page number.

:param int position: The *page number* to insert this file. File will
Expand All @@ -127,7 +125,6 @@ def merge(
:param bool import_bookmarks: You may prevent the source document's
bookmarks from being imported by specifying this as ``False``.
"""

stream, my_file, encryption_obj = self._create_stream(fileobj)

# Create a new PdfReader instance using the stream
Expand Down Expand Up @@ -253,7 +250,7 @@ def append(

def write(self, fileobj: StrByteType) -> None:
"""
Writes all data that has been merged to the given output file.
Write all data that has been merged to the given output file.

:param fileobj: Output file. Can be a filename or any kind of
file-like object.
Expand Down Expand Up @@ -288,10 +285,7 @@ def write(self, fileobj: StrByteType) -> None:
fileobj.close()

def close(self) -> None:
"""
Shuts all file descriptors (input and output) and clears all memory
usage.
"""
"""Shut all file descriptors (input and output) and clear all memory usage."""
self.pages = []
for fo, _reader, mine in self.inputs:
if mine:
Expand Down Expand Up @@ -332,7 +326,7 @@ def setPageLayout(self, layout: LayoutType) -> None: # pragma: no cover

def set_page_layout(self, layout: LayoutType) -> None:
"""
Set the page layout
Set the page layout.

:param str layout: The page layout to be used

Expand Down Expand Up @@ -399,10 +393,7 @@ def _trim_dests(
dests: Dict[str, Dict[str, Any]],
pages: Union[Tuple[int, int], Tuple[int, int, int]],
) -> List[Dict[str, Any]]:
"""
Removes any named destinations that are not a part of the specified
page set.
"""
"""Remove named destinations that are not a part of the specified page set."""
new_dests = []
for key, obj in dests.items():
for j in range(*pages):
Expand All @@ -419,10 +410,7 @@ def _trim_outline(
outline: OutlinesType,
pages: Union[Tuple[int, int], Tuple[int, int, int]],
) -> OutlinesType:
"""
Removes any outline/bookmark entries that are not a part of the
specified page set.
"""
"""Remove outline/bookmark entries that are not a part of the specified page set."""
new_outline = []
prev_header_added = True
for i, o in enumerate(outline):
Expand Down Expand Up @@ -680,7 +668,6 @@ def add_named_destination(self, title: str, pagenum: int) -> None:
:param str title: Title to use
:param int pagenum: Page number this destination points at.
"""

dest = Destination(
TextStringObject(title),
NumberObject(pagenum),
Expand Down
27 changes: 15 additions & 12 deletions PyPDF2/_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,7 @@ def create_blank_page(
space units.
:param float height: The height of the new page expressed in default user
space units.
:return: the new blank page:
:rtype: :class:`PageObject<PageObject>`
:return: the new blank page
:raises PageSizeNotDefinedError: if ``pdf`` is ``None`` or contains
no page
"""
Expand Down Expand Up @@ -1118,7 +1117,6 @@ def _extract_text(
default = "/Content"
:return: a string object.
"""

text: str = ""
output: str = ""
cmaps: Dict[
Expand Down Expand Up @@ -1301,25 +1299,30 @@ def extract_text(
) -> str:
"""
Locate all text drawing commands, in the order they are provided in the
content stream, and extract the text. This works well for some PDF
files, but poorly for others, depending on the generator used. This will
be refined in the future. Do not rely on the order of text coming out of
this function, as it will change if this function is made more
sophisticated.
space_width : float = force default space width (if not extracted from font (default 200)
content stream, and extract the text.

:return: a string object.
This works well for some PDF files, but poorly for others, depending on
the generator used. This will be refined in the future.

Do not rely on the order of text coming out of this function, as it
will change if this function is made more sophisticated.


:param space_width : force default space width (if not extracted from font (default 200)

:return: The extracted text
"""
return self._extract_text(self, self.pdf, space_width, PG.CONTENTS)

def extract_xform_text(
self, xform: EncodedStreamObject, space_width: float = 200.0
) -> str:
"""
Extraction tet from an XObject.
Extract text from an XObject.

space_width : float = force default space width (if not extracted from font (default 200)

:return: a string object.
:return: The extracted text
"""
return self._extract_text(xform, self.pdf, space_width, None)

Expand Down
Loading