From 8c5e55f952d643a4e5e6908db27d2a30622b8afc Mon Sep 17 00:00:00 2001 From: Chang Bo Guo Date: Tue, 26 Nov 2013 06:49:03 -0800 Subject: [PATCH] Unify different names between Python2/3 with six.moves Some modules use different names in Python2 and Python3. Use six.moves to make them work well in Python2 and Python3. This is changes mapping: six.moves Python 2 Python 3 builtins __builtin__ builtins filter itertools.ifilter() filter() reduce reduce() functools.reduce() reload_module reload() imp.reload() Implements: blueprint make-python3-compatible Change-Id: I97971f2ab40385bfc2c73ae7e8a7620c4d64a03c --- openstack/common/log.py | 2 +- tests/unit/test_local.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/openstack/common/log.py b/openstack/common/log.py index f9f226b8..5a4c310d 100644 --- a/openstack/common/log.py +++ b/openstack/common/log.py @@ -349,7 +349,7 @@ class JSONFormatter(logging.Formatter): def formatException(self, ei, strip_newlines=True): lines = traceback.format_exception(*ei) if strip_newlines: - lines = [itertools.ifilter( + lines = [moves.filter( lambda x: x, line.rstrip().splitlines()) for line in lines] lines = list(itertools.chain(*lines)) diff --git a/tests/unit/test_local.py b/tests/unit/test_local.py index 9310a51f..b5997798 100644 --- a/tests/unit/test_local.py +++ b/tests/unit/test_local.py @@ -15,6 +15,8 @@ import threading +from six import moves + from openstack.common import local from openstack.common import test @@ -36,7 +38,7 @@ class LocalStoreTestCase(test.BaseTestCase): # testing in (eventlet vs normal python threading) so # we test the correct type of local store for the current # threading model - reload(local) + moves.reload_module(local) def test_thread_unique_storage(self): """Make sure local store holds thread specific values."""