From b2aa6f40559da92085e77a247b8756d860171a12 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 3 Aug 2013 11:39:39 +0200 Subject: Issue 18532: Added tests and documentation to formally specify the .name attribute on hashlib objects. --- Doc/library/hashlib.rst | 12 ++++++++++++ Lib/test/test_hashlib.py | 5 +++++ 2 files changed, 17 insertions(+) diff --git a/Doc/library/hashlib.rst b/Doc/library/hashlib.rst index 6cb76c1..db41db4 100644 --- a/Doc/library/hashlib.rst +++ b/Doc/library/hashlib.rst @@ -124,6 +124,18 @@ returned by the constructors: The internal block size of the hash algorithm in bytes. +A hash object has the following attributes: + +.. attribute:: hash.name + + The canonical name of this hash, always lowercase and always suitable as a + parameter to :func:`new` to create another hash of this type. + + .. versionchanged:: 3.4 + The name attribute has been present in CPython since its inception, but + until Python 3.4 was not formally specified, so may not exist on some + platforms. + A hash object has the following methods: diff --git a/Lib/test/test_hashlib.py b/Lib/test/test_hashlib.py index 2601209..e944bde 100644 --- a/Lib/test/test_hashlib.py +++ b/Lib/test/test_hashlib.py @@ -154,6 +154,11 @@ class HashLibTestCase(unittest.TestCase): assert isinstance(h.digest(), bytes), name self.assertEqual(hexstr(h.digest()), h.hexdigest()) + def test_name_attribute(self): + for cons in self.hash_constructors: + h = cons() + assert isinstance(h.name, str), "No name attribute" + assert h.name in self.supported_hash_names def test_large_update(self): aas = b'a' * 128 -- cgit v0.12