def prepare_input_source(source, base=''):
 if (type(source) in _StringTypes):
  source = xmlreader.InputSource(source)
 elif hasattr(source, 'read'):
  f = source
  source = xmlreader.InputSource()
  source.setByteStream(f)
  if hasattr(f, 'name'):
   source.setSystemId(f.name)
 if (source.getByteStream() is None):
  sysid = source.getSystemId()
  basehead = os.path.dirname(os.path.normpath(base))
  sysidfilename = os.path.join(basehead, sysid)
  if os.path.isfile(sysidfilename):
   source.setSystemId(sysidfilename)
   f = open(sysidfilename, 'rb')
  else:
   source.setSystemId(urlparse.urljoin(base, sysid))
   f = urllib.urlopen(source.getSystemId())
  source.setByteStream(f)
 return source

def prepare_input_source ( source , base = '' ) : if ( type ( source ) in _StringTypes ) : source = xmlreader . InputSource ( source ) elif hasattr ( source , 'read' ) : f = source source = xmlreader . InputSource ( ) source . setByteStream ( f ) if hasattr ( f , 'name' ) : source . setSystemId ( f . name ) if ( source . getByteStream ( ) is None ) : sysid = source . getSystemId ( ) basehead = os . path . dirname ( os . path . normpath ( base ) ) sysidfilename = os . path . join ( basehead , sysid ) if os . path . isfile ( sysidfilename ) : source . setSystemId ( sysidfilename ) f = open ( sysidfilename , 'rb' ) else : source . setSystemId ( urlparse . urljoin ( base , sysid ) ) f = urllib . urlopen ( source . getSystemId ( ) ) source . setByteStream ( f ) return source
this function takes an inputsource and an optional base url and returns a fully resolved inputsource object ready for reading .