(original) (raw)

changeset: 85038:238c37e4c395 parent: 85036:f4f81ebc3de9 user: Jason R. Coombs jaraco@jaraco.com date: Sat Aug 03 11:39:39 2013 +0200 files: Doc/library/hashlib.rst Lib/test/test_hashlib.py description: Issue 18532: Added tests and documentation to formally specify the .name attribute on hashlib objects. diff -r f4f81ebc3de9 -r 238c37e4c395 Doc/library/hashlib.rst --- a/Doc/library/hashlib.rst Sun Aug 04 15:50:08 2013 -0400 +++ b/Doc/library/hashlib.rst Sat Aug 03 11:39:39 2013 +0200 @@ -124,6 +124,18 @@ 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 -r f4f81ebc3de9 -r 238c37e4c395 Lib/test/test_hashlib.py --- a/Lib/test/test_hashlib.py Sun Aug 04 15:50:08 2013 -0400 +++ b/Lib/test/test_hashlib.py Sat Aug 03 11:39:39 2013 +0200 @@ -154,6 +154,11 @@ 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 /jaraco@jaraco.com