Commit db86e6f7 authored by Paul McCarthy's avatar Paul McCarthy 🚵
Browse files

Python 2/3 issues with memoize and unicode should be sorted

parent 482924ac
......@@ -55,14 +55,14 @@ def memoize(func):
result = cache[key]
log.debug('Retrieved from cache[{}]: {}'.format(key, result))
log.debug(u'Retrieved from cache[{}]: {}'.format(key, result))
except KeyError:
result = func(*a, **kwa)
cache[key] = result
log.debug('Adding to cache[{}]: {}'.format(key, result))
log.debug(u'Adding to cache[{}]: {}'.format(key, result))
return result
return wrapper
......@@ -82,8 +82,15 @@ def memoizeMD5(func):
hashobj = hashlib.md5()
# Convert each arg to a string
# representation, then encode
# it into a sequence of (utf-8
# compatible) bytes , and take
# the hash of those bytes.
for arg in args:
arg = six.u(str(arg)).encode('utf-8')
if not isinstance(arg, six.string_types):
arg = str(arg)
arg = arg.encode('utf-8')
digest = hashobj.hexdigest()
......@@ -94,7 +101,7 @@ def memoizeMD5(func):
result = func(*args, **kwargs)
log.debug('Adding to MD5 cache[{}]: {}'.format(
log.debug(u'Adding to MD5 cache[{}]: {}'.format(
digest, result))
cache[digest] = result
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment