Port keystonemiddleware to Python 3

On Python 3, memcache returns data as Unicode, but the hmac module
expects bytes. Encode data to UTF-8.

Fix also DisableModuleFixture.clear_module() on Python 3. dict.keys() is
now an iterator on Python 3: create a list because sys.modules is
modified in the loop body.

Closes-Bug: #1449423
Change-Id: Id4805c01b0127a3a86235a7d1a4bb3863b51a6b6
This commit is contained in:
Victor Stinner 2015-04-27 11:53:21 +02:00
parent 1e19e6e64a
commit 83f5d3ab5d
2 changed files with 3 additions and 1 deletions

View File

@ -268,6 +268,8 @@ class TokenCache(object):
if serialized is None:
return None
if isinstance(serialized, six.text_type):
serialized = serialized.encode('utf8')
data = self._deserialize(serialized, context)
# Note that _INVALID_INDICATOR and (data, expires) are the only

View File

@ -108,7 +108,7 @@ class DisableModuleFixture(fixtures.Fixture):
def clear_module(self):
cleared_modules = {}
for fullname in sys.modules.keys():
for fullname in list(sys.modules.keys()):
if (fullname == self.module or
fullname.startswith(self.module + '.')):
cleared_modules[fullname] = sys.modules.pop(fullname)