summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxianming mao <xianming.mao@easystack.cn>2016-12-21 13:58:23 +0800
committerxianming.mao <xianming.mao@easystack.cn>2017-01-10 08:55:30 +0000
commit44507540f6904e2ae5bba8283723de2f6748810b (patch)
tree0baafb5f90a1df03b1fc26bc7b9200d58f36e7ca
parent4eb63b8ef278de2e82e3b4957b95ba6fd9032e4f (diff)
downloadpython-cinderclient-44507540f6904e2ae5bba8283723de2f6748810b.tar.gz
Python3 common patterns
Modify some codes in order to lead them meet the python3 common pattern. Look through the following patterns of Cinder, map() and filter() if a list is needed on Python 3: Replace map(func, data) with [func(item) for item in data] Replace filter(lambda obj: test(obj), data) with [obj for obj in data if test(obj)] Replace exceptions.OSError with OSError and remove "import exceptions" Replace iterator.next() with next(iterator) Replace basestring with six.string_types Replace unicode with six.text_type Replace (str, unicode) with six.string_types Replace "for key in dict.iterkeys()" with "for key in dict" Replace dict.iteritems() with dict.items() Replace dict.itervalues() with dict.values() I found that only "filter(lambda obj: test(obj), data)" and "map(func, data)"need to modify. The other items are not be founded in Cinder. Reference:https://wiki.openstack.org/wiki/Python3#Common_patterns Change-Id: If33ec39eb176c14086132d3099c6ec577f956ded
-rw-r--r--cinderclient/shell.py4
-rw-r--r--cinderclient/tests/unit/v1/fakes.py4
-rw-r--r--cinderclient/tests/unit/v2/fakes.py4
-rw-r--r--cinderclient/tests/unit/v3/fakes.py4
4 files changed, 8 insertions, 8 deletions
diff --git a/cinderclient/shell.py b/cinderclient/shell.py
index 5f56a4c..4ba2f81 100644
--- a/cinderclient/shell.py
+++ b/cinderclient/shell.py
@@ -952,8 +952,8 @@ def main():
if sys.version_info >= (3, 0):
OpenStackCinderShell().main(sys.argv[1:])
else:
- OpenStackCinderShell().main(map(encodeutils.safe_decode,
- sys.argv[1:]))
+ OpenStackCinderShell().main([encodeutils.safe_decode(item)
+ for item in sys.argv[1:]])
except KeyboardInterrupt:
print("... terminating cinder client", file=sys.stderr)
sys.exit(130)
diff --git a/cinderclient/tests/unit/v1/fakes.py b/cinderclient/tests/unit/v1/fakes.py
index 2f7cb64..13f1639 100644
--- a/cinderclient/tests/unit/v1/fakes.py
+++ b/cinderclient/tests/unit/v1/fakes.py
@@ -712,9 +712,9 @@ class FakeHTTPClient(base_client.HTTPClient):
},
]
if host:
- services = filter(lambda i: i['host'] == host, services)
+ services = [i for i in services if i['host'] == host]
if binary:
- services = filter(lambda i: i['binary'] == binary, services)
+ services = [i for i in services if i['binary'] == binary]
return (200, {}, {'services': services})
def put_os_services_enable(self, body, **kw):
diff --git a/cinderclient/tests/unit/v2/fakes.py b/cinderclient/tests/unit/v2/fakes.py
index 4574172..995b11e 100644
--- a/cinderclient/tests/unit/v2/fakes.py
+++ b/cinderclient/tests/unit/v2/fakes.py
@@ -1079,9 +1079,9 @@ class FakeHTTPClient(base_client.HTTPClient):
},
]
if host:
- services = filter(lambda i: i['host'] == host, services)
+ services = [i for i in services if i['host'] == host]
if binary:
- services = filter(lambda i: i['binary'] == binary, services)
+ services = [i for i in services if i['binary'] == binary]
return (200, {}, {'services': services})
def put_os_services_enable(self, body, **kw):
diff --git a/cinderclient/tests/unit/v3/fakes.py b/cinderclient/tests/unit/v3/fakes.py
index 060b697..39b2cf0 100644
--- a/cinderclient/tests/unit/v3/fakes.py
+++ b/cinderclient/tests/unit/v3/fakes.py
@@ -116,9 +116,9 @@ class FakeHTTPClient(fake_v2.FakeHTTPClient):
},
]
if host:
- services = list(filter(lambda i: i['host'] == host, services))
+ services = [i for i in services if i['host'] == host]
if binary:
- services = list(filter(lambda i: i['binary'] == binary, services))
+ services = [i for i in services if i['binary'] == binary]
if not self.api_version.matches('3.7'):
for svc in services:
del svc['cluster']