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()
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
return transl_adict[id][val]
-# Encodings, especially cyrillic. Requires Unicode, hence Python 2.0+
-
def recode(s, from_encoding, to_encoding, errors = "strict"):
- return unicode(s, from_encoding, errors).encode(to_encoding, errors)
+ if isinstance(s, bytes):
+ s = s.decode(from_encoding, errors)
+ return s.encode(to_encoding, errors)
def win2koi(s, errors = "strict"):