#NEWLINE# def _ConstructContentList( xml_parts , specification , pretty , level = 0 ) : #NEWLINE# #INDENT# ' Appends the XML parts corresponding to the specification.\n\n  Args:\n    xml_parts: A list of XML parts to be appended to.\n    specification:  The specification of the element.  See EasyXml docs.\n    pretty: True if we want pretty printing with indents and new lines.\n    level: Indentation level.\n  ' #NEWLINE# if pretty : #NEWLINE# #INDENT# indentation = ( '  ' * level ) #NEWLINE# new_line = '\n' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# indentation = '' #NEWLINE# new_line = '' #NEWLINE# #UNINDENT# name = specification [ 0 ] #NEWLINE# if ( not isinstance ( name , str ) ) : #NEWLINE# #INDENT# raise Exception ( ( 'The first item of an EasyXml specification should be a string.  Specification was ' + str ( specification ) ) ) #NEWLINE# #UNINDENT# xml_parts . append ( ( ( indentation + '<' ) + name ) ) #NEWLINE# rest = specification [ 1 : ] #NEWLINE# if ( rest and isinstance ( rest [ 0 ] , dict ) ) : #NEWLINE# #INDENT# for ( at , val ) in sorted ( rest [ 0 ] . iteritems ( ) ) : #NEWLINE# #INDENT# xml_parts . append ( ( ' %s="%s"' % ( at , _XmlEscape ( val , attr = True ) ) ) ) #NEWLINE# #UNINDENT# rest = multi_line [ 1 : ] #NEWLINE# #UNINDENT# if rest : #NEWLINE# #INDENT# xml_parts . append ( '>' ) #NEWLINE# all_strings = reduce ( ( lambda x , y : ( x and isinstance ( y , str ) ) ) , rest , True ) #NEWLINE# multi_line = ( not all_strings ) #NEWLINE# if ( multi_line and new_line ) : #NEWLINE# #INDENT# xml_parts . append ( new_line ) #NEWLINE# #UNINDENT# for child_spec in rest : #NEWLINE# #INDENT# if isinstance ( child_spec , str ) : #NEWLINE# #INDENT# xml_parts . append ( _XmlEscape ( child_spec ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# _ConstructContentList ( xml_parts , child_spec , pretty , ( level + 1 ) ) #NEWLINE# #UNINDENT# #UNINDENT# if ( multi_line and indentation ) : #NEWLINE# #INDENT# xml_parts . append ( indentation ) #NEWLINE# #UNINDENT# xml_parts . append ( ( '</%s>%s' % ( name , new_line ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# xml_parts . append ( ( '/>%s' % new_line ) )