<s> """<STR_LIT>""" <EOL> from lxml import etree <EOL> from oslo_config import cfg <EOL> from oslo_log import log as logging <EOL> import six <EOL> from ec2api . api import cloud <EOL> from ec2api . api import ec2utils <EOL> from ec2api import exception <EOL> from ec2api . i18n import _ <EOL> CONF = cfg . CONF <EOL> LOG = logging . getLogger ( __name__ ) <EOL> def _underscore_to_camelcase ( st ) : <EOL> return '<STR_LIT>' . join ( [ x [ : <NUM_LIT:1> ] . upper ( ) + x [ <NUM_LIT:1> : ] for x in st . split ( '<STR_LIT:_>' ) ] ) <EOL> def _database_to_isoformat ( datetimeobj ) : <EOL> """<STR_LIT>""" <EOL> return datetimeobj . strftime ( "<STR_LIT>" ) [ : - <NUM_LIT:3> ] + '<STR_LIT>' <EOL> class APIRequest ( object ) : <EOL> def __init__ ( self , action , version , args ) : <EOL> self . action = action <EOL> self . version = version <EOL> self . args = args <EOL> if CONF . full_vpc_support : <EOL> self . controller = cloud . VpcCloudController ( ) <EOL> else : <EOL> self . controller = cloud . CloudController ( ) <EOL> def invoke ( self , context ) : <EOL> try : <EOL> method = getattr ( self . controller , <EOL> ec2utils . camelcase_to_underscore ( self . action ) ) <EOL> except AttributeError : <EOL> LOG . exception ( _ ( '<STR_LIT>' ) , <EOL> { '<STR_LIT:action>' : self . action } ) <EOL> raise exception . InvalidRequest ( ) <EOL> args = ec2utils . dict_from_dotted_str ( self . args . items ( ) ) <EOL> def convert_dicts_to_lists ( args ) : <EOL> if not isinstance ( args , dict ) : <EOL> return args <EOL> for key in args . keys ( ) : <EOL> if isinstance ( args [ key ] , dict ) : <EOL> if args [ key ] == { } : <EOL> continue <EOL> first_subkey = next ( six . iterkeys ( args [ key ] ) ) <EOL> if first_subkey . isdigit ( ) : <EOL> s = args [ key ] <EOL> args [ key ] = [ convert_dicts_to_lists ( s [ k ] ) <EOL> for k in sorted ( s ) ] <EOL> elif ( first_subkey == '<STR_LIT:value>' and <EOL> len ( args [ key ] ) == <NUM_LIT:1> ) : <EOL> args [ key ] = args [ key ] [ '<STR_LIT:value>' ] <EOL> return args <EOL> args = convert_dicts_to_lists ( args ) <EOL> result = method ( context , ** args ) <EOL> return self . _render_response ( result , context . request_id ) <EOL> def _render_response ( self , response_data , request_id ) : <EOL> response_el = ec2utils . dict_to_xml ( <EOL> { '<STR_LIT>' : '<STR_LIT:true>' } if response_data is True else response_data , <EOL> self . action + '<STR_LIT>' ) <EOL> response_el . attrib [ '<STR_LIT>' ] = ( '<STR_LIT>' <EOL> % self . version ) <EOL> request_id_el = etree . Element ( '<STR_LIT>' ) <EOL> request_id_el . text = request_id <EOL> response_el . insert ( <NUM_LIT:0> , request_id_el ) <EOL> response = etree . tostring ( response_el , pretty_print = True ) <EOL> if self . action != "<STR_LIT>" : <EOL> LOG . debug ( response ) <EOL> else : <EOL> LOG . debug ( "<STR_LIT>" ) <EOL> return response </s>
