Fix python 2.6 compatibility for moto/swf
This commit is contained in:
parent
90c8797abd
commit
e9732140e5
@ -14,9 +14,9 @@ class SWFClientError(JSONResponseError):
|
|||||||
class SWFUnknownResourceFault(SWFClientError):
|
class SWFUnknownResourceFault(SWFClientError):
|
||||||
def __init__(self, resource_type, resource_name=None):
|
def __init__(self, resource_type, resource_name=None):
|
||||||
if resource_name:
|
if resource_name:
|
||||||
message = "Unknown {}: {}".format(resource_type, resource_name)
|
message = "Unknown {0}: {1}".format(resource_type, resource_name)
|
||||||
else:
|
else:
|
||||||
message = "Unknown {}".format(resource_type)
|
message = "Unknown {0}".format(resource_type)
|
||||||
super(SWFUnknownResourceFault, self).__init__(
|
super(SWFUnknownResourceFault, self).__init__(
|
||||||
message,
|
message,
|
||||||
"com.amazonaws.swf.base.model#UnknownResourceFault")
|
"com.amazonaws.swf.base.model#UnknownResourceFault")
|
||||||
@ -39,7 +39,7 @@ class SWFDomainDeprecatedFault(SWFClientError):
|
|||||||
class SWFSerializationException(JSONResponseError):
|
class SWFSerializationException(JSONResponseError):
|
||||||
def __init__(self, value):
|
def __init__(self, value):
|
||||||
message = "class java.lang.Foo can not be converted to an String "
|
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"
|
__type = "com.amazonaws.swf.base.model#SerializationException"
|
||||||
super(SWFSerializationException, self).__init__(
|
super(SWFSerializationException, self).__init__(
|
||||||
400, "Bad Request",
|
400, "Bad Request",
|
||||||
@ -50,14 +50,14 @@ class SWFSerializationException(JSONResponseError):
|
|||||||
class SWFTypeAlreadyExistsFault(SWFClientError):
|
class SWFTypeAlreadyExistsFault(SWFClientError):
|
||||||
def __init__(self, _type):
|
def __init__(self, _type):
|
||||||
super(SWFTypeAlreadyExistsFault, self).__init__(
|
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")
|
"com.amazonaws.swf.base.model#TypeAlreadyExistsFault")
|
||||||
|
|
||||||
|
|
||||||
class SWFTypeDeprecatedFault(SWFClientError):
|
class SWFTypeDeprecatedFault(SWFClientError):
|
||||||
def __init__(self, _type):
|
def __init__(self, _type):
|
||||||
super(SWFTypeDeprecatedFault, self).__init__(
|
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")
|
"com.amazonaws.swf.base.model#TypeDeprecatedFault")
|
||||||
|
|
||||||
|
|
||||||
@ -107,14 +107,14 @@ class SWFDecisionValidationException(SWFClientError):
|
|||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
"Unhandled decision constraint type: {}".format(pb["type"])
|
"Unhandled decision constraint type: {0}".format(pb["type"])
|
||||||
)
|
)
|
||||||
# prefix
|
# prefix
|
||||||
count = len(problems)
|
count = len(problems)
|
||||||
if count < 2:
|
if count < 2:
|
||||||
prefix = "{} validation error detected: "
|
prefix = "{0} validation error detected: "
|
||||||
else:
|
else:
|
||||||
prefix = "{} validation errors detected: "
|
prefix = "{0} validation errors detected: "
|
||||||
super(SWFDecisionValidationException, self).__init__(
|
super(SWFDecisionValidationException, self).__init__(
|
||||||
prefix.format(count) + "; ".join(messages),
|
prefix.format(count) + "; ".join(messages),
|
||||||
"com.amazon.coral.validate#ValidationException"
|
"com.amazon.coral.validate#ValidationException"
|
||||||
|
@ -117,7 +117,7 @@ class SWFBackend(BaseBackend):
|
|||||||
_type = domain.get_type(kind, name, version, ignore_empty=True)
|
_type = domain.get_type(kind, name, version, ignore_empty=True)
|
||||||
if _type:
|
if _type:
|
||||||
raise SWFTypeAlreadyExistsFault(_type)
|
raise SWFTypeAlreadyExistsFault(_type)
|
||||||
_class = globals()["{}Type".format(kind.capitalize())]
|
_class = globals()["{0}Type".format(kind.capitalize())]
|
||||||
_type = _class(name, version, **kwargs)
|
_type = _class(name, version, **kwargs)
|
||||||
domain.add_type(_type)
|
domain.add_type(_type)
|
||||||
|
|
||||||
@ -245,7 +245,7 @@ class SWFBackend(BaseBackend):
|
|||||||
if wfe.execution_status != "OPEN":
|
if wfe.execution_status != "OPEN":
|
||||||
raise SWFUnknownResourceFault(
|
raise SWFUnknownResourceFault(
|
||||||
"execution",
|
"execution",
|
||||||
"WorkflowExecution=[workflowId={}, runId={}]".format(
|
"WorkflowExecution=[workflowId={0}, runId={1}]".format(
|
||||||
wfe.workflow_id, wfe.run_id
|
wfe.workflow_id, wfe.run_id
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@ -253,7 +253,7 @@ class SWFBackend(BaseBackend):
|
|||||||
if decision_task.state != "STARTED":
|
if decision_task.state != "STARTED":
|
||||||
if decision_task.state == "COMPLETED":
|
if decision_task.state == "COMPLETED":
|
||||||
raise SWFUnknownResourceFault(
|
raise SWFUnknownResourceFault(
|
||||||
"decision task, scheduledEventId = {}".format(decision_task.scheduled_event_id)
|
"decision task, scheduledEventId = {0}".format(decision_task.scheduled_event_id)
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
@ -333,7 +333,7 @@ class SWFBackend(BaseBackend):
|
|||||||
if wfe.execution_status != "OPEN":
|
if wfe.execution_status != "OPEN":
|
||||||
raise SWFUnknownResourceFault(
|
raise SWFUnknownResourceFault(
|
||||||
"execution",
|
"execution",
|
||||||
"WorkflowExecution=[workflowId={}, runId={}]".format(
|
"WorkflowExecution=[workflowId={0}, runId={1}]".format(
|
||||||
wfe.workflow_id, wfe.run_id
|
wfe.workflow_id, wfe.run_id
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@ -341,7 +341,7 @@ class SWFBackend(BaseBackend):
|
|||||||
if activity_task.state != "STARTED":
|
if activity_task.state != "STARTED":
|
||||||
if activity_task.state == "COMPLETED":
|
if activity_task.state == "COMPLETED":
|
||||||
raise SWFUnknownResourceFault(
|
raise SWFUnknownResourceFault(
|
||||||
"activity, scheduledEventId = {}".format(activity_task.scheduled_event_id)
|
"activity, scheduledEventId = {0}".format(activity_task.scheduled_event_id)
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
|
@ -53,7 +53,7 @@ class Domain(object):
|
|||||||
if not ignore_empty:
|
if not ignore_empty:
|
||||||
raise SWFUnknownResourceFault(
|
raise SWFUnknownResourceFault(
|
||||||
"type",
|
"type",
|
||||||
"{}Type=[name={}, version={}]".format(
|
"{0}Type=[name={1}, version={2}]".format(
|
||||||
kind.capitalize(), name, version
|
kind.capitalize(), name, version
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@ -91,10 +91,10 @@ class Domain(object):
|
|||||||
wfe = None
|
wfe = None
|
||||||
if not wfe and raise_if_none:
|
if not wfe and raise_if_none:
|
||||||
if run_id:
|
if run_id:
|
||||||
args = ["execution", "WorkflowExecution=[workflowId={}, runId={}]".format(
|
args = ["execution", "WorkflowExecution=[workflowId={0}, runId={1}]".format(
|
||||||
workflow_id, run_id)]
|
workflow_id, run_id)]
|
||||||
else:
|
else:
|
||||||
args = ["execution, workflowId = {}".format(workflow_id)]
|
args = ["execution, workflowId = {0}".format(workflow_id)]
|
||||||
raise SWFUnknownResourceFault(*args)
|
raise SWFUnknownResourceFault(*args)
|
||||||
# at last return workflow execution
|
# at last return workflow execution
|
||||||
return wfe
|
return wfe
|
||||||
|
@ -23,7 +23,7 @@ class GenericType(object):
|
|||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
cls = self.__class__.__name__
|
cls = self.__class__.__name__
|
||||||
attrs = "name: %(name)s, version: %(version)s, status: %(status)s" % self.__dict__
|
attrs = "name: %(name)s, version: %(version)s, status: %(status)s" % self.__dict__
|
||||||
return "{}({})".format(cls, attrs)
|
return "{0}({1})".format(cls, attrs)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def kind(self):
|
def kind(self):
|
||||||
@ -41,7 +41,7 @@ class GenericType(object):
|
|||||||
|
|
||||||
def to_medium_dict(self):
|
def to_medium_dict(self):
|
||||||
hsh = {
|
hsh = {
|
||||||
"{}Type".format(self.kind): self.to_short_dict(),
|
"{0}Type".format(self.kind): self.to_short_dict(),
|
||||||
"creationDate": 1420066800,
|
"creationDate": 1420066800,
|
||||||
"status": self.status,
|
"status": self.status,
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ class HistoryEvent(object):
|
|||||||
}
|
}
|
||||||
|
|
||||||
def _attributes_key(self):
|
def _attributes_key(self):
|
||||||
key = "{}EventAttributes".format(self.event_type)
|
key = "{0}EventAttributes".format(self.event_type)
|
||||||
return decapitalize(key)
|
return decapitalize(key)
|
||||||
|
|
||||||
def event_attributes(self):
|
def event_attributes(self):
|
||||||
@ -154,5 +154,5 @@ class HistoryEvent(object):
|
|||||||
return hsh
|
return hsh
|
||||||
else:
|
else:
|
||||||
raise NotImplementedError(
|
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)
|
||||||
)
|
)
|
||||||
|
@ -83,7 +83,7 @@ class WorkflowExecution(object):
|
|||||||
self.child_workflow_executions = []
|
self.child_workflow_executions = []
|
||||||
|
|
||||||
def __repr__(self):
|
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):
|
def _set_from_kwargs_or_workflow_type(self, kwargs, local_key, workflow_type_key=None):
|
||||||
if workflow_type_key is None:
|
if workflow_type_key is None:
|
||||||
@ -219,7 +219,7 @@ class WorkflowExecution(object):
|
|||||||
if dt.task_token == task_token:
|
if dt.task_token == task_token:
|
||||||
return dt
|
return dt
|
||||||
raise ValueError(
|
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):
|
def start_decision_task(self, task_token, identity=None):
|
||||||
@ -260,7 +260,7 @@ class WorkflowExecution(object):
|
|||||||
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",
|
||||||
"where": "decisions.{}.member.{}.{}".format(
|
"where": "decisions.{0}.member.{1}.{2}".format(
|
||||||
decision_id, kind, key
|
decision_id, kind, key
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
@ -297,7 +297,7 @@ class WorkflowExecution(object):
|
|||||||
attrs_to_check = filter(lambda x: x.endswith("DecisionAttributes"), dcs.keys())
|
attrs_to_check = filter(lambda x: x.endswith("DecisionAttributes"), dcs.keys())
|
||||||
if dcs["decisionType"] in self.KNOWN_DECISION_TYPES:
|
if dcs["decisionType"] in self.KNOWN_DECISION_TYPES:
|
||||||
decision_type = dcs["decisionType"]
|
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)
|
attrs_to_check.append(decision_attr)
|
||||||
for attr in attrs_to_check:
|
for attr in attrs_to_check:
|
||||||
problems += self._check_decision_attributes(attr, dcs.get(attr, {}), decision_number)
|
problems += self._check_decision_attributes(attr, dcs.get(attr, {}), decision_number)
|
||||||
@ -306,7 +306,7 @@ class WorkflowExecution(object):
|
|||||||
problems.append({
|
problems.append({
|
||||||
"type": "bad_decision_type",
|
"type": "bad_decision_type",
|
||||||
"value": dcs["decisionType"],
|
"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),
|
"possible_values": ", ".join(self.KNOWN_DECISION_TYPES),
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -322,7 +322,7 @@ class WorkflowExecution(object):
|
|||||||
# handle each decision separately, in order
|
# handle each decision separately, in order
|
||||||
for decision in decisions:
|
for decision in decisions:
|
||||||
decision_type = decision["decisionType"]
|
decision_type = decision["decisionType"]
|
||||||
attributes_key = "{}DecisionAttributes".format(decapitalize(decision_type))
|
attributes_key = "{0}DecisionAttributes".format(decapitalize(decision_type))
|
||||||
attributes = decision.get(attributes_key, {})
|
attributes = decision.get(attributes_key, {})
|
||||||
if decision_type == "CompleteWorkflowExecution":
|
if decision_type == "CompleteWorkflowExecution":
|
||||||
self.complete(event_id, attributes.get("result"))
|
self.complete(event_id, attributes.get("result"))
|
||||||
@ -341,7 +341,7 @@ class WorkflowExecution(object):
|
|||||||
# TODO: implement Decision type: SignalExternalWorkflowExecution
|
# TODO: implement Decision type: SignalExternalWorkflowExecution
|
||||||
# TODO: implement Decision type: StartChildWorkflowExecution
|
# TODO: implement Decision type: StartChildWorkflowExecution
|
||||||
# TODO: implement Decision type: StartTimer
|
# 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
|
# finally decrement counter if and only if everything went well
|
||||||
self.open_counts["openDecisionTasks"] -= 1
|
self.open_counts["openDecisionTasks"] -= 1
|
||||||
@ -419,7 +419,7 @@ class WorkflowExecution(object):
|
|||||||
if not timeouts[_type]:
|
if not timeouts[_type]:
|
||||||
error_key = default_key.replace("default_task_", "default_")
|
error_key = default_key.replace("default_task_", "default_")
|
||||||
fail_schedule_activity_task(activity_type,
|
fail_schedule_activity_task(activity_type,
|
||||||
"{}_UNDEFINED".format(error_key.upper()))
|
"{0}_UNDEFINED".format(error_key.upper()))
|
||||||
return
|
return
|
||||||
|
|
||||||
# Only add event and increment counters now that nothing went wrong
|
# Only add event and increment counters now that nothing went wrong
|
||||||
@ -447,7 +447,7 @@ class WorkflowExecution(object):
|
|||||||
if task.task_token == task_token:
|
if task.task_token == task_token:
|
||||||
return task
|
return task
|
||||||
raise ValueError(
|
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):
|
def start_activity_task(self, task_token, identity=None):
|
||||||
|
@ -61,7 +61,7 @@ class SWFResponse(BaseResponse):
|
|||||||
|
|
||||||
def _describe_type(self, kind):
|
def _describe_type(self, kind):
|
||||||
domain = self._params["domain"]
|
domain = self._params["domain"]
|
||||||
_type_args = self._params["{}Type".format(kind)]
|
_type_args = self._params["{0}Type".format(kind)]
|
||||||
name = _type_args["name"]
|
name = _type_args["name"]
|
||||||
version = _type_args["version"]
|
version = _type_args["version"]
|
||||||
_type = self.swf_backend.describe_type(kind, domain, name, version)
|
_type = self.swf_backend.describe_type(kind, domain, name, version)
|
||||||
@ -70,7 +70,7 @@ class SWFResponse(BaseResponse):
|
|||||||
|
|
||||||
def _deprecate_type(self, kind):
|
def _deprecate_type(self, kind):
|
||||||
domain = self._params["domain"]
|
domain = self._params["domain"]
|
||||||
_type_args = self._params["{}Type".format(kind)]
|
_type_args = self._params["{0}Type".format(kind)]
|
||||||
name = _type_args["name"]
|
name = _type_args["name"]
|
||||||
version = _type_args["version"]
|
version = _type_args["version"]
|
||||||
self.swf_backend.deprecate_type(kind, domain, name, version)
|
self.swf_backend.deprecate_type(kind, domain, name, version)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user