<s> """<STR_LIT>""" <EOL> import logging <EOL> from functools import partial <EOL> from awscli . argprocess import detect_shape_structure <EOL> from awscli import arguments <EOL> from awscli . customizations . utils import validate_mutually_exclusive_handler <EOL> LOG = logging . getLogger ( __name__ ) <EOL> _NOT_SPECIFIED = object ( ) <EOL> def register_bool_params ( event_handler ) : <EOL> event_handler . register ( '<STR_LIT>' , <EOL> partial ( pull_up_bool , <EOL> event_handler = event_handler ) ) <EOL> def _qualifies_for_simplification ( arg_model ) : <EOL> if detect_shape_structure ( arg_model ) == '<STR_LIT>' : <EOL> members = arg_model . members <EOL> if ( len ( members ) == <NUM_LIT:1> and <EOL> list ( members . keys ( ) ) [ <NUM_LIT:0> ] == '<STR_LIT>' and <EOL> list ( members . values ( ) ) [ <NUM_LIT:0> ] . type_name == '<STR_LIT>' ) : <EOL> return True <EOL> return False <EOL> def pull_up_bool ( argument_table , event_handler , ** kwargs ) : <EOL> boolean_pairs = [ ] <EOL> event_handler . register ( <EOL> '<STR_LIT>' , <EOL> partial ( validate_boolean_mutex_groups , <EOL> boolean_pairs = boolean_pairs ) ) <EOL> for key , value in list ( argument_table . items ( ) ) : <EOL> if hasattr ( value , '<STR_LIT>' ) : <EOL> arg_model = value . argument_model <EOL> if _qualifies_for_simplification ( arg_model ) : <EOL> new_arg = PositiveBooleanArgument ( <EOL> value . name , arg_model , value . _operation_model , <EOL> value . _event_emitter , <EOL> group_name = value . name , <EOL> serialized_name = value . _serialized_name ) <EOL> argument_table [ value . name ] = new_arg <EOL> negative_name = '<STR_LIT>' % value . name <EOL> negative_arg = NegativeBooleanParameter ( <EOL> negative_name , arg_model , value . _operation_model , <EOL> value . _event_emitter , <EOL> action = '<STR_LIT:store_true>' , dest = '<STR_LIT>' % new_arg . py_name , <EOL> group_name = value . name , <EOL> serialized_name = value . _serialized_name ) <EOL> argument_table [ negative_name ] = negative_arg <EOL> boolean_pairs . append ( ( new_arg , negative_arg ) ) <EOL> def validate_boolean_mutex_groups ( boolean_pairs , parsed_args , ** kwargs ) : <EOL> for positive , negative in boolean_pairs : <EOL> if getattr ( parsed_args , positive . py_name ) is not _NOT_SPECIFIED and getattr ( parsed_args , negative . py_name ) is not _NOT_SPECIFIED : <EOL> raise ValueError ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % ( positive . cli_name , negative . cli_name ) ) <EOL> class PositiveBooleanArgument ( arguments . CLIArgument ) : <EOL> def __init__ ( self , name , argument_model , operation_model , <EOL> event_emitter , serialized_name , group_name ) : <EOL> super ( PositiveBooleanArgument , self ) . __init__ ( <EOL> name , argument_model , operation_model , event_emitter , <EOL> serialized_name = serialized_name ) <EOL> self . _group_name = group_name <EOL> @ property <EOL> def group_name ( self ) : <EOL> return self . _group_name <EOL> def add_to_parser ( self , parser ) : <EOL> parser . add_argument ( self . cli_name , <EOL> help = self . documentation , <EOL> action = '<STR_LIT:store>' , <EOL> default = _NOT_SPECIFIED , <EOL> nargs = '<STR_LIT:?>' ) <EOL> def add_to_params ( self , parameters , value ) : <EOL> if value is _NOT_SPECIFIED : <EOL> return <EOL> elif value is None : <EOL> parameters [ self . _serialized_name ] = { '<STR_LIT>' : True } <EOL> else : <EOL> parameters [ self . _serialized_name ] = self . _unpack_argument ( <EOL> value ) <EOL> class NegativeBooleanParameter ( arguments . BooleanArgument ) : <EOL> def __init__ ( self , name , argument_model , operation_model , <EOL> event_emitter , serialized_name , action = '<STR_LIT:store_true>' , <EOL> dest = None , group_name = None ) : <EOL> super ( NegativeBooleanParameter , self ) . __init__ ( <EOL> name , argument_model , operation_model , event_emitter , <EOL> default = _NOT_SPECIFIED , serialized_name = serialized_name ) <EOL> self . _group_name = group_name <EOL> def add_to_params ( self , parameters , value ) : <EOL> if value is not _NOT_SPECIFIED and value : <EOL> parameters [ self . _serialized_name ] = { '<STR_LIT>' : False } </s>
