commit afe449e127 Author: John Kristensen Date: Fri May 9 17:32:44 2014 +1000 Remove roundup.anypy.hashlib_ The hashlib_ module was being used to provide backwards compatibility for python v2.4. Roundup has dropped support for python v2.4 so we can get rid of it. diff --git a/2to3-done.txt b/2to3-done.txt index 9b31da1b7f..6472568c2f 100644 --- a/2to3-done.txt +++ b/2to3-done.txt @@ -90,7 +90,6 @@ TODO ./test/session_common.py ./test/test_actions.py ./test/test_anydbm.py -./test/test_anypy_hashlib.py ./test/test_cgi.py ./test/test_dates.py ./test/test_hyperdbvals.py @@ -148,7 +147,6 @@ NOTHING DONE ./roundup/__init__.py ./roundup/actions.py ./roundup/anypy/__init__.py -./roundup/anypy/hashlib_.py ./roundup/anypy/sets_.py ./roundup/backends/blobfiles.py ./roundup/backends/indexer_xapian.py diff --git a/roundup/anypy/README.txt b/roundup/anypy/README.txt index 7b0fe7281d..478f693cbc 100644 --- a/roundup/anypy/README.txt +++ b/roundup/anypy/README.txt @@ -36,22 +36,4 @@ To avoid unnecessary imports, you can:: except NameError: from roundup.anypy.sets_ import set -hashlib_: md5/sha/hashlib compatibility -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -The md5 and sha modules are deprecated since Python 2.6; the hashlib -module, introduced with Python 2.5, is recommended instead. - -Change all:: - import md5 - md5.md5(), md5.new() - import sha - sha.sha(), sha.new() - -to:: - from roundup.anypy.hashlib_ import md5 - md5() - from roundup.anypy.hashlib_ import sha1 - sha1() - # vim: si diff --git a/roundup/anypy/__init__.py b/roundup/anypy/__init__.py index 21eee1e1a2..dfdde4396d 100644 --- a/roundup/anypy/__init__.py +++ b/roundup/anypy/__init__.py @@ -3,5 +3,5 @@ roundup.anypy - compatibility layer for any Python 2.3+ """ VERSION = '.'.join(map(str, (0, - 1, # hashlib_, sets_ + 2, # hashlib_ ))) diff --git a/roundup/anypy/hashlib_.py b/roundup/anypy/hashlib_.py deleted file mode 100644 index 779176f4fc..0000000000 --- a/roundup/anypy/hashlib_.py +++ /dev/null @@ -1,13 +0,0 @@ -""" -anypy.hashlib_: encapsulation of hashlib/md5/sha1/sha -""" - -try: - from hashlib import md5, sha1 # new in Python 2.5 - shamodule = sha1 -except ImportError: - from md5 import md5 # deprecated in Python 2.6 - from sha import sha as sha1 # deprecated in Python 2.6 - import sha as shamodule - -# vim: ts=8 sts=4 sw=4 si diff --git a/roundup/install_util.py b/roundup/install_util.py index 59288f44e3..a1f9737c08 100644 --- a/roundup/install_util.py +++ b/roundup/install_util.py @@ -21,7 +21,7 @@ __docformat__ = 'restructuredtext' import os, shutil -from roundup.anypy.hashlib_ import sha1 +from hashlib import sha1 sgml_file_types = [".xml", ".ent", ".html"] hash_file_types = [".py", ".sh", ".conf", ".cgi"] diff --git a/roundup/password.py b/roundup/password.py index d8804b2a53..e3f07fe400 100644 --- a/roundup/password.py +++ b/roundup/password.py @@ -21,7 +21,8 @@ __docformat__ = 'restructuredtext' import re, string, random from base64 import b64encode, b64decode -from roundup.anypy.hashlib_ import md5, sha1, shamodule +from hashlib import md5, sha1 + try: import crypt except ImportError: @@ -65,7 +66,7 @@ except ImportError: def _pbkdf2(password, salt, rounds, keylen): digest_size = 20 # sha1 generates 20-byte blocks total_blocks = int((keylen+digest_size-1)/digest_size) - hmac_template = HMAC(password, None, shamodule) + hmac_template = HMAC(password, None, sha1) out = _bempty for i in xrange(1, total_blocks+1): hmac = hmac_template.copy() diff --git a/test/test_anypy_hashlib.py b/test/test_anypy_hashlib.py deleted file mode 100644 index c86775608d..0000000000 --- a/test/test_anypy_hashlib.py +++ /dev/null @@ -1,138 +0,0 @@ -#! /usr/bin/env python -import unittest -import warnings - -import roundup.anypy.hashlib_ - -class UntestableWarning(Warning): - pass - -# suppress deprecation warnings; -> warnings.filters[0]: -warnings.simplefilter(action='ignore', - category=DeprecationWarning, - append=0) - -try: - import sha -except: - warnings.warn('sha module functions', UntestableWarning) - sha = None - -try: - import md5 -except: - warnings.warn('md5 module functions', UntestableWarning) - md5 = None - -try: - import hashlib -except: - warnings.warn('hashlib module functions', UntestableWarning) - hashlib = None - -# preserve other warning filters set elsewhere: -del warnings.filters[0] - -if not ((sha or md5) and hashlib): - warnings.warn('anypy.hashlib_ continuity', UntestableWarning) - -class TestCase_anypy_hashlib(unittest.TestCase): - """test the hashlib compatibility layer""" - - data_for_test = ( - ('', - 'da39a3ee5e6b4b0d3255bfef95601890afd80709', - 'd41d8cd98f00b204e9800998ecf8427e'), - ('Strange women lying in ponds distributing swords' - ' is no basis for a system of government.', - 'da9b2b00466b00411038c057681fe67349f92d7d', - 'b71c5178d316ec446c25386f4857d4f9'), - ('Ottos Mops hopst fort', - 'fdf7e6c54cf07108c86edd8d47c90450671c2c81', - 'a3dce74bee59ee92f1038263e5252500'), - ('Dieser Satz kein Verb', - '3030aded8a079b92043a39dc044a35443959dcdd', - '2f20c69d514228011fb0d32e14dd5d80'), - ) - - # the following two are always excecuted: - def test_sha1_expected_anypy(self): - """...anypy.hashlib_.sha1().hexdigest() yields expected results""" - for src, SHA, MD5 in self.data_for_test: - self.assertEqual(roundup.anypy.hashlib_.sha1(src).hexdigest(), SHA) - - def test_md5_expected_anypy(self): - """...anypy.hashlib_.md5().hexdigest() yields expected results""" - for src, SHA, MD5 in self.data_for_test: - self.assertEqual(roundup.anypy.hashlib_.md5(src).hexdigest(), MD5) - - # execution depending on availability of modules: - if md5 and hashlib: - def test_md5_continuity(self): - """md5.md5().digest() == hashlib.md5().digest()""" - if md5.md5 is hashlib.md5: - return - else: - for s, i1, i2 in self.data_for_test: - self.assertEqual(md5.md5(s).digest(), - hashlib.md5().digest()) - - if md5: - def test_md5_expected(self): - """md5.md5().hexdigest() yields expected results""" - for src, SHA, MD5 in self.data_for_test: - self.assertEqual(md5.md5(src).hexdigest(), MD5) - - def test_md5_new_expected(self): - """md5.new is md5.md5, or at least yields expected results""" - if md5.new is md5.md5: - return - else: - for src, SHA, MD5 in self.data_for_test: - self.assertEqual(md5.new(src).hexdigest(), MD5) - - if sha and hashlib: - def test_sha1_continuity(self): - """sha.sha().digest() == hashlib.sha1().digest()""" - if sha.sha is hashlib.sha1: - return - else: - for s in self.data_for_test: - self.assertEqual(sha.sha(s).digest(), - hashlib.sha1().digest()) - - if sha: - def test_sha_expected(self): - """sha.sha().hexdigest() yields expected results""" - for src, SHA, MD5 in self.data_for_test: - self.assertEqual(sha.sha(src).hexdigest(), SHA) - - def test_sha_new_expected(self): - """sha.new is sha.sha, or at least yields expected results""" - if sha.new is sha.sha: - return - else: - for src, SHA, MD5 in self.data_for_test: - self.assertEqual(sha.new(src).hexdigest(), SHA) - - if hashlib: - def test_sha1_expected_hashlib(self): - """hashlib.sha1().hexdigest() yields expected results""" - for src, SHA, MD5 in self.data_for_test: - self.assertEqual(hashlib.sha1(src).hexdigest(), SHA) - - def test_md5_expected_hashlib(self): - """hashlib.md5().hexdigest() yields expected results""" - for src, SHA, MD5 in self.data_for_test: - self.assertEqual(hashlib.md5(src).hexdigest(), MD5) - -def test_suite(): - suite = unittest.TestSuite() - suite.addTest(unittest.makeSuite(TestCase_anypy_hashlib)) - return suite - -if __name__ == '__main__': - runner = unittest.TextTestRunner() - unittest.main(testRunner=runner) - -# vim: ts=8 et sts=4 sw=4 si diff --git a/test/test_hyperdbvals.py b/test/test_hyperdbvals.py index 5a1f84fdec..8e6151346f 100644 --- a/test/test_hyperdbvals.py +++ b/test/test_hyperdbvals.py @@ -9,7 +9,7 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. import unittest, os, shutil, errno, sys, difflib, cgi, re -from roundup.anypy.hashlib_ import sha1 +from hashlib import sha1 from roundup import init, instance, password, hyperdb, date