#NEWLINE# def _serialize( self , parent , obj , siblings , nsmap = None ) : #NEWLINE# #INDENT# 'Internal serialization.\n\n        Recursive routine to build a tree of etree.Element instances\n        from an object based on the template.  Returns the first\n        etree.Element instance rendered, or None.\n\n        :param parent: The parent etree.Element instance.  Can be\n                       None.\n        :param obj: The object to render.\n        :param siblings: The TemplateElement instances against which\n                         to render the object.\n        :param nsmap: An optional namespace dictionary to be\n                      associated with the etree.Element instance\n                      rendered.\n        ' #NEWLINE# elems = siblings [ 0 ] . render ( parent , obj , siblings [ 1 : ] , nsmap ) #NEWLINE# seen = set ( ) #NEWLINE# for ( idx , sibling ) in enumerate ( siblings ) : #NEWLINE# #INDENT# for child in sibling : #NEWLINE# #INDENT# if ( child . tag in seen ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# seen . add ( child . tag ) #NEWLINE# nieces = [ child ] #NEWLINE# for sib in siblings [ ( idx + 1 ) : ] : #NEWLINE# #INDENT# if ( child . tag in sib ) : #NEWLINE# #INDENT# nieces . append ( sib [ child . tag ] ) #NEWLINE# #UNINDENT# #UNINDENT# for ( elem , datum ) in elems : #NEWLINE# #INDENT# self . _serialize ( elem , datum , nieces ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if elems : #NEWLINE# #INDENT# return elems [ 0 ] [ 0 ]