<s> """<STR_LIT>""" <EOL> from xml . sax . saxutils import XMLGenerator <EOL> __all__ = ( '<STR_LIT>' , ) <EOL> class SimpleXMLGenerator ( XMLGenerator ) : <EOL> """<STR_LIT>""" <EOL> root_name = '<STR_LIT:root>' <EOL> item_tag_name = '<STR_LIT>' <EOL> def __init__ ( self , stream , encoding = '<STR_LIT:utf-8>' ) : <EOL> super ( SimpleXMLGenerator , self ) . __init__ ( stream , encoding = encoding ) <EOL> def parse ( self , data ) : <EOL> """<STR_LIT>""" <EOL> self . startDocument ( ) <EOL> self . startElement ( self . root_name , { } ) <EOL> self . to_xml ( self , data ) <EOL> self . endElement ( self . root_name ) <EOL> self . endDocument ( ) <EOL> def to_str ( self , value ) : <EOL> """<STR_LIT>""" <EOL> return str ( value ) . encode ( self . _encoding ) <EOL> def to_xml ( self , xml , data ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( data , ( list , tuple ) ) : <EOL> for item in data : <EOL> self . startElement ( self . item_tag_name , { } ) <EOL> self . to_xml ( xml , item ) <EOL> self . endElement ( self . item_tag_name ) <EOL> elif isinstance ( data , dict ) : <EOL> for key , value in data . items ( ) : <EOL> xml . startElement ( key , { } ) <EOL> self . to_xml ( xml , value ) <EOL> xml . endElement ( key ) <EOL> elif data is None : <EOL> pass <EOL> else : <EOL> xml . characters ( self . to_str ( data ) ) </s>
