From 5834669a98dc2835c3d83ce4ebc531ef572cba27 Mon Sep 17 00:00:00 2001 From: Matthew Peveler Date: Wed, 22 Jun 2022 01:24:15 -0400 Subject: [PATCH 1/3] DOC: Mention crypto extra_requires for installation (#1017) --- README.md | 8 ++++++++ docs/user/encryption-decryption.md | 4 ++++ docs/user/installation.md | 8 ++++++++ 3 files changed, 20 insertions(+) diff --git a/README.md b/README.md index dca927584..0bf8211b0 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,14 @@ You can install PyPDF2 via pip: pip install PyPDF2 ``` +If you plan to use PyPDF2 for encrypting or decrypting PDFs that use AES, you +will need to install some extra dependencies. Encryption using RC4 is supported +using the regular installation. + +``` +pip install PyPDF2[crypto] +``` + ## Usage ```python diff --git a/docs/user/encryption-decryption.md b/docs/user/encryption-decryption.md index a6db79920..22e1d100b 100644 --- a/docs/user/encryption-decryption.md +++ b/docs/user/encryption-decryption.md @@ -1,5 +1,9 @@ # Encryption and Decryption of PDFs +Please see the note in the +[Installation doc](https://pypdf2.readthedocs.io/en/latest/user/installation.html) +for installing the extra dependencies if interacting with PDFs that use AES. + ## Encrypt Add a password to a PDF (encrypt it): diff --git a/docs/user/installation.md b/docs/user/installation.md index fef09f65e..d9b382451 100644 --- a/docs/user/installation.md +++ b/docs/user/installation.md @@ -20,6 +20,14 @@ install PyPDF2 for your current user: pip install --user PyPDF2 ``` +If you plan to use PyPDF2 for encrypting or decrypting PDFs that use AES, you +will need to install some extra dependencies. Encryption using RC4 is supported +using the regular installation. + +``` +pip install PyPDF2[crypto] +``` + ## Anaconda Anaconda users can [install PyPDF2 via conda-forge](https://anaconda.org/conda-forge/pypdf2). From 187224a2be5241b99b80a4f7059e3a4d95c5423d Mon Sep 17 00:00:00 2001 From: Martin Thoma Date: Wed, 22 Jun 2022 22:50:36 +0200 Subject: [PATCH 2/3] DOC: Adjust PdfWriter.add_uri docstring --- PyPDF2/_writer.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/PyPDF2/_writer.py b/PyPDF2/_writer.py index b2ce6c382..80565dc6f 100644 --- a/PyPDF2/_writer.py +++ b/PyPDF2/_writer.py @@ -1340,7 +1340,7 @@ def add_uri( ) -> None: """ Add an URI from a rectangular area to the specified page. - This uses the basic structure of AddLink + This uses the basic structure of :meth:`add_link` :param int pagenum: index of the page on which to place the URI action. :param int uri: string -- uri of resource to link to. @@ -1350,9 +1350,6 @@ def add_uri( :param border: if provided, an array describing border-drawing properties. See the PDF spec for details. No border will be drawn if this argument is omitted. - - REMOVED FIT/ZOOM ARG - -John Mulligan """ page_link = self.get_object(self._pages)[PA.KIDS][pagenum] # type: ignore From 7d820f043ad56e0cc9dabb3921f1d64416777452 Mon Sep 17 00:00:00 2001 From: Martin Thoma Date: Thu, 23 Jun 2022 20:27:15 +0200 Subject: [PATCH 3/3] DEV: Adjust string formatting to be able to use mutmut (#1020) Relates to https://github.com/davidhalter/parso/issues/207 Additionally, make Makefile more consistent --- Makefile | 2 +- PyPDF2/generic.py | 6 +++++- mutmut-test.sh | 1 + tests/test_writer.py | 1 + 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 29e6f5f3e..caa6c463d 100644 --- a/Makefile +++ b/Makefile @@ -25,7 +25,7 @@ testtype: mutation-test: mutmut run -mutmut-results: +mutation-results: mutmut junitxml --suspicious-policy=ignore --untested-policy=ignore > mutmut-results.xml junit2html mutmut-results.xml mutmut-results.html diff --git a/PyPDF2/generic.py b/PyPDF2/generic.py index 719b6948c..3b2a7c8d4 100644 --- a/PyPDF2/generic.py +++ b/PyPDF2/generic.py @@ -565,7 +565,11 @@ def write_to_stream( stream.write(b"(") for c in bytearr: if not chr(c).isalnum() and c != b" ": - stream.write(b_(rf"\{c:0>3o}")) + # This: + # stream.write(b_(rf"\{c:0>3o}")) + # gives + # https://github.com/davidhalter/parso/issues/207 + stream.write(b_("\\%03o" % c)) else: stream.write(b_(chr(c))) stream.write(b")") diff --git a/mutmut-test.sh b/mutmut-test.sh index 2284ed765..39dfb2272 100755 --- a/mutmut-test.sh +++ b/mutmut-test.sh @@ -1,2 +1,3 @@ #!/bin/bash -e pytest -x +mypy PyPDF2 --show-error-codes --disallow-untyped-defs --disallow-incomplete-defs --ignore-missing-imports diff --git a/tests/test_writer.py b/tests/test_writer.py index 332e3dbff..a412e352f 100644 --- a/tests/test_writer.py +++ b/tests/test_writer.py @@ -291,6 +291,7 @@ def test_encrypt(use_128bit): reader = PdfReader(tmp_filename, password="userpwd") new_text = reader.pages[0].extract_text() + assert reader.metadata.get("/Producer") == "PyPDF2" assert new_text == orig_text