Lines Matching full:section
3 A configuration file consists of sections, lead by a "[section]" header,
27 objects for the list of sections, for the options within a section, and
40 When `strict` is True, the parser won't allow for any section or option
51 When `default_section' is given, the name of the special section is
53 be customized to point to any other valid section name. Its current
68 section proxies.
71 Return all the configuration section names, sans DEFAULT.
73 has_section(section)
74 Return whether the given section exists.
76 has_option(section, option)
77 Return whether the given option exists in the given section.
79 options(section)
80 Return list of configuration options for the named section.
96 Read configuration from a dictionary. Keys are section names,
98 in the section. If the used dictionary type preserves order, sections
102 get(section, option, raw=False, vars=None, fallback=_UNSET)
105 constructor and the DEFAULT section. Additional substitutions may be
110 getint(section, options, raw=False, vars=None, fallback=_UNSET)
113 getfloat(section, options, raw=False, vars=None, fallback=_UNSET)
116 getboolean(section, options, raw=False, vars=None, fallback=_UNSET)
121 items(section=_UNSET, raw=False, vars=None)
122 If section is given, return a list of tuples with (name, value) for
123 each option in the section. Otherwise, return a list of tuples with
124 (section_name, section_proxy) for each section, including DEFAULTSECT.
126 remove_section(section)
127 Remove the given file section and all its options.
129 remove_option(section, option)
130 Remove the given option from the given section.
132 set(section, option, value)
181 """Raised when no section matches a requested option."""
183 def __init__(self, section): argument
184 Error.__init__(self, 'No section: %r' % (section,))
185 self.section = section
186 self.args = (section, )
190 """Raised when a section is repeated in an input source.
193 using the API or in strict parsers when a section is found more than once
197 def __init__(self, section, source=None, lineno=None): argument
198 msg = [repr(section), " already exists"]
203 message.append(": section ")
207 msg.insert(0, "Section ")
209 self.section = section
212 self.args = (section, source, lineno)
222 def __init__(self, section, option, source=None, lineno=None): argument
223 msg = [repr(option), " in section ", repr(section),
235 self.section = section
239 self.args = (section, option, source, lineno)
245 def __init__(self, option, section): argument
246 Error.__init__(self, "No option %r in section: %r" %
247 (option, section))
249 self.section = section
250 self.args = (option, section)
256 def __init__(self, option, section, msg): argument
259 self.section = section
260 self.args = (option, section, msg)
266 def __init__(self, option, section, rawval, reference): argument
267 msg = ("Bad value substitution: option {!r} in section {!r} contains "
269 "Raw value: {!r}".format(option, section, reference, rawval))
270 InterpolationError.__init__(self, option, section, msg)
272 self.args = (option, section, rawval, reference)
286 def __init__(self, option, section, rawval): argument
288 "in section {!r} contains an interpolation key which "
290 "".format(option, section, MAX_INTERPOLATION_DEPTH,
292 InterpolationError.__init__(self, option, section, msg)
293 self.args = (option, section, rawval)
340 """Raised when a key-value pair is found before any section header."""
345 'File contains no section headers.\nfile: %r, line: %d\n%r' %
362 def before_get(self, parser, section, option, value, defaults): argument
365 def before_set(self, parser, section, option, value): argument
368 def before_read(self, parser, section, option, value): argument
371 def before_write(self, parser, section, option, value): argument
379 the same section, or values in the special default section.
392 def before_get(self, parser, section, option, value, defaults): argument
394 self._interpolate_some(parser, option, L, value, section, defaults, 1)
397 def before_set(self, parser, section, option, value): argument
405 def _interpolate_some(self, parser, option, accum, rest, section, map, argument
407 rawval = parser.get(section, option, raw=True, fallback=rest)
409 raise InterpolationDepthError(option, section, rawval)
426 raise InterpolationSyntaxError(option, section,
434 option, section, rawval, var) from None
437 section, map, depth + 1)
442 option, section,
453 def before_get(self, parser, section, option, value, defaults): argument
455 self._interpolate_some(parser, option, L, value, section, defaults, 1)
458 def before_set(self, parser, section, option, value): argument
466 def _interpolate_some(self, parser, option, accum, rest, section, map, argument
468 rawval = parser.get(section, option, raw=True, fallback=rest)
470 raise InterpolationDepthError(option, section, rawval)
487 raise InterpolationSyntaxError(option, section,
491 sect = section
503 option, section,
507 option, section, rawval, ":".join(path)) from None
516 option, section,
527 def before_get(self, parser, section, option, value, vars): argument
540 option, section, rawval, e.args[0]) from None
544 raise InterpolationDepthError(option, section, rawval)
547 def before_set(self, parser, section, option, value): argument
562 # Regular expressions for parsing section headers and options
644 """Return a list of section names, excluding [DEFAULT]"""
648 def add_section(self, section): argument
649 """Create a new section in the configuration.
651 Raise DuplicateSectionError if a section by the specified name
654 if section == self.default_section:
655 raise ValueError('Invalid section name: %r' % section)
657 if section in self._sections:
658 raise DuplicateSectionError(section)
659 self._sections[section] = self._dict()
660 self._proxies[section] = SectionProxy(self, section)
662 def has_section(self, section): argument
663 """Indicate whether the named section is present in the configuration.
665 The DEFAULT section is not acknowledged.
667 return section in self._sections
669 def options(self, section): argument
670 """Return a list of option names for the given section name."""
672 opts = self._sections[section].copy()
674 raise NoSectionError(section) from None
727 Keys are section names, values are dictionaries with keys and values
728 that should be present in the section. If the used dictionary type
732 reading, including section names, option names and keys.
738 for section, keys in dictionary.items():
739 section = str(section)
741 self.add_section(section)
743 if self._strict and section in elements_added:
745 elements_added.add(section)
750 if self._strict and (section, key) in elements_added:
751 raise DuplicateOptionError(section, key, source)
752 elements_added.add((section, key))
753 self.set(section, key, value)
764 def get(self, section, option, *, raw=False, vars=None, fallback=_UNSET): argument
765 """Get an option value for a given section.
768 in `vars' (if provided), `section', and in `DEFAULTSECT' in that order.
777 The section DEFAULT is special.
780 d = self._unify_values(section, vars)
791 raise NoOptionError(option, section)
798 return self._interpolation.before_get(self, section, option, value,
801 def _get(self, section, conv, option, **kwargs): argument
802 return conv(self.get(section, option, **kwargs))
804 def _get_conv(self, section, option, conv, *, raw=False, vars=None, argument
807 return self._get(section, conv, option, raw=raw, vars=vars,
815 def getint(self, section, option, *, raw=False, vars=None, argument
817 return self._get_conv(section, option, int, raw=raw, vars=vars,
820 def getfloat(self, section, option, *, raw=False, vars=None, argument
822 return self._get_conv(section, option, float, raw=raw, vars=vars,
825 def getboolean(self, section, option, *, raw=False, vars=None, argument
827 return self._get_conv(section, option, self._convert_to_boolean,
830 def items(self, section=_UNSET, raw=False, vars=None): argument
831 """Return a list of (name, value) tuples for each option in a section.
839 The section DEFAULT is special.
841 if section is _UNSET:
845 d.update(self._sections[section])
847 if section != self.default_section:
848 raise NoSectionError(section)
854 section, option, d[option], d)
860 """Remove a section from the parser and return it as
861 a (section_name, section_proxy) tuple. If no section is present, raise
864 The section DEFAULT is never returned because it cannot be removed.
875 def has_option(self, section, option): argument
876 """Check for the existence of a given option in a given section.
877 If the specified `section' is None or an empty string, DEFAULT is
878 assumed. If the specified `section' does not exist, returns False."""
879 if not section or section == self.default_section:
882 elif section not in self._sections:
886 return (option in self._sections[section]
889 def set(self, section, option, value=None): argument
892 value = self._interpolation.before_set(self, section, option,
894 if not section or section == self.default_section:
898 sectdict = self._sections[section]
900 raise NoSectionError(section) from None
916 for section in self._sections:
917 self._write_section(fp, section,
918 self._sections[section].items(), d)
921 """Write a single section to the specified `fp'."""
933 def remove_option(self, section, option): argument
935 if not section or section == self.default_section:
939 sectdict = self._sections[section]
941 raise NoSectionError(section) from None
948 def remove_section(self, section): argument
949 """Remove a file section."""
950 existed = section in self._sections
952 del self._sections[section]
953 del self._proxies[section]
963 # the section.
975 raise ValueError("Cannot remove the default section.")
984 return len(self._sections) + 1 # the default section
993 Each section in a configuration file contains a header, indicated by
1005 section names.
1055 # a section header or option header?
1058 # is it a section header?
1077 # no section header in the file?
1116 for section, options in all_sections:
1121 section,
1136 def _unify_values(self, section, vars): argument
1138 the 'section' which takes priority over the DEFAULTSECT.
1143 sectiondict = self._sections[section]
1145 if section != self.default_section:
1146 raise NoSectionError(section) from None
1163 def _validate_value_types(self, *, section="", option="", value=""): argument
1176 if not isinstance(section, str):
1177 raise TypeError("section names must be strings")
1194 def set(self, section, option, value=None): argument
1198 super().set(section, option, value)
1200 def add_section(self, section): argument
1201 """Create a new section in the configuration. Extends
1202 RawConfigParser.add_section by validating if the section name is
1204 self._validate_value_types(section=section)
1205 super().add_section(section)
1235 """A proxy for a single section from a parser."""
1238 """Creates a view on a section of the specified `name` in `parser`."""
1247 return '<Section: {}>'.format(self._name)
1285 # The name of the section on a proxy is read-only.
1305 """Enables reuse of get*() methods between the parser and section proxies.
1309 section proxies to find and use the implementation on the parser class.