X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=m_lib%2Fmd5wrapper.py;h=14013027f687356bf692cecee605bfdda9a0567d;hb=HEAD;hp=0c1a5f1e2c03ed8e991dfd642d8edf8fac302a8e;hpb=d7c459a9f979c4978cf07ff11056512a852fd61d;p=m_lib.git diff --git a/m_lib/md5wrapper.py b/m_lib/md5wrapper.py index 0c1a5f1..1401302 100755 --- a/m_lib/md5wrapper.py +++ b/m_lib/md5wrapper.py @@ -1,21 +1,20 @@ #! /usr/bin/env python """User wrapper for md5 builtin object""" -__author__ = "Oleg Broytman " -__copyright__ = "Copyright (C) 1997-2012 PhiloSoft Design" -__license__ = "GNU GPL" - -__all__ = ['md5wrapper'] - +from __future__ import print_function import sys if sys.version < '2.5': from md5 import md5 else: from hashlib import md5 +__all__ = ['md5wrapper'] + class md5wrapper: def __init__(self, init=None): if init: + if not isinstance(init, bytes): + init = init.encode('ascii') self._md5 = md5(init) else: self._md5 = md5() @@ -28,6 +27,8 @@ class md5wrapper: def __repr__(self): str = self.digest() + if isinstance(str, bytes): + str = str.decode('latin1') return "%02x"*len(str) % tuple(map(ord, str)) # This nice was suggested by Guido @@ -48,6 +49,6 @@ class md5wrapper: infile.close() if __name__ == "__main__": - print "This must print exactly the string" - print "Test: 900150983cd24fb0d6963f7d28e17f72" - print "Test:", md5wrapper("abc") + print("This must print exactly the string") + print("Test: 900150983cd24fb0d6963f7d28e17f72") + print("Test:", md5wrapper("abc"))