app/django/utils/hashcompat.py
author Pawel Solyga <Pawel.Solyga@gmail.com>
Mon, 01 Jun 2009 22:23:46 +0200
changeset 2376 feec28b50f1b
parent 323 ff1a9aa48cfd
permissions -rw-r--r--
Extend taggable-mixin to support different Tag models. Usage is pretty simple. Tag model is default in Taggable constructor but you can call it with different model like GHOPTaskType that inherits from Tag model. Both Taggable and Tag models have been updated and they don't use hardcoded Tag model anymore and instead use cls of class methods or self.__class__. In case of Taggable it's self.__tag_model.

"""
The md5 and sha modules are deprecated since Python 2.5, replaced by the
hashlib module containing both hash algorithms. Here, we provide a common
interface to the md5 and sha constructors, preferring the hashlib module when
available.
"""

try:
    import hashlib
    md5_constructor = hashlib.md5
    sha_constructor = hashlib.sha1
except ImportError:
    import md5
    md5_constructor = md5.new
    import sha
    sha_constructor = sha.new