#NEWLINE# def resources_as_xml( self , resources , sitemapindex = False , fh = None ) : #NEWLINE# #INDENT# 'Write or return XML for a set of resources in sitemap format\n        \n        Arguments:\n        - resources - either an iterable or iterator of Resource objects;\n                      if there an md attribute this will go to <rs:md>\n                      if there an ln attribute this will go to <rs:ln>\n        - sitemapindex - set True to write sitemapindex instead of sitemap\n        - fh - write to filehandle fh instead of returning string\n        ' #NEWLINE# root_element = ( 'sitemapindex' if sitemapindex else 'urlset' ) #NEWLINE# item_element = ( 'sitemap' if sitemapindex else 'url' ) #NEWLINE# namespaces = { #NEWLINE# #INDENT# 'xmlns' : SITEMAP_NS , #NEWLINE# 'xmlns:rs' : RS_NS , #NEWLINE# #UNINDENT# } #NEWLINE# root = Element ( root_element , namespaces ) #NEWLINE# if self . pretty_xml : #NEWLINE# #INDENT# root . text = '\n' #NEWLINE# #UNINDENT# if hasattr ( resources , 'ln' ) : #NEWLINE# #INDENT# for ln in resources . ln : #NEWLINE# #INDENT# self . add_element_with_atts_to_etree ( root , 'rs:ln' , ln ) #NEWLINE# #UNINDENT# #UNINDENT# if hasattr ( item_element , 'md' ) : #NEWLINE# #INDENT# self . add_element_with_atts_to_etree ( root , 'rs:md' , resources . md ) #NEWLINE# #UNINDENT# for r in resources : #NEWLINE# #INDENT# e = self . resource_etree_element ( r , element_name = item_element ) #NEWLINE# root . append ( e ) #NEWLINE# #UNINDENT# tree = ElementTree ( root ) #NEWLINE# xml_buf = None #NEWLINE# if ( fh is None ) : #NEWLINE# #INDENT# xml_buf = io . StringIO ( ) #NEWLINE# fh = xml_buf #NEWLINE# #UNINDENT# if ( sys . version_info < ( 2 , 7 ) ) : #NEWLINE# #INDENT# tree . write ( fh , encoding = 'UTF-8' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( sys . version_info < ( 3 , 0 ) ) : #NEWLINE# #INDENT# tree . write ( fh , encoding = 'UTF-8' , xml_declaration = True , method = 'xml' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# tree . write ( fh , encoding = 'unicode' , xml_declaration = True , method = 'xml' ) #NEWLINE# #UNINDENT# #UNINDENT# if ( xml_buf is not None ) : #NEWLINE# #INDENT# return xml_buf . getvalue ( )