parameters: (self, infile=None, options=None, **kwargs)
docstring: Parse or create a config file object.
          
          ``ConfigObj(infile=None, options=None, **kwargs)``
docstring_summary: Parse or create a config file object.
          
          ``ConfigObj(infile=None, options=None, **kwargs)``
docstring_tokens: Parse or create a config file object . ConfigObj ( infile = None options = None ** kwargs )
function: def __init__(self, infile=None, options=None, **kwargs):
          """
          Parse or create a config file object.
          
          ``ConfigObj(infile=None, options=None, **kwargs)``
          """
          if infile is None:
              infile = []
          if options is None:
              options = {}
          else:
              options = dict(options)
          # keyword arguments take precedence over an options dictionary
          options.update(kwargs)
          # init the superclass
          Section.__init__(self, self, 0, self)
          #
          defaults = OPTION_DEFAULTS.copy()
          for entry in options.keys():
              if entry not in defaults.keys():
                  raise TypeError, 'Unrecognised option "%s".' % entry
          # TODO: check the values too.
          #
          # Add any explicit options to the defaults
          defaults.update(options)
          #
          # initialise a few variables
          self.filename = None
          self._errors = []
          self.raise_errors = defaults['raise_errors']
          self.interpolation = defaults['interpolation']
          self.list_values = defaults['list_values']
          self.create_empty = defaults['create_empty']
          self.file_error = defaults['file_error']
          self.stringify = defaults['stringify']
          self.indent_type = defaults['indent_type']
          self.encoding = defaults['encoding']
          self.default_encoding = defaults['default_encoding']
          self.BOM = False
          self.newlines = None
          self.write_empty_values = defaults['write_empty_values']
          self.unrepr = defaults['unrepr']
          #
          self.initial_comment = []
          self.final_comment = []
          #
          self._terminated = False
          #
          if isinstance(infile, StringTypes):
              self.filename = infile
              if os.path.isfile(infile):
                  infile = open(infile).read() or []
              elif self.file_error:
                  # raise an error if the file doesn't exist
                  raise IOError, 'Config file not found: "%s".' % self.filename
              else:
                  # file doesn't already exist
                  if self.create_empty:
                      # this is a good test that the filename specified
                      # isn't impossible - like on a non existent device
                      h = open(infile, 'w')
                      h.write('')
                      h.close()
                  infile = []
          elif isinstance(infile, (list, tuple)):
              infile = list(infile)
          elif isinstance(infile, dict):
              # initialise self
              # the Section class handles creating subsections
              if isinstance(infile, ConfigObj):
                  # get a copy of our ConfigObj
                  infile = infile.dict()
              for entry in infile:
                  self[entry] = infile[entry]
              del self._errors
              if defaults['configspec'] is not None:
                  self._handle_configspec(defaults['configspec'])
              else:
                  self.configspec = None
              return
          elif hasattr(infile, 'read'):
              # This supports file like objects
              infile = infile.read() or []
              # needs splitting into lines - but needs doing *after* decoding
              # in case it's not an 8 bit encoding
          else:
              raise TypeError, ('infile must be a filename,'
                  ' file like object, or list of lines.')
          #
          if infile:
              # don't do it for the empty ConfigObj
              infile = self._handle_bom(infile)
              # infile is now *always* a list
              #
              # Set the newlines attribute (first line ending it finds)
              # and strip trailing '\n' or '\r' from lines
              for line in infile:
                  if (not line) or (line[-1] not in ('\r', '\n', '\r\n')):
                      continue
                  for end in ('\r\n', '\n', '\r'):
                      if line.endswith(end):
                          self.newlines = end
                          break
                  break
              if infile[-1] and infile[-1] in ('\r', '\n', '\r\n'):
                  self._terminated = True
              infile = [line.rstrip('\r\n') for line in infile]
          #
          self._parse(infile)
          # if we had any errors, now is the time to raise them
          if self._errors:
              info = "at line %s." % self._errors[0].line_number
              if len(self._errors) > 1:
                  msg = ("Parsing failed with several errors.\nFirst error %s" %
                      info)
                  error = ConfigObjError(msg)
              else:
                  error = self._errors[0]
              # set the errors attribute; it's a list of tuples:
              # (error_type, message, line_number)
              error.errors = self._errors
              # set the config attribute
              error.config = self
              raise error
          # delete private attributes
          del self._errors
          #
          if defaults['configspec'] is None:
              self.configspec = None
          else:
              self._handle_configspec(defaults['configspec'])
