diff options
author | pjenvey <devnull@localhost> | 2008-09-17 22:18:35 +0000 |
---|---|---|
committer | pjenvey <devnull@localhost> | 2008-09-17 22:18:35 +0000 |
commit | 53e7d3ce846eaf9546b0a413c2921627138ecc45 (patch) | |
tree | 793b0ba4f7bafcbf7444b5eec976bc72bf0a9739 /paste/exceptions | |
parent | 12512c9ad73e4352351f84be7ee0259f023597ef (diff) | |
download | paste-53e7d3ce846eaf9546b0a413c2921627138ecc45.tar.gz |
prefer hashlib over the md5/sha modules which are deprecated in Python 2.6
Diffstat (limited to 'paste/exceptions')
-rw-r--r-- | paste/exceptions/serial_number_generator.py | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/paste/exceptions/serial_number_generator.py b/paste/exceptions/serial_number_generator.py index 7a8ad4a..0289663 100644 --- a/paste/exceptions/serial_number_generator.py +++ b/paste/exceptions/serial_number_generator.py @@ -8,7 +8,10 @@ to create compact representations that are unique for a certain string (or concatenation of strings) """ -import md5 +try: + from hashlib import md5 +except ImportError: + from md5 import md5 good_characters = "23456789abcdefghjkmnpqrtuvwxyz" @@ -49,13 +52,16 @@ def hash_identifier(s, length, pad=True, hasher=md5, prefix='', length. E.g., ``group=4`` will cause a identifier like ``a5f3-hgk3-asdf``. Grouping occurs before the prefix. """ + if not callable(hasher): + # Accept sha/md5 modules as well as callables + hasher = hasher.new if length > 26 and hasher is md5: raise ValueError, ( "md5 cannot create hashes longer than 26 characters in " "length (you gave %s)" % length) if isinstance(s, unicode): s = s.encode('utf-8') - h = hasher.new(str(s)) + h = hasher(str(s)) bin_hash = h.digest() modulo = base ** length number = 0 |