Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions | Private Attributes | Static Private Attributes
configparser.RawConfigParser Class Reference
Inheritance diagram for configparser.RawConfigParser:
Inheritance graph
[legend]
Collaboration diagram for configparser.RawConfigParser:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def defaults
def sections
def add_section
def has_section
def options
def read
def read_file
def read_string
def read_dict
def readfp
def get
def getint
def getfloat
def getboolean
def items
def optionxform
def has_option
def set
def write
def remove_option
def remove_section
def __getitem__
def __setitem__
def __delitem__
def __contains__
def __len__
def __iter__

Public Attributes

 default_section

Static Public Attributes

tuple SECTCRE = re.compile(_SECT_TMPL, re.VERBOSE)
tuple OPTCRE = re.compile(_OPT_TMPL.format(delim="=|:"), re.VERBOSE)
tuple OPTCRE_NV = re.compile(_OPT_NV_TMPL.format(delim="=|:"), re.VERBOSE)
tuple NONSPACECRE = re.compile(r"\S")
dictionary BOOLEAN_STATES

Private Member Functions

def _get
def _write_section
def _read
def _join_multiline_values
def _handle_error
def _unify_values
def _convert_to_boolean
def _validate_value_types

Private Attributes

 _dict
 _sections
 _defaults
 _proxies
 _delimiters
 _optcre
 _comment_prefixes
 _inline_comment_prefixes
 _strict
 _allow_no_value
 _empty_lines_in_values
 _interpolation

Static Private Attributes

string _SECT_TMPL = r""
string _OPT_TMPL = r""
string _OPT_NV_TMPL = r""
tuple _DEFAULT_INTERPOLATION = Interpolation()

Detailed Description

ConfigParser that does not do interpolation.

Definition at line 554 of file configparser.py.


Constructor & Destructor Documentation

