Availability of hashlib.md5
Claude Paroz <[email protected]> Sun, 22 May 2022 11:03:57 +0200
| Newsgroups | gmane.comp.python.reportlab.user |
|---|---|
| Message-ID | <[email protected]> |
Hi, I think we can now always count on hashlib.md5 availability. The joined patch is cleaning that in current code. Regards, Claude -- www.2xlibre.net
0001-hashlib.md5-is-now-always-available.patch
(text/x-patch, 3.1 KB)
From bde59f77cde338663843149cacf91a9fe947e18d Mon Sep 17 00:00:00 2001 From: Claude Paroz <[email protected]> Date: Mon, 27 Dec 2021 18:43:41 +0100 Subject: [PATCH] hashlib.md5 is now always available --- src/reportlab/lib/pdfencrypt.py | 3 ++- src/reportlab/lib/utils.py | 5 ----- src/reportlab/pdfbase/cidfonts.py | 5 +---- tests/test_images.py | 5 +---- tests/test_invariant.py | 3 ++- 5 files changed, 6 insertions(+), 15 deletions(-) diff --git a/src/reportlab/lib/pdfencrypt.py b/src/reportlab/lib/pdfencrypt.py index aefa4899..d02487dd 100644 --- a/src/reportlab/lib/pdfencrypt.py +++ b/src/reportlab/lib/pdfencrypt.py @@ -5,9 +5,10 @@ __version__='3.3.0' """helpers for pdf encryption/decryption""" import sys, os from binascii import hexlify, unhexlify +from hashlib import md5 from io import BytesIO -from reportlab.lib.utils import md5, asBytes, int2Byte, rawBytes, asNative +from reportlab.lib.utils import asBytes, int2Byte, rawBytes, asNative from reportlab.pdfgen.canvas import Canvas from reportlab.pdfbase.pdfdoc import PDFObject from reportlab.platypus.flowables import Flowable diff --git a/src/reportlab/lib/utils.py b/src/reportlab/lib/utils.py index 51995d17..59a7d8b4 100644 --- a/src/reportlab/lib/utils.py +++ b/src/reportlab/lib/utils.py @@ -23,11 +23,6 @@ class __UNSET__: __repr__ = __str__ __UNSET__ = __UNSET__() -try: - from hashlib import md5 -except ImportError: - import md5 - try: import platform isPyPy = platform.python_implementation()=='PyPy' diff --git a/src/reportlab/pdfbase/cidfonts.py b/src/reportlab/pdfbase/cidfonts.py index f3baf72b..f02502ee 100644 --- a/src/reportlab/pdfbase/cidfonts.py +++ b/src/reportlab/pdfbase/cidfonts.py @@ -11,10 +11,7 @@ their own width and how to write themselves into PDF files.""" import os import marshal import time -try: - from hashlib import md5 -except ImportError: - from md5 import md5 +from hashlib import md5 from reportlab.pdfbase import pdfmetrics from reportlab.pdfbase._cidfontdata import allowedTypeFaces, allowedEncodings, CIDFontInfo, \ diff --git a/tests/test_images.py b/tests/test_images.py index a0c8c327..9727e6a6 100644 --- a/tests/test_images.py +++ b/tests/test_images.py @@ -8,11 +8,8 @@ Most of them make use of test\\pythonpowereed.gif.""" from reportlab.lib.testutils import setOutDir,makeSuiteForClasses, printLocation setOutDir(__name__) import os -try: - from hashlib import md5 -except ImportError: - from md5 import md5 import unittest +from hashlib import md5 from reportlab.lib.utils import ImageReader diff --git a/tests/test_invariant.py b/tests/test_invariant.py index f1bf8a6e..37baf2c0 100644 --- a/tests/test_invariant.py +++ b/tests/test_invariant.py @@ -57,7 +57,8 @@ def makeSuite(): if __name__ == "__main__": # add some diagnostics, useful in invariant tests import sys, os - from reportlab.lib.utils import md5, bytestr + from hashlib import md5 + from reportlab.lib.utils import bytestr verbose = ('-v' in sys.argv) unittest.TextTestRunner().run(makeSuite()) if verbose: -- 2.30.2