<s> import logging <EOL> from botocore import xform_name <EOL> from . params import create_request_parameters <EOL> from . response import RawHandler , ResourceHandler <EOL> from . model import Action <EOL> from boto3 . docs . docstring import ActionDocstring <EOL> from boto3 . utils import inject_attribute <EOL> logger = logging . getLogger ( __name__ ) <EOL> class ServiceAction ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , action_model , factory = None , service_context = None ) : <EOL> self . _action_model = action_model <EOL> resource_response_model = action_model . resource <EOL> if resource_response_model : <EOL> self . _response_handler = ResourceHandler ( <EOL> search_path = resource_response_model . path , <EOL> factory = factory , resource_model = resource_response_model , <EOL> service_context = service_context , <EOL> operation_name = action_model . request . operation <EOL> ) <EOL> else : <EOL> self . _response_handler = RawHandler ( action_model . path ) <EOL> def __call__ ( self , parent , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> operation_name = xform_name ( self . _action_model . request . operation ) <EOL> params = create_request_parameters ( parent , self . _action_model . request ) <EOL> params . update ( kwargs ) <EOL> logger . info ( '<STR_LIT>' , parent . meta . service_name , <EOL> operation_name , params ) <EOL> response = getattr ( parent . meta . client , operation_name ) ( ** params ) <EOL> logger . debug ( '<STR_LIT>' , response ) <EOL> return self . _response_handler ( parent , params , response ) <EOL> class BatchAction ( ServiceAction ) : <EOL> """<STR_LIT>""" <EOL> def __call__ ( self , parent , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> service_name = None <EOL> client = None <EOL> responses = [ ] <EOL> operation_name = xform_name ( self . _action_model . request . operation ) <EOL> for page in parent . pages ( ) : <EOL> params = { } <EOL> for index , resource in enumerate ( page ) : <EOL> if service_name is None : <EOL> service_name = resource . meta . service_name <EOL> if client is None : <EOL> client = resource . meta . client <EOL> create_request_parameters ( <EOL> resource , self . _action_model . request , <EOL> params = params , index = index ) <EOL> if not params : <EOL> break <EOL> params . update ( kwargs ) <EOL> logger . info ( '<STR_LIT>' , <EOL> service_name , operation_name , params ) <EOL> response = getattr ( client , operation_name ) ( ** params ) <EOL> logger . debug ( '<STR_LIT>' , response ) <EOL> responses . append ( <EOL> self . _response_handler ( parent , params , response ) ) <EOL> return responses <EOL> class WaiterAction ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , waiter_model , waiter_resource_name ) : <EOL> self . _waiter_model = waiter_model <EOL> self . _waiter_resource_name = waiter_resource_name <EOL> def __call__ ( self , parent , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> client_waiter_name = xform_name ( self . _waiter_model . waiter_name ) <EOL> params = create_request_parameters ( parent , self . _waiter_model ) <EOL> params . update ( kwargs ) <EOL> logger . info ( '<STR_LIT>' , <EOL> parent . meta . service_name , <EOL> self . _waiter_resource_name , params ) <EOL> client = parent . meta . client <EOL> waiter = client . get_waiter ( client_waiter_name ) <EOL> response = waiter . wait ( ** params ) <EOL> logger . debug ( '<STR_LIT>' , response ) <EOL> class CustomModeledAction ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , action_name , action_model , <EOL> function , event_emitter ) : <EOL> """<STR_LIT>""" <EOL> self . name = action_name <EOL> self . model = action_model <EOL> self . function = function <EOL> self . emitter = event_emitter <EOL> def inject ( self , class_attributes , service_context , event_name , ** kwargs ) : <EOL> resource_name = event_name . rsplit ( "<STR_LIT:.>" ) [ - <NUM_LIT:1> ] <EOL> action = Action ( self . name , self . model , { } ) <EOL> self . function . __name__ = self . name <EOL> self . function . __doc__ = ActionDocstring ( <EOL> resource_name = resource_name , <EOL> event_emitter = self . emitter , <EOL> action_model = action , <EOL> service_model = service_context . service_model , <EOL> include_signature = False <EOL> ) <EOL> inject_attribute ( class_attributes , self . name , self . function ) </s>
