<s> '''<STR_LIT>''' <EOL> __docformat__ = '<STR_LIT>' <EOL> __version__ = '<STR_LIT>' <EOL> import urlparse <EOL> import urllib2 <EOL> import os . path <EOL> import warnings <EOL> def create_locator ( address ) : <EOL> '''<STR_LIT>''' <EOL> url = urlparse . urlparse ( address ) <EOL> if not url [ <NUM_LIT:0> ] : <EOL> return LocalFileLocator ( address ) <EOL> else : <EOL> return URLLocator ( address ) <EOL> class Locator ( object ) : <EOL> '''<STR_LIT>''' <EOL> def get_stream ( self , uri ) : <EOL> '''<STR_LIT>''' <EOL> return None <EOL> def get_default_stream ( self ) : <EOL> '''<STR_LIT>''' <EOL> return None <EOL> class LocalFileLocator ( Locator ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , uri = '<STR_LIT>' ) : <EOL> self . uri = uri <EOL> self . base = os . path . split ( uri ) [ <NUM_LIT:0> ] <EOL> def get_stream ( self , uri ) : <EOL> if not os . path . isabs ( uri ) : <EOL> uri = os . path . join ( self . base , uri ) <EOL> try : <EOL> return open ( uri , '<STR_LIT:rb>' ) <EOL> except IOError : <EOL> warnings . warn ( '<STR_LIT>' % uri ) <EOL> return None <EOL> def get_default_stream ( self ) : <EOL> try : <EOL> return open ( self . uri , '<STR_LIT:rb>' ) <EOL> except IOError : <EOL> warnings . warn ( '<STR_LIT>' % self . uri ) <EOL> return None <EOL> class URLLocator ( Locator ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , base = '<STR_LIT>' ) : <EOL> self . base = base <EOL> def get_stream ( self , uri ) : <EOL> uri = urlparse . urljoin ( self . base , uri ) <EOL> try : <EOL> return urllib2 . urlopen ( uri ) <EOL> except IOError : <EOL> warnings . warn ( '<STR_LIT>' % uri ) <EOL> return None <EOL> def get_default_stream ( self ) : <EOL> return self . get_stream ( self . base ) </s>
