<s> """<STR_LIT>""" <EOL> import logging <EOL> from botocore import xform_name <EOL> from botocore . hooks import first_non_none_response <EOL> from awscli . argprocess import unpack_cli_arg <EOL> from awscli . schema import SchemaTransformer <EOL> from botocore import model <EOL> LOG = logging . getLogger ( '<STR_LIT>' ) <EOL> class UnknownArgumentError ( Exception ) : <EOL> pass <EOL> def create_argument_model_from_schema ( schema ) : <EOL> transformer = SchemaTransformer ( ) <EOL> shapes_map = transformer . transform ( schema ) <EOL> shape_resolver = model . ShapeResolver ( shapes_map ) <EOL> arg_shape = shape_resolver . get_shape_by_name ( '<STR_LIT>' ) <EOL> return arg_shape <EOL> class BaseCLIArgument ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , name ) : <EOL> self . _name = name <EOL> def add_to_arg_table ( self , argument_table ) : <EOL> """<STR_LIT>""" <EOL> argument_table [ self . name ] = self <EOL> def add_to_parser ( self , parser ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def add_to_params ( self , parameters , value ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> @ property <EOL> def name ( self ) : <EOL> return self . _name <EOL> @ property <EOL> def cli_name ( self ) : <EOL> return '<STR_LIT>' + self . _name <EOL> @ property <EOL> def cli_type_name ( self ) : <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> @ property <EOL> def required ( self ) : <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> @ property <EOL> def documentation ( self ) : <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> @ property <EOL> def cli_type ( self ) : <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> @ property <EOL> def py_name ( self ) : <EOL> return self . _name . replace ( '<STR_LIT:->' , '<STR_LIT:_>' ) <EOL> @ property <EOL> def choices ( self ) : <EOL> """<STR_LIT>""" <EOL> return None <EOL> @ property <EOL> def synopsis ( self ) : <EOL> return '<STR_LIT>' <EOL> @ property <EOL> def positional_arg ( self ) : <EOL> return False <EOL> @ property <EOL> def nargs ( self ) : <EOL> return None <EOL> @ name . setter <EOL> def name ( self , value ) : <EOL> self . _name = value <EOL> @ property <EOL> def group_name ( self ) : <EOL> """<STR_LIT>""" <EOL> return None <EOL> class CustomArgument ( BaseCLIArgument ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , name , help_text = '<STR_LIT>' , dest = None , default = None , <EOL> action = None , required = None , choices = None , nargs = None , <EOL> cli_type_name = None , group_name = None , positional_arg = False , <EOL> no_paramfile = False , argument_model = None , synopsis = '<STR_LIT>' , <EOL> const = None ) : <EOL> self . _name = name <EOL> self . _help = help_text <EOL> self . _dest = dest <EOL> self . _default = default <EOL> self . _action = action <EOL> self . _required = required <EOL> self . _nargs = nargs <EOL> self . _const = const <EOL> self . _cli_type_name = cli_type_name <EOL> self . _group_name = group_name <EOL> self . _positional_arg = positional_arg <EOL> if choices is None : <EOL> choices = [ ] <EOL> self . _choices = choices <EOL> self . _synopsis = synopsis <EOL> self . no_paramfile = no_paramfile <EOL> self . argument_model = None <EOL> if argument_model is None : <EOL> argument_model = self . _create_scalar_argument_model ( ) <EOL> self . argument_model = argument_model <EOL> if self . argument_model is not None and self . argument_model . type_name == '<STR_LIT:list>' : <EOL> self . _nargs = '<STR_LIT:+>' <EOL> def _create_scalar_argument_model ( self ) : <EOL> if self . _nargs is not None : <EOL> return None <EOL> type_name = self . cli_type_name <EOL> return create_argument_model_from_schema ( { '<STR_LIT:type>' : type_name } ) <EOL> @ property <EOL> def cli_name ( self ) : <EOL> if self . _positional_arg : <EOL> return self . _name <EOL> else : <EOL> return '<STR_LIT>' + self . _name <EOL> def add_to_parser ( self , parser ) : <EOL> """<STR_LIT>""" <EOL> cli_name = self . cli_name <EOL> kwargs = { } <EOL> if self . _dest is not None : <EOL> kwargs [ '<STR_LIT>' ] = self . _dest <EOL> if self . _action is not None : <EOL> kwargs [ '<STR_LIT:action>' ] = self . _action <EOL> if self . _default is not None : <EOL> kwargs [ '<STR_LIT:default>' ] = self . _default <EOL> if self . _choices : <EOL> kwargs [ '<STR_LIT>' ] = self . _choices <EOL> if self . _required is not None : <EOL> kwargs [ '<STR_LIT>' ] = self . _required <EOL> if self . _nargs is not None : <EOL> kwargs [ '<STR_LIT>' ] = self . _nargs <EOL> if self . _const is not None : <EOL> kwargs [ '<STR_LIT>' ] = self . _const <EOL> parser . add_argument ( cli_name , ** kwargs ) <EOL> @ property <EOL> def required ( self ) : <EOL> if self . _required is None : <EOL> return False <EOL> return self . _required <EOL> @ required . setter <EOL> def required ( self , value ) : <EOL> self . _required = value <EOL> @ property <EOL> def documentation ( self ) : <EOL> return self . _help <EOL> @ property <EOL> def cli_type_name ( self ) : <EOL> if self . _cli_type_name is not None : <EOL> return self . _cli_type_name <EOL> elif self . _action in [ '<STR_LIT:store_true>' , '<STR_LIT>' ] : <EOL> return '<STR_LIT>' <EOL> elif self . argument_model is not None : <EOL> return self . argument_model . type_name <EOL> else : <EOL> return '<STR_LIT:string>' <EOL> @ property <EOL> def cli_type ( self ) : <EOL> cli_type = str <EOL> if self . _action in [ '<STR_LIT:store_true>' , '<STR_LIT>' ] : <EOL> cli_type = bool <EOL> return cli_type <EOL> @ property <EOL> def choices ( self ) : <EOL> return self . _choices <EOL> @ property <EOL> def group_name ( self ) : <EOL> return self . _group_name <EOL> @ property <EOL> def synopsis ( self ) : <EOL> return self . _synopsis <EOL> @ property <EOL> def positional_arg ( self ) : <EOL> return self . _positional_arg <EOL> @ property <EOL> def nargs ( self ) : <EOL> return self . _nargs <EOL> class CLIArgument ( BaseCLIArgument ) : <EOL> """<STR_LIT>""" <EOL> TYPE_MAP = { <EOL> '<STR_LIT>' : str , <EOL> '<STR_LIT>' : str , <EOL> '<STR_LIT>' : str , <EOL> '<STR_LIT:list>' : str , <EOL> '<STR_LIT:string>' : str , <EOL> '<STR_LIT:float>' : float , <EOL> '<STR_LIT>' : str , <EOL> '<STR_LIT>' : int , <EOL> '<STR_LIT>' : bool , <EOL> '<STR_LIT>' : float , <EOL> '<STR_LIT>' : str <EOL> } <EOL> def __init__ ( self , name , argument_model , operation_model , <EOL> event_emitter , is_required = False , <EOL> serialized_name = None ) : <EOL> """<STR_LIT>""" <EOL> self . _name = name <EOL> if serialized_name is None : <EOL> serialized_name = name <EOL> self . _serialized_name = serialized_name <EOL> self . argument_model = argument_model <EOL> self . _required = is_required <EOL> self . _operation_model = operation_model <EOL> self . _event_emitter = event_emitter <EOL> self . _documentation = argument_model . documentation <EOL> @ property <EOL> def py_name ( self ) : <EOL> return self . _name . replace ( '<STR_LIT:->' , '<STR_LIT:_>' ) <EOL> @ property <EOL> def required ( self ) : <EOL> return self . _required <EOL> @ required . setter <EOL> def required ( self , value ) : <EOL> self . _required = value <EOL> @ property <EOL> def documentation ( self ) : <EOL> return self . _documentation <EOL> @ documentation . setter <EOL> def documentation ( self , value ) : <EOL> self . _documentation = value <EOL> @ property <EOL> def cli_type_name ( self ) : <EOL> return self . argument_model . type_name <EOL> @ property <EOL> def cli_type ( self ) : <EOL> return self . TYPE_MAP . get ( self . argument_model . type_name , str ) <EOL> def add_to_parser ( self , parser ) : <EOL> """<STR_LIT>""" <EOL> cli_name = self . cli_name <EOL> parser . add_argument ( <EOL> cli_name , <EOL> help = self . documentation , <EOL> type = self . cli_type , <EOL> required = self . required ) <EOL> def add_to_params ( self , parameters , value ) : <EOL> if value is None : <EOL> return <EOL> else : <EOL> unpacked = self . _unpack_argument ( value ) <EOL> LOG . debug ( '<STR_LIT>' , value , <EOL> self . py_name , unpacked ) <EOL> parameters [ self . _serialized_name ] = unpacked <EOL> def _unpack_argument ( self , value ) : <EOL> service_name = self . _operation_model . service_model . endpoint_prefix <EOL> operation_name = xform_name ( self . _operation_model . name , '<STR_LIT:->' ) <EOL> override = self . _emit_first_response ( '<STR_LIT>' % ( <EOL> service_name , operation_name ) , param = self . argument_model , <EOL> cli_argument = self , value = value ) <EOL> if override is not None : <EOL> return override <EOL> else : <EOL> return unpack_cli_arg ( self , value ) <EOL> def _emit ( self , name , ** kwargs ) : <EOL> return self . _event_emitter . emit ( name , ** kwargs ) <EOL> def _emit_first_response ( self , name , ** kwargs ) : <EOL> responses = self . _emit ( name , ** kwargs ) <EOL> return first_non_none_response ( responses ) <EOL> class ListArgument ( CLIArgument ) : <EOL> def add_to_parser ( self , parser ) : <EOL> cli_name = self . cli_name <EOL> parser . add_argument ( cli_name , <EOL> nargs = '<STR_LIT:*>' , <EOL> type = self . cli_type , <EOL> required = self . required ) <EOL> class BooleanArgument ( CLIArgument ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , name , argument_model , operation_model , <EOL> event_emitter , <EOL> is_required = False , action = '<STR_LIT:store_true>' , dest = None , <EOL> group_name = None , default = None , <EOL> serialized_name = None ) : <EOL> super ( BooleanArgument , self ) . __init__ ( name , <EOL> argument_model , <EOL> operation_model , <EOL> event_emitter , <EOL> is_required , <EOL> serialized_name = serialized_name ) <EOL> self . _mutex_group = None <EOL> self . _action = action <EOL> if dest is None : <EOL> self . _destination = self . py_name <EOL> else : <EOL> self . _destination = dest <EOL> if group_name is None : <EOL> self . _group_name = self . name <EOL> else : <EOL> self . _group_name = group_name <EOL> self . _default = default <EOL> def add_to_params ( self , parameters , value ) : <EOL> if value is not None : <EOL> parameters [ self . _serialized_name ] = value <EOL> def add_to_arg_table ( self , argument_table ) : <EOL> argument_table [ self . name ] = self <EOL> negative_name = '<STR_LIT>' % self . name <EOL> negative_version = self . __class__ ( <EOL> negative_name , self . argument_model , <EOL> self . _operation_model , self . _event_emitter , <EOL> action = '<STR_LIT>' , dest = self . _destination , <EOL> group_name = self . group_name , serialized_name = self . _serialized_name ) <EOL> argument_table [ negative_name ] = negative_version <EOL> def add_to_parser ( self , parser ) : <EOL> parser . add_argument ( self . cli_name , <EOL> help = self . documentation , <EOL> action = self . _action , <EOL> default = self . _default , <EOL> dest = self . _destination ) <EOL> @ property <EOL> def group_name ( self ) : <EOL> return self . _group_name </s>
