summaryrefslogtreecommitdiffstats
path: root/ipalib/compat.py
diff options
context:
space:
mode:
authorJason Gerard DeRose <jderose@redhat.com>2010-02-12 13:03:14 -0700
committerRob Crittenden <rcritten@redhat.com>2010-02-12 17:20:46 -0500
commita63224f4dced1f81eee1f2fe99dbfd4c8c25a083 (patch)
tree8c052ed96fffb47d652f64380a07399b6fa1edaf /ipalib/compat.py
parent2779da3096450ea08ced146e7455ae4a764dac71 (diff)
downloadfreeipa-a63224f4dced1f81eee1f2fe99dbfd4c8c25a083.tar.gz
freeipa-a63224f4dced1f81eee1f2fe99dbfd4c8c25a083.tar.xz
freeipa-a63224f4dced1f81eee1f2fe99dbfd4c8c25a083.zip
Add sha1, md5 to compat
Diffstat (limited to 'ipalib/compat.py')
-rw-r--r--ipalib/compat.py38
1 files changed, 34 insertions, 4 deletions
diff --git a/ipalib/compat.py b/ipalib/compat.py
index 70f098b16..fcf33fd62 100644
--- a/ipalib/compat.py
+++ b/ipalib/compat.py
@@ -18,11 +18,14 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""
-Abstracts some compatability issues for Python2.4 - Python2.6.
+Abstracts some compatibility issues for Python 2.4 - Python 2.6.
-The ``json`` module was added in Python2.6, which previously was in a seperate
-package and called ``simplejson``. This hack abstracts the difference so you
-can use the ``json`` module generically like this:
+Python 2.6
+==========
+
+The ``json`` module was added in Python 2.6, which previously was in an external
+package and called ``simplejson``. The `compat` module abstracts the difference
+so you can use the ``json`` module generically like this:
>>> from compat import json
>>> json.dumps({'hello': 'world'})
@@ -40,6 +43,28 @@ future-proofing here so you can import ``parse_qs()`` generically like this:
For more information, see *What's New in Python 2.6*:
http://docs.python.org/whatsnew/2.6.html
+
+
+Python 2.5
+==========
+
+The ``hashlib`` module was added in Python2.5, after which use of the ``sha``
+and ``md5`` modules is deprecated. You can generically import a ``sha1`` class
+from the `compat` module like this:
+
+>>> from compat import sha1
+>>> sha1('hello world').hexdigest()
+'2aae6c35c94fcfb415dbe95f408b9ce91ee846ed'
+
+And generically import an ``md5`` class like this:
+
+>>> from compat import md5
+>>> md5('hello world').hexdigest()
+'5eb63bbbe01eeed093cb22bb8f5acdc3'
+
+For more information, see *What's New in Python 2.5*:
+
+ http://python.org/doc/2.5/whatsnew/whatsnew25.html
"""
import sys
@@ -49,3 +74,8 @@ if sys.version_info[:2] >= (2, 6):
else:
import simplejson as json
from cgi import parse_qs
+try:
+ from hashlib import sha1, md5
+except ImportError:
+ from sha import new as sha1
+ from md5 import new as md5