parameters: (source, base = "")
return_statement: return source
docstring: This function takes an InputSource and an optional base URL and
      returns a fully resolved InputSource object ready for reading.
docstring_summary: This function takes an InputSource and an optional base URL and
      returns a fully resolved InputSource object ready for reading.
docstring_tokens: This function takes an InputSource and an optional base URL and returns a fully resolved InputSource object ready for reading .
function: def prepare_input_source(source, base = ""):
      """This function takes an InputSource and an optional base URL and
      returns a fully resolved InputSource object ready for reading."""
  
      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:
          try:
              sysid = source.getSystemId()
              basehead = os.path.dirname(os.path.normpath(base))
              encoding = sys.getfilesystemencoding()
              if isinstance(sysid, unicode):
                  if not isinstance(basehead, unicode):
                      try:
                          basehead = basehead.decode(encoding)
                      except UnicodeDecodeError:
                          sysid = sysid.encode(encoding)
              else:
                  if isinstance(basehead, unicode):
                      try:
                          sysid = sysid.decode(encoding)
                      except UnicodeDecodeError:
                          basehead = basehead.encode(encoding)
              sysidfilename = os.path.join(basehead, sysid)
              isfile = os.path.isfile(sysidfilename)
          except UnicodeError:
              isfile = False
          if isfile:
              source.setSystemId(sysidfilename)
              f = open(sysidfilename, "rb")
          else:
              source.setSystemId(urlparse.urljoin(base, source.getSystemId()))
              f = urllib.urlopen(source.getSystemId())
  
          source.setByteStream(f)
  
      return source
function_tokens: 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 : try : sysid = source . getSystemId ( ) basehead = os . path . dirname ( os . path . normpath ( base ) ) encoding = sys . getfilesystemencoding ( ) if isinstance ( sysid , unicode ) : if not isinstance ( basehead , unicode ) : try : basehead = basehead . decode ( encoding ) except UnicodeDecodeError : sysid = sysid . encode ( encoding ) else : if isinstance ( basehead , unicode ) : try : sysid = sysid . decode ( encoding ) except UnicodeDecodeError : basehead = basehead . encode ( encoding ) sysidfilename = os . path . join ( basehead , sysid ) isfile = os . path . isfile ( sysidfilename ) except UnicodeError : isfile = False if isfile : source . setSystemId ( sysidfilename ) f = open ( sysidfilename , "rb" ) else : source . setSystemId ( urlparse . urljoin ( base , source . getSystemId ( ) ) ) f = urllib . urlopen ( source . getSystemId ( ) ) source . setByteStream ( f ) return source