2 """User wrapper for md5 builtin object"""
4 from __future__ import print_function
6 if sys.version < '2.5':
9 from hashlib import md5
11 __all__ = ['md5wrapper']
14 def __init__(self, init=None):
20 def update(self, data):
21 self._md5.update(data)
24 return self._md5.digest()
28 return "%02x"*len(str) % tuple(map(ord, str))
29 # This nice was suggested by Guido
32 if type(f) == type(''): # If f is string - use it as file's name
35 infile = f # else assume it is file or file-like object
39 buf = infile.read(16*1024)
44 if type(f) == type(''): # If f was opened - close it
47 if __name__ == "__main__":
48 print("This must print exactly the string")
49 print("Test: 900150983cd24fb0d6963f7d28e17f72")
50 print("Test:", md5wrapper("abc"))