function_tokens: def __init__ ( self , infile = None , options = None , * * kwargs ) : if infile is None : infile = [ ] if options is None : options = { } else : options = dict ( options ) # keyword arguments take precedence over an options dictionary options . update ( kwargs ) # init the superclass Section . __init__ ( self , self , 0 , self ) # defaults = OPTION_DEFAULTS . copy ( ) for entry in options . keys ( ) : if entry not in defaults . keys ( ) : raise TypeError , 'Unrecognised option "%s".' % entry # TODO: check the values too. # # Add any explicit options to the defaults defaults . update ( options ) # # initialise a few variables self . filename = None self . _errors = [ ] self . raise_errors = defaults [ 'raise_errors' ] self . interpolation = defaults [ 'interpolation' ] self . list_values = defaults [ 'list_values' ] self . create_empty = defaults [ 'create_empty' ] self . file_error = defaults [ 'file_error' ] self . stringify = defaults [ 'stringify' ] self . indent_type = defaults [ 'indent_type' ] self . encoding = defaults [ 'encoding' ] self . default_encoding = defaults [ 'default_encoding' ] self . BOM = False self . newlines = None self . write_empty_values = defaults [ 'write_empty_values' ] self . unrepr = defaults [ 'unrepr' ] # self . initial_comment = [ ] self . final_comment = [ ] # self . _terminated = False # if isinstance ( infile , StringTypes ) : self . filename = infile if os . path . isfile ( infile ) : infile = open ( infile ) . read ( ) or [ ] elif self . file_error : # raise an error if the file doesn't exist raise IOError , 'Config file not found: "%s".' % self . filename else : # file doesn't already exist if self . create_empty : # this is a good test that the filename specified # isn't impossible - like on a non existent device h = open ( infile , 'w' ) h . write ( '' ) h . close ( ) infile = [ ] elif isinstance ( infile , ( list , tuple ) ) : infile = list ( infile ) elif isinstance ( infile , dict ) : # initialise self # the Section class handles creating subsections if isinstance ( infile , ConfigObj ) : # get a copy of our ConfigObj infile = infile . dict ( ) for entry in infile : self [ entry ] = infile [ entry ] del self . _errors if defaults [ 'configspec' ] is not None : self . _handle_configspec ( defaults [ 'configspec' ] ) else : self . configspec = None return elif hasattr ( infile , 'read' ) : # This supports file like objects infile = infile . read ( ) or [ ] # needs splitting into lines - but needs doing *after* decoding # in case it's not an 8 bit encoding else : raise TypeError , ( 'infile must be a filename,' ' file like object, or list of lines.' ) # if infile : # don't do it for the empty ConfigObj infile = self . _handle_bom ( infile ) # infile is now *always* a list # # Set the newlines attribute (first line ending it finds) # and strip trailing '\n' or '\r' from lines for line in infile : if ( not line ) or ( line [ - 1 ] not in ( '\r' , '\n' , '\r\n' ) ) : continue for end in ( '\r\n' , '\n' , '\r' ) : if line . endswith ( end ) : self . newlines = end break break if infile [ - 1 ] and infile [ - 1 ] in ( '\r' , '\n' , '\r\n' ) : self . _terminated = True infile = [ line . rstrip ( '\r\n' ) for line in infile ] # self . _parse ( infile ) # if we had any errors, now is the time to raise them if self . _errors : info = "at line %s." % self . _errors [ 0 ] . line_number if len ( self . _errors ) > 1 : msg = ( "Parsing failed with several errors.\nFirst error %s" % info ) error = ConfigObjError ( msg ) else : error = self . _errors [ 0 ] # set the errors attribute; it's a list of tuples: # (error_type, message, line_number) error . errors = self . _errors # set the config attribute error . config = self raise error # delete private attributes del self . _errors # if defaults [ 'configspec' ] is None : self . configspec = None else : self . _handle_configspec ( defaults [ 'configspec' ] )