#NEWLINE# def to_etree( self , data , options = None , name = None , depth = 0 ) : #NEWLINE# #INDENT# '\n        Given some data, converts that data to an ``etree.Element`` suitable\n        for use in the XML output.\n        ' #NEWLINE# if isinstance ( data , ( list , tuple ) ) : #NEWLINE# #INDENT# element = Element ( ( name or 'objects' ) ) #NEWLINE# if name : #NEWLINE# #INDENT# element = Element ( name ) #NEWLINE# element . set ( 'type' , 'list' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# element = Element ( 'objects' ) #NEWLINE# #UNINDENT# for item in data : #NEWLINE# #INDENT# element . append ( self . to_etree ( item , options , depth = ( depth + 1 ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( data , dict ) : #NEWLINE# #INDENT# if ( depth == 0 ) : #NEWLINE# #INDENT# element = Element ( ( name or 'response' ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# element = Element ( ( name or 'object' ) ) #NEWLINE# element . set ( 'type' , 'hash' ) #NEWLINE# #UNINDENT# for ( key , value ) in data . iteritems ( ) : #NEWLINE# #INDENT# element . append ( self . to_etree ( value , options , name = key , depth = ( depth + 1 ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( data , Bundle ) : #NEWLINE# #INDENT# element = Element ( ( name or 'object' ) ) #NEWLINE# for ( field_name , field_object ) in data . data . items ( ) : #NEWLINE# #INDENT# element . append ( self . to_etree ( field_object , options , name = field_name , depth = ( depth + 1 ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if hasattr ( data , 'dehydrated_type' ) : #NEWLINE# #INDENT# if ( ( getattr ( data , 'dehydrated_type' , None ) == 'related' ) and ( data . is_m2m == False ) ) : #NEWLINE# #INDENT# if data . full : #NEWLINE# #INDENT# return self . to_etree ( data . fk_resource , options , name , ( depth + 1 ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return self . to_etree ( data . value , options , name , ( depth + 1 ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( getattr ( data , 'dehydrated_type' , None ) == 'related' ) and ( data . is_m2m == True ) ) : #NEWLINE# #INDENT# if data . full : #NEWLINE# #INDENT# element = Element ( ( name or 'objects' ) ) #NEWLINE# for bundle in data . m2m_bundles : #NEWLINE# #INDENT# element . append ( self . to_etree ( bundle , options , bundle . resource_name , ( depth + 1 ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# element = Element ( ( name or 'objects' ) ) #NEWLINE# for value in data . value : #NEWLINE# #INDENT# element . append ( self . to_etree ( value , options , name , depth = ( depth + 1 ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# return self . to_etree ( data . value , options , name ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# element = Element ( ( name or 'value' ) ) #NEWLINE# simple_data = self . to_simple ( data , options ) #NEWLINE# data_type = get_type_string ( simple_data ) #NEWLINE# if ( data_type != 'string' ) : #NEWLINE# #INDENT# element . set ( 'type' , get_type_string ( simple_data ) ) #NEWLINE# #UNINDENT# if ( data_type != 'null' ) : #NEWLINE# #INDENT# if isinstance ( simple_data , unicode ) : #NEWLINE# #INDENT# element . text = simple_data #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# element . text = force_unicode ( simple_data ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# return element