Fix python 3.x compatibility regarding iterations on a dict

Error on travis-ci was:

    AttributeError: 'dict' object has no attribute 'iteritems'

And actually it's been removed in python 3.x in favor of dict.items()
This commit is contained in:
Jean-Baptiste Barth 2015-11-03 09:17:56 +01:00
parent f4feec4727
commit 2cd3d5fb45
7 changed files with 14 additions and 14 deletions

View File

@ -111,7 +111,7 @@ class SWFBackend(BaseBackend):
self._check_string(domain_name) self._check_string(domain_name)
self._check_string(name) self._check_string(name)
self._check_string(version) self._check_string(version)
for _, value in kwargs.iteritems(): for _, value in kwargs.items():
self._check_none_or_string(value) self._check_none_or_string(value)
domain = self._get_domain(domain_name) domain = self._get_domain(domain_name)
_type = domain.get_type(kind, name, version, ignore_empty=True) _type = domain.get_type(kind, name, version, ignore_empty=True)
@ -146,7 +146,7 @@ class SWFBackend(BaseBackend):
self._check_string(workflow_name) self._check_string(workflow_name)
self._check_string(workflow_version) self._check_string(workflow_version)
self._check_none_or_list_of_strings(tag_list) self._check_none_or_list_of_strings(tag_list)
for _, value in kwargs.iteritems(): for _, value in kwargs.items():
self._check_none_or_string(value) self._check_none_or_string(value)
domain = self._get_domain(domain_name) domain = self._get_domain(domain_name)
@ -190,7 +190,7 @@ class SWFBackend(BaseBackend):
# #
# TODO: handle long polling (case 2) for decision tasks # TODO: handle long polling (case 2) for decision tasks
candidates = [] candidates = []
for _task_list, tasks in domain.decision_task_lists.iteritems(): for _task_list, tasks in domain.decision_task_lists.items():
if _task_list == task_list: if _task_list == task_list:
candidates += filter(lambda t: t.state == "SCHEDULED", tasks) candidates += filter(lambda t: t.state == "SCHEDULED", tasks)
if any(candidates): if any(candidates):
@ -290,7 +290,7 @@ class SWFBackend(BaseBackend):
# #
# TODO: handle long polling (case 2) for activity tasks # TODO: handle long polling (case 2) for activity tasks
candidates = [] candidates = []
for _task_list, tasks in domain.activity_task_lists.iteritems(): for _task_list, tasks in domain.activity_task_lists.items():
if _task_list == task_list: if _task_list == task_list:
candidates += filter(lambda t: t.state == "SCHEDULED", tasks) candidates += filter(lambda t: t.state == "SCHEDULED", tasks)
if any(candidates): if any(candidates):
@ -309,7 +309,7 @@ class SWFBackend(BaseBackend):
self._process_timeouts() self._process_timeouts()
domain = self._get_domain(domain_name) domain = self._get_domain(domain_name)
count = 0 count = 0
for _task_list, tasks in domain.activity_task_lists.iteritems(): for _task_list, tasks in domain.activity_task_lists.items():
if _task_list == task_list: if _task_list == task_list:
pending = [t for t in tasks if t.state in ["SCHEDULED", "STARTED"]] pending = [t for t in tasks if t.state in ["SCHEDULED", "STARTED"]]
count += len(pending) count += len(pending)

View File

@ -63,8 +63,8 @@ class Domain(object):
def find_types(self, kind, status): def find_types(self, kind, status):
_all = [] _all = []
for _, family in self.types[kind].iteritems(): for _, family in self.types[kind].items():
for _, _type in family.iteritems(): for _, _type in family.items():
if _type.status == status: if _type.status == status:
_all.append(_type) _all.append(_type)
return _all return _all
@ -107,7 +107,7 @@ class Domain(object):
@property @property
def activity_tasks(self): def activity_tasks(self):
_all = [] _all = []
for _, tasks in self.activity_task_lists.iteritems(): for _, tasks in self.activity_task_lists.items():
_all += tasks _all += tasks
return _all return _all
@ -119,6 +119,6 @@ class Domain(object):
@property @property
def decision_tasks(self): def decision_tasks(self):
_all = [] _all = []
for _, tasks in self.decision_task_lists.iteritems(): for _, tasks in self.decision_task_lists.items():
_all += tasks _all += tasks
return _all return _all

View File

@ -10,7 +10,7 @@ class GenericType(object):
self.status = "REGISTERED" self.status = "REGISTERED"
if "description" in kwargs: if "description" in kwargs:
self.description = kwargs.pop("description") self.description = kwargs.pop("description")
for key, value in kwargs.iteritems(): for key, value in kwargs.items():
self.__setattr__(key, value) self.__setattr__(key, value)
# default values set to none # default values set to none
for key in self._configuration_keys: for key in self._configuration_keys:

View File

@ -10,7 +10,7 @@ class HistoryEvent(object):
self.event_id = event_id self.event_id = event_id
self.event_type = event_type self.event_type = event_type
self.event_timestamp = now_timestamp() self.event_timestamp = now_timestamp()
for key, value in kwargs.iteritems(): for key, value in kwargs.items():
self.__setattr__(key, value) self.__setattr__(key, value)
# break soon if attributes are not valid # break soon if attributes are not valid
self.event_attributes() self.event_attributes()

View File

@ -256,7 +256,7 @@ class WorkflowExecution(object):
def _check_decision_attributes(self, kind, value, decision_id): def _check_decision_attributes(self, kind, value, decision_id):
problems = [] problems = []
constraints = DECISIONS_FIELDS.get(kind, {}) constraints = DECISIONS_FIELDS.get(kind, {})
for key, constraint in constraints.iteritems(): for key, constraint in constraints.items():
if constraint["required"] and not value.get(key): if constraint["required"] and not value.get(key):
problems.append({ problems.append({
"type": "null_value", "type": "null_value",

View File

@ -13,7 +13,7 @@ def test_decapitalize():
"FooBar": "fooBar", "FooBar": "fooBar",
"FOO BAR": "fOO BAR", "FOO BAR": "fOO BAR",
} }
for before, after in cases.iteritems(): for before, after in cases.items():
decapitalize(before).should.equal(after) decapitalize(before).should.equal(after)
@freeze_time("2015-01-01 12:00:00") @freeze_time("2015-01-01 12:00:00")

View File

@ -29,7 +29,7 @@ SCHEDULE_ACTIVITY_TASK_DECISION = {
"taskList": { "name": "activity-task-list" }, "taskList": { "name": "activity-task-list" },
} }
} }
for key, value in ACTIVITY_TASK_TIMEOUTS.iteritems(): for key, value in ACTIVITY_TASK_TIMEOUTS.items():
SCHEDULE_ACTIVITY_TASK_DECISION["scheduleActivityTaskDecisionAttributes"][key] = value SCHEDULE_ACTIVITY_TASK_DECISION["scheduleActivityTaskDecisionAttributes"][key] = value
# A test Domain # A test Domain