From 640abe0c12e63c207fcf67592838f112a29f5b43 Mon Sep 17 00:00:00 2001 From: Sirushti Murugesan Date: Thu, 23 Apr 2015 14:55:43 +0530 Subject: [PATCH] Update the rest of the code to satisfy flake8 in a py34 env * Use six.moves.reduce * Update numliteral from 0L to 0 * Use open() instead of file() * Use rich comparison methods instead of cmp() partial blueprint heat-python34-support Change-Id: I9ffd85645563192b5d6124f8dbb71c24245eefc4 --- heat/cloudinit/loguserdata.py | 2 +- heat/common/plugin_loader.py | 2 +- heat/engine/attributes.py | 2 +- heat/engine/cfn/functions.py | 2 +- heat/engine/hot/functions.py | 3 ++- heat/engine/rsrc_defn.py | 2 +- heat/engine/scheduler.py | 22 ++++++++++++++++++++-- 7 files changed, 27 insertions(+), 8 deletions(-) diff --git a/heat/cloudinit/loguserdata.py b/heat/cloudinit/loguserdata.py index bf90af4611..e51c85c5de 100755 --- a/heat/cloudinit/loguserdata.py +++ b/heat/cloudinit/loguserdata.py @@ -100,7 +100,7 @@ if __name__ == '__main__': provision_log = os.path.join(VAR_PATH, 'provision-finished') # touch the file so it is timestamped with when finished - pl = file(provision_log, 'a') + pl = open(provision_log, 'a') try: os.utime(provision_log, None) finally: diff --git a/heat/common/plugin_loader.py b/heat/common/plugin_loader.py index 86b5e94087..cfa0465f3c 100644 --- a/heat/common/plugin_loader.py +++ b/heat/common/plugin_loader.py @@ -76,7 +76,7 @@ def _import_module(importer, module_name, package): # Make this accessible through the parent package for static imports local_name = module_name.partition(package.__name__ + '.')[2] module_components = local_name.split('.') - parent = reduce(getattr, module_components[:-1], package) + parent = six.moves.reduce(getattr, module_components[:-1], package) setattr(parent, module_components[-1], module) return module diff --git a/heat/engine/attributes.py b/heat/engine/attributes.py index 97cbd56208..f35d61ffa5 100644 --- a/heat/engine/attributes.py +++ b/heat/engine/attributes.py @@ -198,6 +198,6 @@ def select_from_attribute(attribute_value, path): return collection[key] try: - return reduce(get_path_component, path, attribute_value) + return six.moves.reduce(get_path_component, path, attribute_value) except (KeyError, IndexError, TypeError): return None diff --git a/heat/engine/cfn/functions.py b/heat/engine/cfn/functions.py index 205f937910..42db1e8a84 100644 --- a/heat/engine/cfn/functions.py +++ b/heat/engine/cfn/functions.py @@ -449,7 +449,7 @@ class Replace(function.Function): return string.replace(placeholder, six.text_type(value)) - return reduce(replace, six.iteritems(mapping), template) + return six.moves.reduce(replace, six.iteritems(mapping), template) class Base64(function.Function): diff --git a/heat/engine/hot/functions.py b/heat/engine/hot/functions.py index e4d7872858..f433e7e048 100644 --- a/heat/engine/hot/functions.py +++ b/heat/engine/hot/functions.py @@ -83,7 +83,8 @@ class GetParam(function.Function): return collection[key] try: - return reduce(get_path_component, path_components, parameter) + return six.moves.reduce(get_path_component, path_components, + parameter) except (KeyError, IndexError, TypeError): return '' diff --git a/heat/engine/rsrc_defn.py b/heat/engine/rsrc_defn.py index 4c787ed9dd..fc323977c7 100644 --- a/heat/engine/rsrc_defn.py +++ b/heat/engine/rsrc_defn.py @@ -412,6 +412,6 @@ def _hash_data(data): if isinstance(data, collections.Mapping): item_hashes = (hash(k) ^ _hash_data(v) for k, v in data.items()) - return reduce(operator.xor, item_hashes, 0L) + return six.moves.reduce(operator.xor, item_hashes, 0) return hash(data) diff --git a/heat/engine/scheduler.py b/heat/engine/scheduler.py index 0a221461a2..ed79448d97 100644 --- a/heat/engine/scheduler.py +++ b/heat/engine/scheduler.py @@ -89,10 +89,28 @@ class Timeout(BaseException): generator.close() return False - def __cmp__(self, other): + def __eq__(self, other): + return not self < other and not other < self + + def __ne__(self, other): + return not self.__eq__(other) + + def __gt__(self, other): + return other < self + + def __ge__(self, other): + return not self < other + + def __le__(self, other): + return not other < self + + def __lt__(self, other): if not isinstance(other, Timeout): return NotImplemented - return cmp(self._endtime, other._endtime) + return self._endtime < other._endtime + + def __cmp__(self, other): + return self < other class TimedCancel(Timeout):