#NEWLINE# def resource_from_etree( self , etree , resource_class ) : #NEWLINE# #INDENT# 'Construct a Resource from an etree\n\n        Parameters:\n         etree - the etree to parse\n         resource_class - class of Resource object to create\n\n        The parsing is properly namespace aware but we search just \n        for the elements wanted and leave everything else alone. Will \n        raise an error if there are multiple <loc> or multiple <lastmod>\n        elements. Otherwise, provided there is a <loc> element then will \n        go ahead and extract as much as possible.\n\n        All errors raised are SitemapParseError with messages intended\n        to help debug problematic sitemap XML.\n        ' #NEWLINE# loc_elements = etree . findall ( ( ( '{' + SITEMAP_NS ) + '}loc' ) ) #NEWLINE# if ( len ( loc_elements ) > 1 ) : #NEWLINE# #INDENT# raise SitemapParseError ( 'Multiple <loc> elements while parsing <url> in sitemap' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( len ( loc_elements ) == 0 ) : #NEWLINE# #INDENT# raise SitemapParseError ( 'Missing <loc> element while parsing <url> in sitemap' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# loc = loc_elements [ 0 ] . text #NEWLINE# #UNINDENT# #UNINDENT# if ( ( loc is None ) or ( loc == '' ) ) : #NEWLINE# #INDENT# raise SitemapParseError ( 'Bad <loc> element with no content while parsing <url> in sitemap' ) #NEWLINE# #UNINDENT# resource = resource_class ( uri = loc ) #NEWLINE# lastmod_elements = etree . findall ( ( ( '{' + SITEMAP_NS ) + '}lastmod' ) ) #NEWLINE# if ( len ( lastmod_elements ) > 1 ) : #NEWLINE# #INDENT# raise SitemapParseError ( 'Multiple <lastmod> elements while parsing <url> in sitemap' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( len ( lastmod_elements ) == 1 ) : #NEWLINE# #INDENT# resource . lastmod = lastmod_elements [ 0 ] . text #NEWLINE# #UNINDENT# #UNINDENT# md_elements = etree . findall ( ( ( '{' + RS_NS ) + '}md' ) ) #NEWLINE# if ( len ( md_elements ) > 1 ) : #NEWLINE# #INDENT# raise SitemapParseError ( 'Found multiple (%d) <rs:md> elements for %s' , ( len ( md_elements ) , loc ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( len ( md_elements ) == 1 ) : #NEWLINE# #INDENT# md = self . md_from_etree ( md_elements [ 0 ] , context = loc ) #NEWLINE# for att in ( 'capability' , 'change' , 'length' , 'path' , 'mime_type' ) : #NEWLINE# #INDENT# if ( att in md ) : #NEWLINE# #INDENT# setattr ( resource , att , md [ att ] ) #NEWLINE# #UNINDENT# #UNINDENT# if ( 'hash' in md ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# resource . hash = md [ 'hash' ] #NEWLINE# #UNINDENT# except ValueError as e : #NEWLINE# #INDENT# self . logger . warning ( ( '%s in <rs:md> for %s' % ( str ( e ) , loc ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# ln_elements = etree . findall ( ( ( '{' + RS_NS ) + '}ln' ) ) #NEWLINE# if ( len ( ln_elements ) > 0 ) : #NEWLINE# #INDENT# resource . ln = [ ] #NEWLINE# for ln_element in ln_elements : #NEWLINE# #INDENT# resource . ln . append ( self . ln_from_etree ( ln_element , loc ) ) #NEWLINE# #UNINDENT# #UNINDENT# return resource