diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2013-07-17 11:28:44 -0400 |
---|---|---|
committer | Jason R. Coombs <jaraco@jaraco.com> | 2013-07-17 11:28:44 -0400 |
commit | 3e72e7f7eacca7db638f7230f93cf696d49c77bf (patch) | |
tree | 5e696d38763d9ec86ec7ec583ee974ea886029e1 /setuptools | |
parent | d00b66d5f530da930fdd89cdfdf0ff954f88a141 (diff) | |
download | external_python_setuptools-3e72e7f7eacca7db638f7230f93cf696d49c77bf.tar.gz external_python_setuptools-3e72e7f7eacca7db638f7230f93cf696d49c77bf.tar.bz2 external_python_setuptools-3e72e7f7eacca7db638f7230f93cf696d49c77bf.zip |
Add compatibility for Python 2.4 when querying the hash name. Fixes #440.9.6
Diffstat (limited to 'setuptools')
-rwxr-xr-x | setuptools/package_index.py | 17 | ||||
-rw-r--r-- | setuptools/tests/test_packageindex.py | 16 |
2 files changed, 31 insertions, 2 deletions
diff --git a/setuptools/package_index.py b/setuptools/package_index.py index 70aabd1b..47f00c00 100755 --- a/setuptools/package_index.py +++ b/setuptools/package_index.py @@ -242,8 +242,23 @@ class HashChecker(ContentChecker): def is_valid(self): return self.hash.hexdigest() == self.expected + def _get_hash_name(self): + """ + Python 2.4 implementation of MD5 doesn't supply a .name attribute + so provide that name. + + When Python 2.4 is no longer required, replace invocations of this + method with simply 'self.hash.name'. + """ + try: + return self.hash.name + except AttributeError: + if 'md5' in str(type(self.hash)): + return 'md5' + raise + def report(self, reporter, template): - msg = template % self.hash.name + msg = template % self._get_hash_name() return reporter(msg) diff --git a/setuptools/tests/test_packageindex.py b/setuptools/tests/test_packageindex.py index 4f2d382c..3791914a 100644 --- a/setuptools/tests/test_packageindex.py +++ b/setuptools/tests/test_packageindex.py @@ -147,7 +147,6 @@ class TestContentCheckers(unittest.TestCase): def test_md5(self): checker = setuptools.package_index.HashChecker.from_url( 'http://foo/bar#md5=f12895fdffbd45007040d2e44df98478') - self.assertEqual(checker.hash.name, 'md5') checker.feed('You should probably not be using MD5'.encode('ascii')) self.assertEqual(checker.hash.hexdigest(), 'f12895fdffbd45007040d2e44df98478') @@ -166,3 +165,18 @@ class TestContentCheckers(unittest.TestCase): 'http://foo/bar#md5=') checker.feed('anything'.encode('ascii')) self.assertTrue(checker.is_valid()) + + def test_get_hash_name_md5(self): + checker = setuptools.package_index.HashChecker.from_url( + 'http://foo/bar#md5=f12895fdffbd45007040d2e44df98478') + if sys.version_info >= (2,5): + self.assertEqual(checker.hash.name, 'md5') + else: + # Python 2.4 compatability + self.assertEqual(checker._get_hash_name(), 'md5') + + def test_report(self): + checker = setuptools.package_index.HashChecker.from_url( + 'http://foo/bar#md5=f12895fdffbd45007040d2e44df98478') + rep = checker.report(lambda x: x, 'My message about %s') + self.assertEqual(rep, 'My message about md5') |