parameters: (self, config_file)
docstring: Read and parse a configuration file.
docstring_summary: Read and parse a configuration file.
docstring_tokens: Read and parse a configuration file .
function: def __init__(self, config_file):
          """ Read and parse a configuration file. """
  
          self._config = {}
          self._extrapolating = []
  
          cfg = open(config_file)
          line_nr = 0
          last_name = None
  
          section = ''
          section_config = {}
          self._config[section] = section_config
  
          for l in cfg:
              line_nr += 1
  
              # Strip comments.
              l = l.split('#')[0]
  
              # See if this might be part of a multi-line.
              multiline = (last_name is not None and len(l) != 0 and l[0] == ' ')
  
              l = l.strip()
  
              if l == '':
                  last_name = None
                  continue
  
              # See if this is a new section.
              if l[0] == '[' and l[-1] == ']':
                  section = l[1:-1].strip()
                  if section == '':
                      error(
                              "%s:%d: Empty section name." % (
                                      config_file, line_nr))
  
                  if section in self._config:
                      error(
                              "%s:%d: Section '%s' defined more than once." % (
                                      config_file, line_nr, section))
  
                  section_config = {}
                  self._config[section] = section_config
  
                  last_name = None
                  continue
  
              parts = l.split('=', 1)
              if len(parts) == 2:
                  name = parts[0].strip()
                  value = parts[1].strip()
              elif multiline:
                  name = last_name
                  value = section_config[last_name]
                  value += ' ' + l
              else:
                  name = value = ''
  
              if name == '' or value == '':
                  error("%s:%d: Invalid line." % (config_file, line_nr))
  
              section_config[name] = value
              last_name = name
  
          cfg.close()
function_tokens: def __init__ ( self , config_file ) : self . _config = { } self . _extrapolating = [ ] cfg = open ( config_file ) line_nr = 0 last_name = None section = '' section_config = { } self . _config [ section ] = section_config for l in cfg : line_nr += 1 # Strip comments. l = l . split ( '#' ) [ 0 ] # See if this might be part of a multi-line. multiline = ( last_name is not None and len ( l ) != 0 and l [ 0 ] == ' ' ) l = l . strip ( ) if l == '' : last_name = None continue # See if this is a new section. if l [ 0 ] == '[' and l [ - 1 ] == ']' : section = l [ 1 : - 1 ] . strip ( ) if section == '' : error ( "%s:%d: Empty section name." % ( config_file , line_nr ) ) if section in self . _config : error ( "%s:%d: Section '%s' defined more than once." % ( config_file , line_nr , section ) ) section_config = { } self . _config [ section ] = section_config last_name = None continue parts = l . split ( '=' , 1 ) if len ( parts ) == 2 : name = parts [ 0 ] . strip ( ) value = parts [ 1 ] . strip ( ) elif multiline : name = last_name value = section_config [ last_name ] value += ' ' + l else : name = value = '' if name == '' or value == '' : error ( "%s:%d: Invalid line." % ( config_file , line_nr ) ) section_config [ name ] = value last_name = name cfg . close ( )