#NEWLINE# def _replace_output( data , **output_mapping ) : #NEWLINE# #INDENT# "Helper to replace output data.\n\n    Example:\n       data = {'a': 'hello'}\n       output_mapping = {'a': 'b'}\n       returns: {'b': 'hello'}\n\n       data = {'a': {'b': 'hello'}}\n       output_mapping =  {'a': 'b'}\n       returns: {'b': {'b': 'hello'}}\n\n       data = {'a': {'b': 'hello'}}\n       output_mapping =  {'a': {'b': 'c'}}\n       returns: {'a': {'c': 'hello'}}\n\n       data = [{'a': 'hello'}, {'a': 'hi'}]\n       output_mapping = {'a': 'b'}\n       returns: [{'b': 'hello'}, {'b': 'hi'}]\n    " #NEWLINE# if isinstance ( data , list ) : #NEWLINE# #INDENT# return [ _replace_output ( item , ** output_mapping ) for item in data ] #NEWLINE# #UNINDENT# if ( not isinstance ( data , dict ) ) : #NEWLINE# #INDENT# raise exception . InvalidResponse ( ( '%s type is not dict' % data ) ) #NEWLINE# #UNINDENT# info = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for ( key , value ) in data . items ( ) : #NEWLINE# #INDENT# if ( key in output_mapping ) : #NEWLINE# #INDENT# output_key = output_mapping [ key ] #NEWLINE# if isinstance ( output_key , basestring ) : #NEWLINE# #INDENT# info [ output_key ] = value #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# info [ key ] = _replace_output ( value , ** output_key ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# info [ key ] = value #NEWLINE# #UNINDENT# #UNINDENT# return info