Fix python 2.6 compatibility for moto/swf

This commit is contained in:
Jean-Baptiste Barth 2015-11-03 08:40:33 +01:00
parent 90c8797abd
commit e9732140e5
7 changed files with 31 additions and 31 deletions

View File

@ -14,9 +14,9 @@ class SWFClientError(JSONResponseError):
class SWFUnknownResourceFault(SWFClientError):
def __init__(self, resource_type, resource_name=None):
if resource_name:
message = "Unknown {}: {}".format(resource_type, resource_name)
message = "Unknown {0}: {1}".format(resource_type, resource_name)
else:
message = "Unknown {}".format(resource_type)
message = "Unknown {0}".format(resource_type)
super(SWFUnknownResourceFault, self).__init__(
message,
"com.amazonaws.swf.base.model#UnknownResourceFault")
@ -39,7 +39,7 @@ class SWFDomainDeprecatedFault(SWFClientError):
class SWFSerializationException(JSONResponseError):
def __init__(self, value):
message = "class java.lang.Foo can not be converted to an String "
message += " (not a real SWF exception ; happened on: {})".format(value)
message += " (not a real SWF exception ; happened on: {0})".format(value)
__type = "com.amazonaws.swf.base.model#SerializationException"
super(SWFSerializationException, self).__init__(
400, "Bad Request",
@ -50,14 +50,14 @@ class SWFSerializationException(JSONResponseError):
class SWFTypeAlreadyExistsFault(SWFClientError):
def __init__(self, _type):
super(SWFTypeAlreadyExistsFault, self).__init__(
"{}=[name={}, version={}]".format(_type.__class__.__name__, _type.name, _type.version),
"{0}=[name={1}, version={2}]".format(_type.__class__.__name__, _type.name, _type.version),
"com.amazonaws.swf.base.model#TypeAlreadyExistsFault")
class SWFTypeDeprecatedFault(SWFClientError):
def __init__(self, _type):
super(SWFTypeDeprecatedFault, self).__init__(
"{}=[name={}, version={}]".format(_type.__class__.__name__, _type.name, _type.version),
"{0}=[name={1}, version={2}]".format(_type.__class__.__name__, _type.name, _type.version),
"com.amazonaws.swf.base.model#TypeDeprecatedFault")
@ -107,14 +107,14 @@ class SWFDecisionValidationException(SWFClientError):
)
else:
raise ValueError(
"Unhandled decision constraint type: {}".format(pb["type"])
"Unhandled decision constraint type: {0}".format(pb["type"])
)
# prefix
count = len(problems)
if count < 2:
prefix = "{} validation error detected: "
prefix = "{0} validation error detected: "
else:
prefix = "{} validation errors detected: "
prefix = "{0} validation errors detected: "
super(SWFDecisionValidationException, self).__init__(
prefix.format(count) + "; ".join(messages),
"com.amazon.coral.validate#ValidationException"

View File

@ -117,7 +117,7 @@ class SWFBackend(BaseBackend):
_type = domain.get_type(kind, name, version, ignore_empty=True)
if _type:
raise SWFTypeAlreadyExistsFault(_type)
_class = globals()["{}Type".format(kind.capitalize())]
_class = globals()["{0}Type".format(kind.capitalize())]
_type = _class(name, version, **kwargs)
domain.add_type(_type)
@ -245,7 +245,7 @@ class SWFBackend(BaseBackend):
if wfe.execution_status != "OPEN":
raise SWFUnknownResourceFault(
"execution",
"WorkflowExecution=[workflowId={}, runId={}]".format(
"WorkflowExecution=[workflowId={0}, runId={1}]".format(
wfe.workflow_id, wfe.run_id
)
)
@ -253,7 +253,7 @@ class SWFBackend(BaseBackend):
if decision_task.state != "STARTED":
if decision_task.state == "COMPLETED":
raise SWFUnknownResourceFault(
"decision task, scheduledEventId = {}".format(decision_task.scheduled_event_id)
"decision task, scheduledEventId = {0}".format(decision_task.scheduled_event_id)
)
else:
raise ValueError(
@ -333,7 +333,7 @@ class SWFBackend(BaseBackend):
if wfe.execution_status != "OPEN":
raise SWFUnknownResourceFault(
"execution",
"WorkflowExecution=[workflowId={}, runId={}]".format(
"WorkflowExecution=[workflowId={0}, runId={1}]".format(
wfe.workflow_id, wfe.run_id
)
)
@ -341,7 +341,7 @@ class SWFBackend(BaseBackend):
if activity_task.state != "STARTED":
if activity_task.state == "COMPLETED":
raise SWFUnknownResourceFault(
"activity, scheduledEventId = {}".format(activity_task.scheduled_event_id)
"activity, scheduledEventId = {0}".format(activity_task.scheduled_event_id)
)
else:
raise ValueError(

View File

@ -53,7 +53,7 @@ class Domain(object):
if not ignore_empty:
raise SWFUnknownResourceFault(
"type",
"{}Type=[name={}, version={}]".format(
"{0}Type=[name={1}, version={2}]".format(
kind.capitalize(), name, version
)
)
@ -91,10 +91,10 @@ class Domain(object):
wfe = None
if not wfe and raise_if_none:
if run_id:
args = ["execution", "WorkflowExecution=[workflowId={}, runId={}]".format(
args = ["execution", "WorkflowExecution=[workflowId={0}, runId={1}]".format(
workflow_id, run_id)]
else:
args = ["execution, workflowId = {}".format(workflow_id)]
args = ["execution, workflowId = {0}".format(workflow_id)]
raise SWFUnknownResourceFault(*args)
# at last return workflow execution
return wfe

View File

@ -23,7 +23,7 @@ class GenericType(object):
def __repr__(self):
cls = self.__class__.__name__
attrs = "name: %(name)s, version: %(version)s, status: %(status)s" % self.__dict__
return "{}({})".format(cls, attrs)
return "{0}({1})".format(cls, attrs)
@property
def kind(self):
@ -41,7 +41,7 @@ class GenericType(object):
def to_medium_dict(self):
hsh = {
"{}Type".format(self.kind): self.to_short_dict(),
"{0}Type".format(self.kind): self.to_short_dict(),
"creationDate": 1420066800,
"status": self.status,
}

View File

@ -24,7 +24,7 @@ class HistoryEvent(object):
}
def _attributes_key(self):
key = "{}EventAttributes".format(self.event_type)
key = "{0}EventAttributes".format(self.event_type)
return decapitalize(key)
def event_attributes(self):
@ -154,5 +154,5 @@ class HistoryEvent(object):
return hsh
else:
raise NotImplementedError(
"HistoryEvent does not implement attributes for type '{}'".format(self.event_type)
"HistoryEvent does not implement attributes for type '{0}'".format(self.event_type)
)

View File

@ -83,7 +83,7 @@ class WorkflowExecution(object):
self.child_workflow_executions = []
def __repr__(self):
return "WorkflowExecution(run_id: {})".format(self.run_id)
return "WorkflowExecution(run_id: {0})".format(self.run_id)
def _set_from_kwargs_or_workflow_type(self, kwargs, local_key, workflow_type_key=None):
if workflow_type_key is None:
@ -219,7 +219,7 @@ class WorkflowExecution(object):
if dt.task_token == task_token:
return dt
raise ValueError(
"No decision task with token: {}".format(task_token)
"No decision task with token: {0}".format(task_token)
)
def start_decision_task(self, task_token, identity=None):
@ -260,7 +260,7 @@ class WorkflowExecution(object):
if constraint["required"] and not value.get(key):
problems.append({
"type": "null_value",
"where": "decisions.{}.member.{}.{}".format(
"where": "decisions.{0}.member.{1}.{2}".format(
decision_id, kind, key
)
})
@ -297,7 +297,7 @@ class WorkflowExecution(object):
attrs_to_check = filter(lambda x: x.endswith("DecisionAttributes"), dcs.keys())
if dcs["decisionType"] in self.KNOWN_DECISION_TYPES:
decision_type = dcs["decisionType"]
decision_attr = "{}DecisionAttributes".format(decapitalize(decision_type))
decision_attr = "{0}DecisionAttributes".format(decapitalize(decision_type))
attrs_to_check.append(decision_attr)
for attr in attrs_to_check:
problems += self._check_decision_attributes(attr, dcs.get(attr, {}), decision_number)
@ -306,7 +306,7 @@ class WorkflowExecution(object):
problems.append({
"type": "bad_decision_type",
"value": dcs["decisionType"],
"where": "decisions.{}.member.decisionType".format(decision_number),
"where": "decisions.{0}.member.decisionType".format(decision_number),
"possible_values": ", ".join(self.KNOWN_DECISION_TYPES),
})
@ -322,7 +322,7 @@ class WorkflowExecution(object):
# handle each decision separately, in order
for decision in decisions:
decision_type = decision["decisionType"]
attributes_key = "{}DecisionAttributes".format(decapitalize(decision_type))
attributes_key = "{0}DecisionAttributes".format(decapitalize(decision_type))
attributes = decision.get(attributes_key, {})
if decision_type == "CompleteWorkflowExecution":
self.complete(event_id, attributes.get("result"))
@ -341,7 +341,7 @@ class WorkflowExecution(object):
# TODO: implement Decision type: SignalExternalWorkflowExecution
# TODO: implement Decision type: StartChildWorkflowExecution
# TODO: implement Decision type: StartTimer
raise NotImplementedError("Cannot handle decision: {}".format(decision_type))
raise NotImplementedError("Cannot handle decision: {0}".format(decision_type))
# finally decrement counter if and only if everything went well
self.open_counts["openDecisionTasks"] -= 1
@ -419,7 +419,7 @@ class WorkflowExecution(object):
if not timeouts[_type]:
error_key = default_key.replace("default_task_", "default_")
fail_schedule_activity_task(activity_type,
"{}_UNDEFINED".format(error_key.upper()))
"{0}_UNDEFINED".format(error_key.upper()))
return
# Only add event and increment counters now that nothing went wrong
@ -447,7 +447,7 @@ class WorkflowExecution(object):
if task.task_token == task_token:
return task
raise ValueError(
"No activity task with token: {}".format(task_token)
"No activity task with token: {0}".format(task_token)
)
def start_activity_task(self, task_token, identity=None):

View File

@ -61,7 +61,7 @@ class SWFResponse(BaseResponse):
def _describe_type(self, kind):
domain = self._params["domain"]
_type_args = self._params["{}Type".format(kind)]
_type_args = self._params["{0}Type".format(kind)]
name = _type_args["name"]
version = _type_args["version"]
_type = self.swf_backend.describe_type(kind, domain, name, version)
@ -70,7 +70,7 @@ class SWFResponse(BaseResponse):
def _deprecate_type(self, kind):
domain = self._params["domain"]
_type_args = self._params["{}Type".format(kind)]
_type_args = self._params["{0}Type".format(kind)]
name = _type_args["name"]
version = _type_args["version"]
self.swf_backend.deprecate_type(kind, domain, name, version)