[Git][reproducible-builds/diffoscope][master] Support both PyPDF 1.x and 2.x.

Chris Lamb (@lamby) gitlab at salsa.debian.org
Thu Jun 2 11:54:32 UTC 2022



Chris Lamb pushed to branch master at Reproducible Builds / diffoscope


Commits:
3adcd3bd by Chris Lamb at 2022-06-02T12:53:59+01:00
Support both PyPDF 1.x and 2.x.

- - - - -


1 changed file:

- diffoscope/comparators/pdf.py


Changes:

=====================================
diffoscope/comparators/pdf.py
=====================================
@@ -27,6 +27,14 @@ from .utils.command import Command
 
 try:
     import PyPDF2
+
+    try:
+        # PyPDF 2.x
+        from PyPDF2.errors import PdfReadError
+    except ImportError:
+        # PyPDF 1.x
+        from PyPDF2.utils import PdfReadError
+
 except ImportError:  # noqa
     python_module_missing("PyPDF2")
     PyPDF2 = None
@@ -92,7 +100,7 @@ class PdfFile(File):
         try:
             pdf = PyPDF2.PdfFileReader(file.path)
             document_info = pdf.getDocumentInfo()
-        except PyPDF2.utils.PdfReadError as e:
+        except PdfReadError as e:
             return f"(Could not extract metadata: {e})"
 
         if document_info is None:
@@ -108,7 +116,7 @@ class PdfFile(File):
     def dump_pypdf2_annotations(file):
         try:
             pdf = PyPDF2.PdfFileReader(file.path)
-        except PyPDF2.utils.PdfReadError as e:
+        except PdfReadError as e:
             return f"(Could not open file: {e})"
 
         xs = []



View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/commit/3adcd3bd3f670ee58c248ca2d17a93e3e40f03d3

-- 
View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/commit/3adcd3bd3f670ee58c248ca2d17a93e3e40f03d3
You're receiving this email because of your account on salsa.debian.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.reproducible-builds.org/pipermail/rb-commits/attachments/20220602/5bae395b/attachment.htm>


More information about the rb-commits mailing list