<s> import time <EOL> import boto <EOL> from boto . connection import AWSAuthConnection <EOL> from boto . provider import Provider <EOL> from boto . exception import SWFResponseError <EOL> from boto . swf import exceptions as swf_exceptions <EOL> from boto . compat import json <EOL> Debug = <NUM_LIT:0> <EOL> class Layer1 ( AWSAuthConnection ) : <EOL> """<STR_LIT>""" <EOL> DefaultRegionName = '<STR_LIT>' <EOL> """<STR_LIT>""" <EOL> ServiceName = '<STR_LIT>' <EOL> """<STR_LIT>""" <EOL> _fault_excp = { <EOL> '<STR_LIT>' : <EOL> swf_exceptions . SWFDomainAlreadyExistsError , <EOL> '<STR_LIT>' : <EOL> swf_exceptions . SWFLimitExceededError , <EOL> '<STR_LIT>' : <EOL> swf_exceptions . SWFOperationNotPermittedError , <EOL> '<STR_LIT>' : <EOL> swf_exceptions . SWFTypeAlreadyExistsError , <EOL> '<STR_LIT>' : <EOL> swf_exceptions . SWFWorkflowExecutionAlreadyStartedError , <EOL> } <EOL> ResponseError = SWFResponseError <EOL> def __init__ ( self , aws_access_key_id = None , aws_secret_access_key = None , <EOL> is_secure = True , port = None , proxy = None , proxy_port = None , <EOL> debug = <NUM_LIT:0> , session_token = None , region = None , profile_name = None ) : <EOL> if not region : <EOL> region_name = boto . config . get ( '<STR_LIT>' , '<STR_LIT>' , <EOL> self . DefaultRegionName ) <EOL> for reg in boto . swf . regions ( ) : <EOL> if reg . name == region_name : <EOL> region = reg <EOL> break <EOL> self . region = region <EOL> super ( Layer1 , self ) . __init__ ( self . region . endpoint , <EOL> aws_access_key_id , aws_secret_access_key , <EOL> is_secure , port , proxy , proxy_port , <EOL> debug , session_token , profile_name = profile_name ) <EOL> def _required_auth_capability ( self ) : <EOL> return [ '<STR_LIT>' ] <EOL> @ classmethod <EOL> def _normalize_request_dict ( cls , data ) : <EOL> """<STR_LIT>""" <EOL> for item in list ( data . keys ( ) ) : <EOL> if isinstance ( data [ item ] , dict ) : <EOL> cls . _normalize_request_dict ( data [ item ] ) <EOL> if data [ item ] in ( None , { } ) : <EOL> del data [ item ] <EOL> def json_request ( self , action , data , object_hook = None ) : <EOL> """<STR_LIT>""" <EOL> self . _normalize_request_dict ( data ) <EOL> json_input = json . dumps ( data ) <EOL> return self . make_request ( action , json_input , object_hook ) <EOL> def make_request ( self , action , body = '<STR_LIT>' , object_hook = None ) : <EOL> """<STR_LIT>""" <EOL> headers = { '<STR_LIT>' : '<STR_LIT>' % ( self . ServiceName , action ) , <EOL> '<STR_LIT>' : self . region . endpoint , <EOL> '<STR_LIT:Content-Type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str ( len ( body ) ) } <EOL> http_request = self . build_base_http_request ( '<STR_LIT:POST>' , '<STR_LIT:/>' , '<STR_LIT:/>' , <EOL> { } , headers , body , None ) <EOL> response = self . _mexe ( http_request , sender = None , <EOL> override_num_retries = <NUM_LIT:10> ) <EOL> response_body = response . read ( ) . decode ( '<STR_LIT:utf-8>' ) <EOL> boto . log . debug ( response_body ) <EOL> if response . status == <NUM_LIT:200> : <EOL> if response_body : <EOL> return json . loads ( response_body , object_hook = object_hook ) <EOL> else : <EOL> return None <EOL> else : <EOL> json_body = json . loads ( response_body ) <EOL> fault_name = json_body . get ( '<STR_LIT>' , None ) <EOL> excp_cls = self . _fault_excp . get ( fault_name , self . ResponseError ) <EOL> raise excp_cls ( response . status , response . reason , body = json_body ) <EOL> def poll_for_activity_task ( self , domain , task_list , identity = None ) : <EOL> """<STR_LIT>""" <EOL> return self . json_request ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : domain , <EOL> '<STR_LIT>' : { '<STR_LIT:name>' : task_list } , <EOL> '<STR_LIT>' : identity , <EOL> } ) <EOL> def respond_activity_task_completed ( self , task_token , result = None ) : <EOL> """<STR_LIT>""" <EOL> return self . json_request ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : task_token , <EOL> '<STR_LIT:result>' : result , <EOL> } ) <EOL> def respond_activity_task_failed ( self , task_token , <EOL> details = None , reason = None ) : <EOL> """<STR_LIT>""" <EOL> return self . json_request ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : task_token , <EOL> '<STR_LIT>' : details , <EOL> '<STR_LIT>' : reason , <EOL> } ) <EOL> def respond_activity_task_canceled ( self , task_token , details = None ) : <EOL> """<STR_LIT>""" <EOL> return self . json_request ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : task_token , <EOL> '<STR_LIT>' : details , <EOL> } ) <EOL> def record_activity_task_heartbeat ( self , task_token , details = None ) : <EOL> """<STR_LIT>""" <EOL> return self . json_request ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : task_token , <EOL> '<STR_LIT>' : details , <EOL> } ) <EOL> def poll_for_decision_task ( self , domain , task_list , identity = None , <EOL> maximum_page_size = None , <EOL> next_page_token = None , <EOL> reverse_order = None ) : <EOL> """<STR_LIT>""" <EOL> return self . json_request ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : domain , <EOL> '<STR_LIT>' : { '<STR_LIT:name>' : task_list } , <EOL> '<STR_LIT>' : identity , <EOL> '<STR_LIT>' : maximum_page_size , <EOL> '<STR_LIT>' : next_page_token , <EOL> '<STR_LIT>' : reverse_order , <EOL> } ) <EOL> def respond_decision_task_completed ( self , task_token , <EOL> decisions = None , <EOL> execution_context = None ) : <EOL> """<STR_LIT>""" <EOL> return self . json_request ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : task_token , <EOL> '<STR_LIT>' : decisions , <EOL> '<STR_LIT>' : execution_context , <EOL> } ) <EOL> def request_cancel_workflow_execution ( self , domain , workflow_id , <EOL> run_id = None ) : <EOL> """<STR_LIT>""" <EOL> return self . json_request ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : domain , <EOL> '<STR_LIT>' : workflow_id , <EOL> '<STR_LIT>' : run_id , <EOL> } ) <EOL> def start_workflow_execution ( self , domain , workflow_id , <EOL> workflow_name , workflow_version , <EOL> task_list = None , child_policy = None , <EOL> execution_start_to_close_timeout = None , <EOL> input = None , tag_list = None , <EOL> task_start_to_close_timeout = None ) : <EOL> """<STR_LIT>""" <EOL> return self . json_request ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : domain , <EOL> '<STR_LIT>' : workflow_id , <EOL> '<STR_LIT>' : { '<STR_LIT:name>' : workflow_name , <EOL> '<STR_LIT:version>' : workflow_version } , <EOL> '<STR_LIT>' : { '<STR_LIT:name>' : task_list } , <EOL> '<STR_LIT>' : child_policy , <EOL> '<STR_LIT>' : execution_start_to_close_timeout , <EOL> '<STR_LIT:input>' : input , <EOL> '<STR_LIT>' : tag_list , <EOL> '<STR_LIT>' : task_start_to_close_timeout , <EOL> } ) <EOL> def signal_workflow_execution ( self , domain , signal_name , workflow_id , <EOL> input = None , run_id = None ) : <EOL> """<STR_LIT>""" <EOL> return self . json_request ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : domain , <EOL> '<STR_LIT>' : signal_name , <EOL> '<STR_LIT>' : workflow_id , <EOL> '<STR_LIT:input>' : input , <EOL> '<STR_LIT>' : run_id , <EOL> } ) <EOL> def terminate_workflow_execution ( self , domain , workflow_id , <EOL> child_policy = None , details = None , <EOL> reason = None , run_id = None ) : <EOL> """<STR_LIT>""" <EOL> return self . json_request ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : domain , <EOL> '<STR_LIT>' : workflow_id , <EOL> '<STR_LIT>' : child_policy , <EOL> '<STR_LIT>' : details , <EOL> '<STR_LIT>' : reason , <EOL> '<STR_LIT>' : run_id , <EOL> } ) <EOL> def register_activity_type ( self , domain , name , version , task_list = None , <EOL> default_task_heartbeat_timeout = None , <EOL> default_task_schedule_to_close_timeout = None , <EOL> default_task_schedule_to_start_timeout = None , <EOL> default_task_start_to_close_timeout = None , <EOL> description = None ) : <EOL> """<STR_LIT>""" <EOL> return self . json_request ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : domain , <EOL> '<STR_LIT:name>' : name , <EOL> '<STR_LIT:version>' : version , <EOL> '<STR_LIT>' : { '<STR_LIT:name>' : task_list } , <EOL> '<STR_LIT>' : default_task_heartbeat_timeout , <EOL> '<STR_LIT>' : default_task_schedule_to_close_timeout , <EOL> '<STR_LIT>' : default_task_schedule_to_start_timeout , <EOL> '<STR_LIT>' : default_task_start_to_close_timeout , <EOL> '<STR_LIT:description>' : description , <EOL> } ) <EOL> def deprecate_activity_type ( self , domain , activity_name , activity_version ) : <EOL> """<STR_LIT>""" <EOL> return self . json_request ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : domain , <EOL> '<STR_LIT>' : { '<STR_LIT:name>' : activity_name , <EOL> '<STR_LIT:version>' : activity_version } <EOL> } ) <EOL> def register_workflow_type ( self , domain , name , version , <EOL> task_list = None , <EOL> default_child_policy = None , <EOL> default_execution_start_to_close_timeout = None , <EOL> default_task_start_to_close_timeout = None , <EOL> description = None ) : <EOL> """<STR_LIT>""" <EOL> return self . json_request ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : domain , <EOL> '<STR_LIT:name>' : name , <EOL> '<STR_LIT:version>' : version , <EOL> '<STR_LIT>' : { '<STR_LIT:name>' : task_list } , <EOL> '<STR_LIT>' : default_child_policy , <EOL> '<STR_LIT>' : default_execution_start_to_close_timeout , <EOL> '<STR_LIT>' : default_task_start_to_close_timeout , <EOL> '<STR_LIT:description>' : description , <EOL> } ) <EOL> def deprecate_workflow_type ( self , domain , workflow_name , workflow_version ) : <EOL> """<STR_LIT>""" <EOL> return self . json_request ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : domain , <EOL> '<STR_LIT>' : { '<STR_LIT:name>' : workflow_name , <EOL> '<STR_LIT:version>' : workflow_version } , <EOL> } ) <EOL> def register_domain ( self , name , <EOL> workflow_execution_retention_period_in_days , <EOL> description = None ) : <EOL> """<STR_LIT>""" <EOL> return self . json_request ( '<STR_LIT>' , { <EOL> '<STR_LIT:name>' : name , <EOL> '<STR_LIT>' : workflow_execution_retention_period_in_days , <EOL> '<STR_LIT:description>' : description , <EOL> } ) <EOL> def deprecate_domain ( self , name ) : <EOL> """<STR_LIT>""" <EOL> return self . json_request ( '<STR_LIT>' , { '<STR_LIT:name>' : name } ) <EOL> def list_activity_types ( self , domain , registration_status , <EOL> name = None , <EOL> maximum_page_size = None , <EOL> next_page_token = None , reverse_order = None ) : <EOL> """<STR_LIT>""" <EOL> return self . json_request ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : domain , <EOL> '<STR_LIT:name>' : name , <EOL> '<STR_LIT>' : registration_status , <EOL> '<STR_LIT>' : maximum_page_size , <EOL> '<STR_LIT>' : next_page_token , <EOL> '<STR_LIT>' : reverse_order , <EOL> } ) <EOL> def describe_activity_type ( self , domain , activity_name , activity_version ) : <EOL> """<STR_LIT>""" <EOL> return self . json_request ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : domain , <EOL> '<STR_LIT>' : { '<STR_LIT:name>' : activity_name , <EOL> '<STR_LIT:version>' : activity_version } <EOL> } ) <EOL> def list_workflow_types ( self , domain , registration_status , <EOL> maximum_page_size = None , name = None , <EOL> next_page_token = None , reverse_order = None ) : <EOL> """<STR_LIT>""" <EOL> return self . json_request ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : domain , <EOL> '<STR_LIT:name>' : name , <EOL> '<STR_LIT>' : registration_status , <EOL> '<STR_LIT>' : maximum_page_size , <EOL> '<STR_LIT>' : next_page_token , <EOL> '<STR_LIT>' : reverse_order , <EOL> } ) <EOL> def describe_workflow_type ( self , domain , workflow_name , workflow_version ) : <EOL> """<STR_LIT>""" <EOL> return self . json_request ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : domain , <EOL> '<STR_LIT>' : { '<STR_LIT:name>' : workflow_name , <EOL> '<STR_LIT:version>' : workflow_version } <EOL> } ) <EOL> def describe_workflow_execution ( self , domain , run_id , workflow_id ) : <EOL> """<STR_LIT>""" <EOL> return self . json_request ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : domain , <EOL> '<STR_LIT>' : { '<STR_LIT>' : run_id , <EOL> '<STR_LIT>' : workflow_id } , <EOL> } ) <EOL> def get_workflow_execution_history ( self , domain , run_id , workflow_id , <EOL> maximum_page_size = None , <EOL> next_page_token = None , <EOL> reverse_order = None ) : <EOL> """<STR_LIT>""" <EOL> return self . json_request ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : domain , <EOL> '<STR_LIT>' : { '<STR_LIT>' : run_id , <EOL> '<STR_LIT>' : workflow_id } , <EOL> '<STR_LIT>' : maximum_page_size , <EOL> '<STR_LIT>' : next_page_token , <EOL> '<STR_LIT>' : reverse_order , <EOL> } ) <EOL> def count_open_workflow_executions ( self , domain , latest_date , oldest_date , <EOL> tag = None , <EOL> workflow_id = None , <EOL> workflow_name = None , <EOL> workflow_version = None ) : <EOL> """<STR_LIT>""" <EOL> return self . json_request ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : domain , <EOL> '<STR_LIT>' : { '<STR_LIT>' : oldest_date , <EOL> '<STR_LIT>' : latest_date } , <EOL> '<STR_LIT>' : { '<STR_LIT:name>' : workflow_name , <EOL> '<STR_LIT:version>' : workflow_version } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : workflow_id } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : tag } , <EOL> } ) <EOL> def list_open_workflow_executions ( self , domain , <EOL> oldest_date , <EOL> latest_date = None , <EOL> tag = None , <EOL> workflow_id = None , <EOL> workflow_name = None , <EOL> workflow_version = None , <EOL> maximum_page_size = None , <EOL> next_page_token = None , <EOL> reverse_order = None ) : <EOL> """<STR_LIT>""" <EOL> return self . json_request ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : domain , <EOL> '<STR_LIT>' : { '<STR_LIT>' : oldest_date , <EOL> '<STR_LIT>' : latest_date } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : tag } , <EOL> '<STR_LIT>' : { '<STR_LIT:name>' : workflow_name , <EOL> '<STR_LIT:version>' : workflow_version } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : workflow_id } , <EOL> '<STR_LIT>' : maximum_page_size , <EOL> '<STR_LIT>' : next_page_token , <EOL> '<STR_LIT>' : reverse_order , <EOL> } ) <EOL> def count_closed_workflow_executions ( self , domain , <EOL> start_latest_date = None , <EOL> start_oldest_date = None , <EOL> close_latest_date = None , <EOL> close_oldest_date = None , <EOL> close_status = None , <EOL> tag = None , <EOL> workflow_id = None , <EOL> workflow_name = None , <EOL> workflow_version = None ) : <EOL> """<STR_LIT>""" <EOL> return self . json_request ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : domain , <EOL> '<STR_LIT>' : { '<STR_LIT>' : start_oldest_date , <EOL> '<STR_LIT>' : start_latest_date } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : close_oldest_date , <EOL> '<STR_LIT>' : close_latest_date } , <EOL> '<STR_LIT>' : { '<STR_LIT:status>' : close_status } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : tag } , <EOL> '<STR_LIT>' : { '<STR_LIT:name>' : workflow_name , <EOL> '<STR_LIT:version>' : workflow_version } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : workflow_id } <EOL> } ) <EOL> def list_closed_workflow_executions ( self , domain , <EOL> start_latest_date = None , <EOL> start_oldest_date = None , <EOL> close_latest_date = None , <EOL> close_oldest_date = None , <EOL> close_status = None , <EOL> tag = None , <EOL> workflow_id = None , <EOL> workflow_name = None , <EOL> workflow_version = None , <EOL> maximum_page_size = None , <EOL> next_page_token = None , <EOL> reverse_order = None ) : <EOL> """<STR_LIT>""" <EOL> return self . json_request ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : domain , <EOL> '<STR_LIT>' : { '<STR_LIT>' : start_oldest_date , <EOL> '<STR_LIT>' : start_latest_date } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : close_oldest_date , <EOL> '<STR_LIT>' : close_latest_date } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : workflow_id } , <EOL> '<STR_LIT>' : { '<STR_LIT:status>' : close_status } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : tag } , <EOL> '<STR_LIT>' : { '<STR_LIT:name>' : workflow_name , <EOL> '<STR_LIT:version>' : workflow_version } , <EOL> '<STR_LIT>' : maximum_page_size , <EOL> '<STR_LIT>' : next_page_token , <EOL> '<STR_LIT>' : reverse_order , <EOL> } ) <EOL> def list_domains ( self , registration_status , <EOL> maximum_page_size = None , <EOL> next_page_token = None , reverse_order = None ) : <EOL> """<STR_LIT>""" <EOL> return self . json_request ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : registration_status , <EOL> '<STR_LIT>' : maximum_page_size , <EOL> '<STR_LIT>' : next_page_token , <EOL> '<STR_LIT>' : reverse_order , <EOL> } ) <EOL> def describe_domain ( self , name ) : <EOL> """<STR_LIT>""" <EOL> return self . json_request ( '<STR_LIT>' , { '<STR_LIT:name>' : name } ) <EOL> def count_pending_decision_tasks ( self , domain , task_list ) : <EOL> """<STR_LIT>""" <EOL> return self . json_request ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : domain , <EOL> '<STR_LIT>' : { '<STR_LIT:name>' : task_list } <EOL> } ) <EOL> def count_pending_activity_tasks ( self , domain , task_list ) : <EOL> """<STR_LIT>""" <EOL> return self . json_request ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : domain , <EOL> '<STR_LIT>' : { '<STR_LIT:name>' : task_list } <EOL> } ) </s>