def configparser.RawConfigParser.__init__ (   self,
  defaults = None,
  dict_type = _default_dict,
  allow_no_value = False,
  delimiters = ('=', ':',
  comment_prefixes = ('#', ';',
  inline_comment_prefixes = None,
  strict = True,
  empty_lines_in_values = True,
  default_section = DEFAULTSECT,
  interpolation = _UNSET 
)

Definition at line 600 of file configparser.py.

00600 
00601                  interpolation=_UNSET):
00602 
00603         self._dict = dict_type
00604         self._sections = self._dict()
00605         self._defaults = self._dict()
00606         self._proxies = self._dict()
00607         self._proxies[default_section] = SectionProxy(self, default_section)
00608         if defaults:
00609             for key, value in defaults.items():
00610                 self._defaults[self.optionxform(key)] = value
00611         self._delimiters = tuple(delimiters)
00612         if delimiters == ('=', ':'):
00613             self._optcre = self.OPTCRE_NV if allow_no_value else self.OPTCRE
00614         else:
00615             d = "|".join(re.escape(d) for d in delimiters)
00616             if allow_no_value:
00617                 self._optcre = re.compile(self._OPT_NV_TMPL.format(delim=d),
00618                                           re.VERBOSE)
00619             else:
00620                 self._optcre = re.compile(self._OPT_TMPL.format(delim=d),
00621                                           re.VERBOSE)
00622         self._comment_prefixes = tuple(comment_prefixes or ())
00623         self._inline_comment_prefixes = tuple(inline_comment_prefixes or ())
00624         self._strict = strict
00625         self._allow_no_value = allow_no_value
00626         self._empty_lines_in_values = empty_lines_in_values
00627         self.default_section=default_section
00628         self._interpolation = interpolation
00629         if self._interpolation is _UNSET:
00630             self._interpolation = self._DEFAULT_INTERPOLATION
00631         if self._interpolation is None:
00632             self._interpolation = Interpolation()

Here is the caller graph for this function:


Member Function Documentation

def configparser.RawConfigParser.__contains__ (   self,
  key 
)

Definition at line 960 of file configparser.py.

00960 
00961     def __contains__(self, key):
00962         return key == self.default_section or self.has_section(key)

Here is the call graph for this function:

def configparser.RawConfigParser.__delitem__ (   self,
  key 
)

Definition at line 953 of file configparser.py.

00953 
00954     def __delitem__(self, key):
00955         if key == self.default_section:
00956             raise ValueError("Cannot remove the default section.")
00957         if not self.has_section(key):
00958             raise KeyError(key)
00959         self.remove_section(key)

Here is the call graph for this function:

def configparser.RawConfigParser.__getitem__ (   self,
  key 
)

Definition at line 939 of file configparser.py.

00939 
00940     def __getitem__(self, key):
00941         if key != self.default_section and not self.has_section(key):
00942             raise KeyError(key)
00943         return self._proxies[key]

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 966 of file configparser.py.

00966 
00967     def __iter__(self):
00968         # XXX does it break when underlying container state changed?
00969         return itertools.chain((self.default_section,), self._sections.keys())

Definition at line 963 of file configparser.py.

00963 
00964     def __len__(self):
00965         return len(self._sections) + 1 # the default section

def configparser.RawConfigParser.__setitem__ (   self,
  key,
  value 
)

Definition at line 944 of file configparser.py.

00944 
00945     def __setitem__(self, key, value):
00946         # To conform with the mapping protocol, overwrites existing values in
00947         # the section.
00948 
00949         # XXX this is not atomic if read_dict fails at any point. Then again,
00950         # no update method in configparser is atomic in this implementation.
00951         self.remove_section(key)
00952         self.read_dict({key: value})

Here is the call graph for this function:

def configparser.RawConfigParser._convert_to_boolean (   self,
  value 
) [private]
Return a boolean value translating from other types if necessary.

Definition at line 1122 of file configparser.py.

01122 
01123     def _convert_to_boolean(self, value):
01124         """Return a boolean value translating from other types if necessary.
01125         """
01126         if value.lower() not in self.BOOLEAN_STATES:
01127             raise ValueError('Not a boolean: %s' % value)
01128         return self.BOOLEAN_STATES[value.lower()]

Here is the caller graph for this function:

def configparser.RawConfigParser._get (   self,
  section,
  conv,
  option,
  kwargs 
) [private]

Definition at line 792 of file configparser.py.

00792 
00793     def _get(self, section, conv, option, **kwargs):
00794         return conv(self.get(section, option, **kwargs))

Here is the call graph for this function:

Here is the caller graph for this function:

def configparser.RawConfigParser._handle_error (   self,
  exc,
  fpname,
  lineno,
  line 
) [private]

Definition at line 1096 of file configparser.py.

01096 
01097     def _handle_error(self, exc, fpname, lineno, line):
01098         if not exc:
01099             exc = ParsingError(fpname)
01100         exc.append(lineno, repr(line))
01101         return exc

Here is the caller graph for this function:

Definition at line 1084 of file configparser.py.

01084 
01085     def _join_multiline_values(self):
01086         defaults = self.default_section, self._defaults
01087         all_sections = itertools.chain((defaults,),
01088                                        self._sections.items())
01089         for section, options in all_sections:
01090             for name, val in options.items():
01091                 if isinstance(val, list):
01092                     val = '\n'.join(val).rstrip()
01093                 options[name] = self._interpolation.before_read(self,
01094                                                                 section,
01095                                                                 name, val)

Here is the caller graph for this function:

def configparser.RawConfigParser._read (   self,
  fp,
  fpname 
) [private]
Parse a sectioned configuration file.

Each section in a configuration file contains a header, indicated by
a name in square brackets (`[]'), plus key/value options, indicated by
`name' and `value' delimited with a specific substring (`=' or `:' by
default).

Values can span multiple lines, as long as they are indented deeper
than the first line of the value. Depending on the parser's mode, blank
lines may be treated as parts of multiline values or ignored.

Configuration files may include comments, prefixed by specific
characters (`#' and `;' by default). Comments may appear on their own
in an otherwise empty line or may be entered in lines holding values or
section names.

Definition at line 970 of file configparser.py.

00970 
00971     def _read(self, fp, fpname):
00972         """Parse a sectioned configuration file.
00973 
00974         Each section in a configuration file contains a header, indicated by
00975         a name in square brackets (`[]'), plus key/value options, indicated by
00976         `name' and `value' delimited with a specific substring (`=' or `:' by
00977         default).
00978 
00979         Values can span multiple lines, as long as they are indented deeper
00980         than the first line of the value. Depending on the parser's mode, blank
00981         lines may be treated as parts of multiline values or ignored.
00982 
00983         Configuration files may include comments, prefixed by specific
00984         characters (`#' and `;' by default). Comments may appear on their own
00985         in an otherwise empty line or may be entered in lines holding values or
00986         section names.
00987         """
00988         elements_added = set()
00989         cursect = None                        # None, or a dictionary
00990         sectname = None
00991         optname = None
00992         lineno = 0
00993         indent_level = 0
00994         e = None                              # None, or an exception
00995         for lineno, line in enumerate(fp, start=1):
00996             comment_start = None
00997             # strip inline comments
00998             for prefix in self._inline_comment_prefixes:
00999                 index = line.find(prefix)
01000                 if index == 0 or (index > 0 and line[index-1].isspace()):
01001                     comment_start = index
01002                     break
01003             # strip full line comments
01004             for prefix in self._comment_prefixes:
01005                 if line.strip().startswith(prefix):
01006                     comment_start = 0
01007                     break
01008             value = line[:comment_start].strip()
01009             if not value:
01010                 if self._empty_lines_in_values:
01011                     # add empty line to the value, but only if there was no
01012                     # comment on the line
01013                     if (comment_start is None and
01014                         cursect is not None and
01015                         optname and
01016                         cursect[optname] is not None):
01017                         cursect[optname].append('') # newlines added at join
01018                 else:
01019                     # empty line marks end of value
01020                     indent_level = sys.maxsize
01021                 continue
01022             # continuation line?
01023             first_nonspace = self.NONSPACECRE.search(line)
01024             cur_indent_level = first_nonspace.start() if first_nonspace else 0
01025             if (cursect is not None and optname and
01026                 cur_indent_level > indent_level):
01027                 cursect[optname].append(value)
01028             # a section header or option header?
01029             else:
01030                 indent_level = cur_indent_level
01031                 # is it a section header?
01032                 mo = self.SECTCRE.match(value)
01033                 if mo:
01034                     sectname = mo.group('header')
01035                     if sectname in self._sections:
01036                         if self._strict and sectname in elements_added:
01037                             raise DuplicateSectionError(sectname, fpname,
01038                                                         lineno)
01039                         cursect = self._sections[sectname]
01040                         elements_added.add(sectname)
01041                     elif sectname == self.default_section:
01042                         cursect = self._defaults
01043                     else:
01044                         cursect = self._dict()
01045                         self._sections[sectname] = cursect
01046                         self._proxies[sectname] = SectionProxy(self, sectname)
01047                         elements_added.add(sectname)
01048                     # So sections can't start with a continuation line
01049                     optname = None
01050                 # no section header in the file?
01051                 elif cursect is None:
01052                     raise MissingSectionHeaderError(fpname, lineno, line)
01053                 # an option line?
01054                 else:
01055                     mo = self._optcre.match(value)
01056                     if mo:
01057                         optname, vi, optval = mo.group('option', 'vi', 'value')
01058                         if not optname:
01059                             e = self._handle_error(e, fpname, lineno, line)
01060                         optname = self.optionxform(optname.rstrip())
01061                         if (self._strict and
01062                             (sectname, optname) in elements_added):
01063                             raise DuplicateOptionError(sectname, optname,
01064                                                        fpname, lineno)
01065                         elements_added.add((sectname, optname))
01066                         # This check is fine because the OPTCRE cannot
01067                         # match if it would set optval to None
01068                         if optval is not None:
01069                             optval = optval.strip()
01070                             cursect[optname] = [optval]
01071                         else:
01072                             # valueless option handling
01073                             cursect[optname] = None
01074                     else:
01075                         # a non-fatal parsing error occurred. set up the
01076                         # exception but keep going. the exception will be
01077                         # raised at the end of the file and will contain a
01078                         # list of all bogus lines
01079                         e = self._handle_error(e, fpname, lineno, line)
01080         # if any parsing errors occurred, raise an exception
01081         if e:
01082             raise e
01083         self._join_multiline_values()

Here is the call graph for this function:

Here is the caller graph for this function:

def configparser.RawConfigParser._unify_values (   self,
  section,
  vars 
) [private]
Create a sequence of lookups with 'vars' taking priority over
the 'section' which takes priority over the DEFAULTSECT.

Definition at line 1102 of file configparser.py.

01102 
01103     def _unify_values(self, section, vars):
01104         """Create a sequence of lookups with 'vars' taking priority over
01105         the 'section' which takes priority over the DEFAULTSECT.
01106 
01107         """
01108         sectiondict = {}
01109         try:
01110             sectiondict = self._sections[section]
01111         except KeyError:
01112             if section != self.default_section:
01113                 raise NoSectionError(section)
01114         # Update with the entry specific variables
01115         vardict = {}
01116         if vars:
01117             for key, value in vars.items():
01118                 if value is not None:
01119                     value = str(value)
01120                 vardict[self.optionxform(key)] = value
01121         return _ChainMap(vardict, sectiondict, self._defaults)

Here is the call graph for this function:

Here is the caller graph for this function:

def configparser.RawConfigParser._validate_value_types (   self,
  section = "",
  option = "",
  value = "" 
) [private]
Raises a TypeError for non-string values.

The only legal non-string value if we allow valueless
options is None, so we need to check if the value is a
string if:
- we do not allow valueless options, or
- we allow valueless options but the value is not None

For compatibility reasons this method is not used in classic set()
for RawConfigParsers. It is invoked in every case for mapping protocol
access and in ConfigParser.set().

Definition at line 1129 of file configparser.py.

01129 
01130     def _validate_value_types(self, *, section="", option="", value=""):
01131         """Raises a TypeError for non-string values.
01132 
01133         The only legal non-string value if we allow valueless
01134         options is None, so we need to check if the value is a
01135         string if:
01136         - we do not allow valueless options, or
01137         - we allow valueless options but the value is not None
01138 
01139         For compatibility reasons this method is not used in classic set()
01140         for RawConfigParsers. It is invoked in every case for mapping protocol
01141         access and in ConfigParser.set().
01142         """
01143         if not isinstance(section, str):
01144             raise TypeError("section names must be strings")
01145         if not isinstance(option, str):
01146             raise TypeError("option keys must be strings")
01147         if not self._allow_no_value or value:
01148             if not isinstance(value, str):
01149                 raise TypeError("option values must be strings")
01150 

Here is the caller graph for this function:

def configparser.RawConfigParser._write_section (   self,
  fp,
  section_name,
  section_items,
  delimiter 
) [private]
Write a single section to the specified `fp'.

Definition at line 903 of file configparser.py.

00903 
00904     def _write_section(self, fp, section_name, section_items, delimiter):
00905         """Write a single section to the specified `fp'."""
00906         fp.write("[{}]\n".format(section_name))
00907         for key, value in section_items:
00908             value = self._interpolation.before_write(self, section_name, key,
00909                                                      value)
00910             if value is not None or not self._allow_no_value:
00911                 value = delimiter + str(value).replace('\n', '\n\t')
00912             else:
00913                 value = ""
00914             fp.write("{}{}\n".format(key, value))
00915         fp.write("\n")

Here is the call graph for this function:

Here is the caller graph for this function:

def configparser.RawConfigParser.add_section (   self,
  section 
)
Create a new section in the configuration.

Raise DuplicateSectionError if a section by the specified name
already exists. Raise ValueError if name is DEFAULT.

Reimplemented in configparser.ConfigParser.

Definition at line 641 of file configparser.py.

00641 
00642     def add_section(self, section):
00643         """Create a new section in the configuration.
00644 
00645         Raise DuplicateSectionError if a section by the specified name
00646         already exists. Raise ValueError if name is DEFAULT.
00647         """
00648         if section == self.default_section:
00649             raise ValueError('Invalid section name: %r' % section)
00650 
00651         if section in self._sections:
00652             raise DuplicateSectionError(section)
00653         self._sections[section] = self._dict()
00654         self._proxies[section] = SectionProxy(self, section)

Here is the caller graph for this function:

Definition at line 633 of file configparser.py.

00633 
00634     def defaults(self):
00635         return self._defaults

def configparser.RawConfigParser.get (   self,
  section,
  option,
  raw = False,
  vars = None,
  fallback = _UNSET 
)
Get an option value for a given section.

If `vars' is provided, it must be a dictionary. The option is looked up
in `vars' (if provided), `section', and in `DEFAULTSECT' in that order.
If the key is not found and `fallback' is provided, it is used as
a fallback value. `None' can be provided as a `fallback' value.

If interpolation is enabled and the optional argument `raw' is False,
all interpolations are expanded in the return values.

Arguments `raw', `vars', and `fallback' are keyword only.

The section DEFAULT is special.

Definition at line 755 of file configparser.py.

00755 
00756     def get(self, section, option, *, raw=False, vars=None, fallback=_UNSET):
00757         """Get an option value for a given section.
00758 
00759         If `vars' is provided, it must be a dictionary. The option is looked up
00760         in `vars' (if provided), `section', and in `DEFAULTSECT' in that order.
00761         If the key is not found and `fallback' is provided, it is used as
00762         a fallback value. `None' can be provided as a `fallback' value.
00763 
00764         If interpolation is enabled and the optional argument `raw' is False,
00765         all interpolations are expanded in the return values.
00766 
00767         Arguments `raw', `vars', and `fallback' are keyword only.
00768 
00769         The section DEFAULT is special.
00770         """
00771         try:
00772             d = self._unify_values(section, vars)
00773         except NoSectionError:
00774             if fallback is _UNSET:
00775                 raise
00776             else:
00777                 return fallback
00778         option = self.optionxform(option)
00779         try:
00780             value = d[option]
00781         except KeyError:
00782             if fallback is _UNSET:
00783                 raise NoOptionError(option, section)
00784             else:
00785                 return fallback
00786 
00787         if raw or value is None:
00788             return value
00789         else:
00790             return self._interpolation.before_get(self, section, option, value,
00791                                                   d)

Here is the call graph for this function:

Here is the caller graph for this function:

def configparser.RawConfigParser.getboolean (   self,
  section,
  option,
  raw = False,
  vars = None,
  fallback = _UNSET 
)

Definition at line 816 of file configparser.py.

00816 
00817                    fallback=_UNSET):
00818         try:
00819             return self._get(section, self._convert_to_boolean, option,
00820                              raw=raw, vars=vars)
00821         except (NoSectionError, NoOptionError):
00822             if fallback is _UNSET:
00823                 raise
00824             else:
00825                 return fallback

Here is the call graph for this function:

Here is the caller graph for this function:

def configparser.RawConfigParser.getfloat (   self,
  section,
  option,
  raw = False,
  vars = None,
  fallback = _UNSET 
)

Definition at line 806 of file configparser.py.

00806 
00807                  fallback=_UNSET):
00808         try:
00809             return self._get(section, float, option, raw=raw, vars=vars)
00810         except (NoSectionError, NoOptionError):
00811             if fallback is _UNSET:
00812                 raise
00813             else:
00814                 return fallback

Here is the call graph for this function:

Here is the caller graph for this function:

def configparser.RawConfigParser.getint (   self,
  section,
  option,
  raw = False,
  vars = None,
  fallback = _UNSET 
)

Definition at line 796 of file configparser.py.

00796 
00797                fallback=_UNSET):
00798         try:
00799             return self._get(section, int, option, raw=raw, vars=vars)
00800         except (NoSectionError, NoOptionError):
00801             if fallback is _UNSET:
00802                 raise
00803             else:
00804                 return fallback

Here is the call graph for this function:

Here is the caller graph for this function:

def configparser.RawConfigParser.has_option (   self,
  section,
  option 
)
Check for the existence of a given option in a given section.
If the specified `section' is None or an empty string, DEFAULT is
assumed. If the specified `section' does not exist, returns False.

Definition at line 858 of file configparser.py.

00858 
00859     def has_option(self, section, option):
00860         """Check for the existence of a given option in a given section.
00861         If the specified `section' is None or an empty string, DEFAULT is
00862         assumed. If the specified `section' does not exist, returns False."""
00863         if not section or section == self.default_section:
00864             option = self.optionxform(option)
00865             return option in self._defaults
00866         elif section not in self._sections:
00867             return False
00868         else:
00869             option = self.optionxform(option)
00870             return (option in self._sections[section]
00871                     or option in self._defaults)

Here is the call graph for this function:

Here is the caller graph for this function:

def configparser.RawConfigParser.has_section (   self,
  section 
)
Indicate whether the named section is present in the configuration.

The DEFAULT section is not acknowledged.

Definition at line 655 of file configparser.py.

00655 
00656     def has_section(self, section):
00657         """Indicate whether the named section is present in the configuration.
00658 
00659         The DEFAULT section is not acknowledged.
00660         """
00661         return section in self._sections

Here is the caller graph for this function:

def configparser.RawConfigParser.items (   self,
  section = _UNSET,
  raw = False,
  vars = None 
)
Return a list of (name, value) tuples for each option in a section.

All % interpolations are expanded in the return values, based on the
defaults passed into the constructor, unless the optional argument
`raw' is true.  Additional substitutions may be provided using the
`vars' argument, which must be a dictionary whose contents overrides
any pre-existing defaults.

The section DEFAULT is special.

Definition at line 826 of file configparser.py.

00826 
00827     def items(self, section=_UNSET, raw=False, vars=None):
00828         """Return a list of (name, value) tuples for each option in a section.
00829 
00830         All % interpolations are expanded in the return values, based on the
00831         defaults passed into the constructor, unless the optional argument
00832         `raw' is true.  Additional substitutions may be provided using the
00833         `vars' argument, which must be a dictionary whose contents overrides
00834         any pre-existing defaults.
00835 
00836         The section DEFAULT is special.
00837         """
00838         if section is _UNSET:
00839             return super().items()
00840         d = self._defaults.copy()
00841         try:
00842             d.update(self._sections[section])
00843         except KeyError:
00844             if section != self.default_section:
00845                 raise NoSectionError(section)
00846         # Update with the entry specific variables
00847         if vars:
00848             for key, value in vars.items():
00849                 d[self.optionxform(key)] = value
00850         value_getter = lambda option: self._interpolation.before_get(self,
00851             section, option, d[option], d)
00852         if raw:
00853             value_getter = lambda option: d[option]
00854         return [(option, value_getter(option)) for option in d.keys()]

Here is the call graph for this function:

Here is the caller graph for this function:

def configparser.RawConfigParser.options (   self,
  section 
)
Return a list of option names for the given section name.

Definition at line 662 of file configparser.py.

00662 
00663     def options(self, section):
00664         """Return a list of option names for the given section name."""
00665         try:
00666             opts = self._sections[section].copy()
00667         except KeyError:
00668             raise NoSectionError(section)
00669         opts.update(self._defaults)
00670         return list(opts.keys())

Here is the caller graph for this function:

def configparser.RawConfigParser.optionxform (   self,
  optionstr 
)

Definition at line 855 of file configparser.py.

00855 
00856     def optionxform(self, optionstr):
00857         return optionstr.lower()

Here is the caller graph for this function:

def configparser.RawConfigParser.read (   self,
  filenames,
  encoding = None 
)
Read and parse a filename or a list of filenames.

Files that cannot be opened are silently ignored; this is
designed so that you can specify a list of potential
configuration file locations (e.g. current directory, user's
home directory, systemwide directory), and all existing
configuration files in the list will be read.  A single
filename may also be given.

Return list of successfully read files.

Definition at line 671 of file configparser.py.

00671 
00672     def read(self, filenames, encoding=None):
00673         """Read and parse a filename or a list of filenames.
00674 
00675         Files that cannot be opened are silently ignored; this is
00676         designed so that you can specify a list of potential
00677         configuration file locations (e.g. current directory, user's
00678         home directory, systemwide directory), and all existing
00679         configuration files in the list will be read.  A single
00680         filename may also be given.
00681 
00682         Return list of successfully read files.
00683         """
00684         if isinstance(filenames, str):
00685             filenames = [filenames]
00686         read_ok = []
00687         for filename in filenames:
00688             try:
00689                 with open(filename, encoding=encoding) as fp:
00690                     self._read(fp, filename)
00691             except IOError:
00692                 continue
00693             read_ok.append(filename)
00694         return read_ok

Here is the call graph for this function:

Here is the caller graph for this function:

def configparser.RawConfigParser.read_dict (   self,
  dictionary,
  source = '<dict>' 
)
Read configuration from a dictionary.

Keys are section names, values are dictionaries with keys and values
that should be present in the section. If the used dictionary type
preserves order, sections and their keys will be added in order.

All types held in the dictionary are converted to strings during
reading, including section names, option names and keys.

Optional second argument is the `source' specifying the name of the
dictionary being read.

Definition at line 715 of file configparser.py.

00715 
00716     def read_dict(self, dictionary, source='<dict>'):
00717         """Read configuration from a dictionary.
00718 
00719         Keys are section names, values are dictionaries with keys and values
00720         that should be present in the section. If the used dictionary type
00721         preserves order, sections and their keys will be added in order.
00722 
00723         All types held in the dictionary are converted to strings during
00724         reading, including section names, option names and keys.
00725 
00726         Optional second argument is the `source' specifying the name of the
00727         dictionary being read.
00728         """
00729         elements_added = set()
00730         for section, keys in dictionary.items():
00731             section = str(section)
00732             try:
00733                 self.add_section(section)
00734             except (DuplicateSectionError, ValueError):
00735                 if self._strict and section in elements_added:
00736                     raise
00737             elements_added.add(section)
00738             for key, value in keys.items():
00739                 key = self.optionxform(str(key))
00740                 if value is not None:
00741                     value = str(value)
00742                 if self._strict and (section, key) in elements_added:
00743                     raise DuplicateOptionError(section, key, source)
00744                 elements_added.add((section, key))
00745                 self.set(section, key, value)

Here is the call graph for this function:

Here is the caller graph for this function:

def configparser.RawConfigParser.read_file (   self,
  f,
  source = None 
)
Like read() but the argument must be a file-like object.

The `f' argument must be iterable, returning one line at a time.
Optional second argument is the `source' specifying the name of the
file being read. If not given, it is taken from f.name. If `f' has no
`name' attribute, `<???>' is used.

Definition at line 695 of file configparser.py.

00695 
00696     def read_file(self, f, source=None):
00697         """Like read() but the argument must be a file-like object.
00698 
00699         The `f' argument must be iterable, returning one line at a time.
00700         Optional second argument is the `source' specifying the name of the
00701         file being read. If not given, it is taken from f.name. If `f' has no
00702         `name' attribute, `<???>' is used.
00703         """
00704         if source is None:
00705             try:
00706                 source = f.name
00707             except AttributeError:
00708                 source = '<???>'
00709         self._read(f, source)

Here is the call graph for this function:

Here is the caller graph for this function:

def configparser.RawConfigParser.read_string (   self,
  string,
  source = '<string>' 
)
Read configuration from a given string.

Definition at line 710 of file configparser.py.

00710 
00711     def read_string(self, string, source='<string>'):
00712         """Read configuration from a given string."""
00713         sfile = io.StringIO(string)
00714         self.read_file(sfile, source)

Here is the call graph for this function:

def configparser.RawConfigParser.readfp (   self,
  fp,
  filename = None 
)
Deprecated, use read_file instead.

Definition at line 746 of file configparser.py.

00746 
00747     def readfp(self, fp, filename=None):
00748         """Deprecated, use read_file instead."""
00749         warnings.warn(
00750             "This method will be removed in future versions.  "
00751             "Use 'parser.read_file()' instead.",
00752             DeprecationWarning, stacklevel=2
00753         )
00754         self.read_file(fp, source=filename)

Here is the call graph for this function:

Here is the caller graph for this function:

def configparser.RawConfigParser.remove_option (   self,
  section,
  option 
)
Remove an option.

Definition at line 916 of file configparser.py.

00916 
00917     def remove_option(self, section, option):
00918         """Remove an option."""
00919         if not section or section == self.default_section:
00920             sectdict = self._defaults
00921         else:
00922             try:
00923                 sectdict = self._sections[section]
00924             except KeyError:
00925                 raise NoSectionError(section)
00926         option = self.optionxform(option)
00927         existed = option in sectdict
00928         if existed:
00929             del sectdict[option]
00930         return existed

Here is the call graph for this function:

Here is the caller graph for this function:

def configparser.RawConfigParser.remove_section (   self,
  section 
)
Remove a file section.

Definition at line 931 of file configparser.py.

00931 
00932     def remove_section(self, section):
00933         """Remove a file section."""
00934         existed = section in self._sections
00935         if existed:
00936             del self._sections[section]
00937             del self._proxies[section]
00938         return existed

Here is the caller graph for this function:

Return a list of section names, excluding [DEFAULT]

Definition at line 636 of file configparser.py.

00636 
00637     def sections(self):
00638         """Return a list of section names, excluding [DEFAULT]"""
00639         # self._sections will never have [DEFAULT] in it
00640         return list(self._sections.keys())

Here is the caller graph for this function:

def configparser.RawConfigParser.set (   self,
  section,
  option,
  value = None 
)
Set an option.

Reimplemented in configparser.ConfigParser.

Definition at line 872 of file configparser.py.

00872 
00873     def set(self, section, option, value=None):
00874         """Set an option."""
00875         if value:
00876             value = self._interpolation.before_set(self, section, option,
00877                                                    value)
00878         if not section or section == self.default_section:
00879             sectdict = self._defaults
00880         else:
00881             try:
00882                 sectdict = self._sections[section]
00883             except KeyError:
00884                 raise NoSectionError(section)
00885         sectdict[self.optionxform(option)] = value

Here is the call graph for this function:

Here is the caller graph for this function:

def configparser.RawConfigParser.write (   self,
  fp,
  space_around_delimiters = True 
)
Write an .ini-format representation of the configuration state.

If `space_around_delimiters' is True (the default), delimiters
between keys and values are surrounded by spaces.

Definition at line 886 of file configparser.py.

00886 
00887     def write(self, fp, space_around_delimiters=True):
00888         """Write an .ini-format representation of the configuration state.
00889 
00890         If `space_around_delimiters' is True (the default), delimiters
00891         between keys and values are surrounded by spaces.
00892         """
00893         if space_around_delimiters:
00894             d = " {} ".format(self._delimiters[0])
00895         else:
00896             d = self._delimiters[0]
00897         if self._defaults:
00898             self._write_section(fp, self.default_section,
00899                                     self._defaults.items(), d)
00900         for section in self._sections:
00901             self._write_section(fp, section,
00902                                 self._sections[section].items(), d)

Here is the call graph for this function:


Member Data Documentation

Definition at line 624 of file configparser.py.

Definition at line 621 of file configparser.py.

Reimplemented in configparser.ConfigParser.

Definition at line 581 of file configparser.py.

Definition at line 604 of file configparser.py.

Definition at line 610 of file configparser.py.

Definition at line 602 of file configparser.py.

Definition at line 625 of file configparser.py.

Definition at line 622 of file configparser.py.

Definition at line 627 of file configparser.py.

Definition at line 571 of file configparser.py.

Definition at line 563 of file configparser.py.

Definition at line 612 of file configparser.py.

Definition at line 605 of file configparser.py.

Definition at line 558 of file configparser.py.

Definition at line 603 of file configparser.py.

Definition at line 623 of file configparser.py.

Initial value:
{'1': True, 'yes': True, 'true': True, 'on': True,
                      '0': False, 'no': False, 'false': False, 'off': False}

Definition at line 592 of file configparser.py.

Definition at line 626 of file configparser.py.

Definition at line 590 of file configparser.py.

tuple configparser.RawConfigParser.OPTCRE = re.compile(_OPT_TMPL.format(delim="=|:"), re.VERBOSE) [static]

Definition at line 585 of file configparser.py.

tuple configparser.RawConfigParser.OPTCRE_NV = re.compile(_OPT_NV_TMPL.format(delim="=|:"), re.VERBOSE) [static]

Definition at line 588 of file configparser.py.

Definition at line 583 of file configparser.py.


The documentation for this class was generated from the following file: