<s> """<STR_LIT>""" <EOL> import collections <EOL> import os <EOL> from datetime import datetime <EOL> import re <EOL> import sys <EOL> try : <EOL> import StringIO as io <EOL> except ImportError : <EOL> import io <EOL> import logging <EOL> try : <EOL> from urllib . request import URLopener <EOL> except ImportError : <EOL> from urllib import URLopener <EOL> from . resource_container import ResourceContainer <EOL> from . sitemap import Sitemap <EOL> class ListBase ( ResourceContainer ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , resources = None , count = None , md = None , ln = None , uri = None , <EOL> capability_name = '<STR_LIT>' ) : <EOL> super ( ListBase , self ) . __init__ ( resources = resources , md = md , ln = ln , uri = uri , <EOL> capability_name = capability_name ) <EOL> self . count = count <EOL> self . sitemapindex = False <EOL> self . pretty_xml = False <EOL> self . logger = logging . getLogger ( '<STR_LIT>' ) <EOL> self . bytes_read = <NUM_LIT:0> <EOL> self . parsed_index = None <EOL> def __iter__ ( self ) : <EOL> """<STR_LIT>""" <EOL> return ( iter ( self . resources ) ) <EOL> def __len__ ( self ) : <EOL> """<STR_LIT>""" <EOL> if ( self . count is not None ) : <EOL> return ( self . count ) <EOL> return ( len ( self . resources ) ) <EOL> def read ( self , uri = None ) : <EOL> """<STR_LIT>""" <EOL> self . parse ( uri = uri ) <EOL> def parse ( self , uri = None , fh = None , str_data = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if ( uri is not None ) : <EOL> try : <EOL> fh = URLopener ( ) . open ( uri ) <EOL> except IOError as e : <EOL> raise Exception ( "<STR_LIT>" % ( uri , str ( e ) ) ) <EOL> elif ( str_data is not None ) : <EOL> fh = io . StringIO ( str_data ) <EOL> elif ( '<STR_LIT:str>' in kwargs ) : <EOL> self . logger . warn ( "<STR_LIT>" ) <EOL> fh = io . StringIO ( kwargs [ '<STR_LIT:str>' ] ) <EOL> if ( fh is None ) : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> s = self . new_sitemap ( ) <EOL> s . parse_xml ( fh = fh , resources = self , capability = self . capability_name , sitemapindex = False ) <EOL> self . parsed_index = s . parsed_index <EOL> def as_xml ( self ) : <EOL> """<STR_LIT>""" <EOL> self . default_capability ( ) <EOL> s = self . new_sitemap ( ) <EOL> return s . resources_as_xml ( self , sitemapindex = self . sitemapindex ) <EOL> def write ( self , basename = "<STR_LIT>" ) : <EOL> """<STR_LIT>""" <EOL> self . default_capability ( ) <EOL> fh = open ( basename , '<STR_LIT:wb>' ) <EOL> s = self . new_sitemap ( ) <EOL> s . resources_as_xml ( self , fh = fh , sitemapindex = self . sitemapindex ) <EOL> fh . close ( ) <EOL> def new_sitemap ( self ) : <EOL> """<STR_LIT>""" <EOL> return Sitemap ( pretty_xml = self . pretty_xml ) </s>
