Commits

John Mulligan  committed 7986242

add compat module to vanity
module for getting best md5/sha hash class without python warnings

  • Participants
  • Parent commits 0502995

Comments (0)

Files changed (2)

File vanity/compat/__init__.py

Empty file added.

File vanity/compat/hashes.py

+"""automatically import md5 and sha modules
+from the best possible source depending on the current python version
+"""
+
+__all__ = [
+    'md5', 'sha', 'sha1',
+    ]
+
+try:
+    import hashlib
+    HAS_HASHLIB = 1
+except ImportError:
+    HAS_HASHLIB = 0
+
+if not HAS_HASHLIB:
+    from md5 import md5
+    from sha import sha
+    sha1 = sha
+else:
+    md5 = hashlib.md5
+    sha = sha1 = hashlib.sha1
+