#NEWLINE# def create_POM( data , dtd ) : #NEWLINE# #INDENT# 'Given a python object, produce reasonable markup from that. Return\n    a valid POM node.\n\n    Dictionaries produce sections (divs) where key names are the class\n    attribute name; lists produce ordered lists; Sets produce unordered\n    lists; Tuples produce a fragment collection (invisible), an\n    ElementNode is taken as-is, and strings return as Text nodes.\n    Callables are called with the DTD, and the return value checked.\n    ' #NEWLINE# if ( data is None ) : #NEWLINE# #INDENT# return NBSP #NEWLINE# #UNINDENT# it = type ( data ) #NEWLINE# if ( it is dict ) : #NEWLINE# #INDENT# creator = FlowCreator ( dtd ) #NEWLINE# outer = POM . Fragments ( ) #NEWLINE# for ( name , content ) in data . iteritems ( ) : #NEWLINE# #INDENT# div = creator . get_section ( name ) #NEWLINE# div . append ( create_POM ( content , dtd ) ) #NEWLINE# outer . append ( div ) #NEWLINE# #UNINDENT# return outer #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( it is list ) : #NEWLINE# #INDENT# creator = FlowCreator ( dtd ) #NEWLINE# ol = creator . get_ordered_list ( ) #NEWLINE# for item in data : #NEWLINE# #INDENT# ol . add_item ( item ) #NEWLINE# #UNINDENT# return ol #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( it is set ) : #NEWLINE# #INDENT# creator = FlowCreator ( dtd ) #NEWLINE# ul = creator . get_unordered_list ( ) #NEWLINE# for item in data : #NEWLINE# #INDENT# ul . add_item ( item ) #NEWLINE# #UNINDENT# return ul #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( it is tuple ) : #NEWLINE# #INDENT# frags = POM . Fragments ( ) #NEWLINE# for item in data : #NEWLINE# #INDENT# frags . append ( create_POM ( item , dtd ) ) #NEWLINE# #UNINDENT# return frags #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( it is unicode ) : #NEWLINE# #INDENT# return POM . Text ( data ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( data , POM . ElementNode ) : #NEWLINE# #INDENT# return data #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( it is FunctionType ) : #NEWLINE# #INDENT# return check_object ( data ( dtd ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return POM . Text ( data )