2 """User wrapper for md5 builtin object"""
4 __author__ = "Oleg Broytman <phd@phdru.name>"
5 __copyright__ = "Copyright (C) 1997-2012 PhiloSoft Design"
6 __license__ = "GNU GPL"
8 __all__ = ['md5wrapper']
11 if sys.version < '2.5':
14 from hashlib import md5
17 def __init__(self, init=None):
23 def update(self, data):
24 self._md5.update(data)
27 return self._md5.digest()
31 return "%02x"*len(str) % tuple(map(ord, str))
32 # This nice was suggested by Guido
35 if type(f) == type(''): # If f is string - use it as file's name
38 infile = f # else assume it is file or file-like object
42 buf = infile.read(16*1024)
47 if type(f) == type(''): # If f was opened - close it
50 if __name__ == "__main__":
51 print "This must print exactly the string"
52 print "Test: 900150983cd24fb0d6963f7d28e17f72"
53 print "Test:", md5wrapper("abc")