updated scrapy.utils.misc.hash_values to drop usage of deprecated sha module in favor or hashlib, added tests to hash_values function

--HG--
extra : convert_revision : svn%3Ab85faa78-f9eb-468e-a121-7cced6da292c%40378
This commit is contained in:
Pablo Hoffman 2008-11-13 15:50:27 +00:00
parent 01b157d10b
commit 79c9ac388d
2 changed files with 16 additions and 2 deletions

View File

@ -0,0 +1,14 @@
import unittest
from scrapy.utils.misc import hash_values
from scrapy.core.exceptions import UsageError
class UtilsMiscTestCase(unittest.TestCase):
def test_hash_values(self):
self.assertEqual(hash_values('some', 'values', 'to', 'hash'),
'f37f5dc65beaaea35af05e16e26d439fd150c576')
self.assertRaises(UsageError, hash_values, 'some', None, 'value')
if __name__ == "__main__":
unittest.main()

View File

@ -2,7 +2,7 @@
Auxiliary functions which doesn't fit anywhere else
"""
import re
import sha
import hashlib
from twisted.internet import defer
@ -104,7 +104,7 @@ def hash_values(*values):
>>> hash_values('some', 'values', 'to', 'hash')
'f37f5dc65beaaea35af05e16e26d439fd150c576'
"""
hash = sha.new()
hash = hashlib.sha1()
for value in values:
if value is None:
message = "hash_values was passed None at argument index %d. This is a bug in the calling code" \