File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2222Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2323"""
2424
25- import md5
26- import sha
25+ try :
26+ import hashlib
27+ except :
28+ import md5
29+ import sha
30+
31+ import sys
2732import struct
2833import urllib
2934
@@ -45,7 +50,10 @@ def hexencode(string):
4550 return string .encode ("hex" )
4651
4752def md5hash (string ):
48- return md5 .new (string ).hexdigest ()
53+ if sys .modules .has_key ('hashlib' ):
54+ return hashlib .md5 (string ).hexdigest ()
55+ else :
56+ return md5 .new (string ).hexdigest ()
4957
5058def orddecode (string ):
5159 packedString = struct .pack ("!" + "I" * len (string ), * string )
@@ -55,7 +63,10 @@ def ordencode(string):
5563 return tuple ([ord (char ) for char in string ])
5664
5765def sha1hash (string ):
58- return sha .new (string ).hexdigest ()
66+ if sys .modules .has_key ('hashlib' ):
67+ return hashlib .sha1 (string ).hexdigest ()
68+ else :
69+ return sha .new (string ).hexdigest ()
5970
6071def urldecode (string ):
6172 result = None
You can’t perform that action at this time.
0 commit comments