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):
16 if not isinstance(init, bytes):
17 init = init.encode('ascii')
22 def update(self, data):
23 self._md5.update(data)
26 return self._md5.digest()
30 if isinstance(str, bytes):
31 str = str.decode('latin1')
32 return "%02x"*len(str) % tuple(map(ord, str))
33 # This nice was suggested by Guido
36 if type(f) == type(''): # If f is string - use it as file's name
39 infile = f # else assume it is file or file-like object
43 buf = infile.read(16*1024)
48 if type(f) == type(''): # If f was opened - close it
51 if __name__ == "__main__":
52 print("This must print exactly the string")
53 print("Test: 900150983cd24fb0d6963f7d28e17f72")
54 print("Test:", md5wrapper("abc"))