Lines Matching refs:section
3 A configuration file consists of sections, lead by a "[section]" header,
28 objects for the list of sections, for the options within a section, and
41 When `strict` is True, the parser won't allow for any section or option
52 When `default_section` is given, the name of the special section is
54 be customized to point to any other valid section name. Its current
69 section proxies.
72 Return all the configuration section names, sans DEFAULT.
74 has_section(section)
75 Return whether the given section exists.
77 has_option(section, option)
78 Return whether the given option exists in the given section.
80 options(section)
81 Return list of configuration options for the named section.
97 Read configuration from a dictionary. Keys are section names,
99 in the section. If the used dictionary type preserves order, sections
103 get(section, option, raw=False, vars=None, fallback=_UNSET)
106 constructor and the DEFAULT section. Additional substitutions may be
111 getint(section, options, raw=False, vars=None, fallback=_UNSET)
114 getfloat(section, options, raw=False, vars=None, fallback=_UNSET)
117 getboolean(section, options, raw=False, vars=None, fallback=_UNSET)
122 items(section=_UNSET, raw=False, vars=None)
123 If section is given, return a list of tuples with (name, value) for
124 each option in the section. Otherwise, return a list of tuples with
125 (section_name, section_proxy) for each section, including DEFAULTSECT.
127 remove_section(section)
128 Remove the given file section and all its options.
130 remove_option(section, option)
131 Remove the given option from the given section.
133 set(section, option, value)
183 """Raised when no section matches a requested option."""
185 def __init__(self, section):
186 Error.__init__(self, 'No section: %r' % (section,))
187 self.section = section
188 self.args = (section, )
192 """Raised when a section is repeated in an input source.
195 using the API or in strict parsers when a section is found more than once
199 def __init__(self, section, source=None, lineno=None):
200 msg = [repr(section), " already exists"]
205 message.append(": section ")
211 self.section = section
214 self.args = (section, source, lineno)
224 def __init__(self, section, option, source=None, lineno=None):
225 msg = [repr(option), " in section ", repr(section),
237 self.section = section
241 self.args = (section, option, source, lineno)
247 def __init__(self, option, section):
248 Error.__init__(self, "No option %r in section: %r" %
249 (option, section))
251 self.section = section
252 self.args = (option, section)
258 def __init__(self, option, section, msg):
261 self.section = section
262 self.args = (option, section, msg)
268 def __init__(self, option, section, rawval, reference):
269 msg = ("Bad value substitution: option {!r} in section {!r} contains "
271 "Raw value: {!r}".format(option, section, reference, rawval))
272 InterpolationError.__init__(self, option, section, msg)
274 self.args = (option, section, rawval, reference)
288 def __init__(self, option, section, rawval):
290 "in section {!r} contains an interpolation key which "
292 "".format(option, section, MAX_INTERPOLATION_DEPTH,
294 InterpolationError.__init__(self, option, section, msg)
295 self.args = (option, section, rawval)
342 """Raised when a key-value pair is found before any section header."""
347 'File contains no section headers.\nfile: %r, line: %d\n%r' %
364 def before_get(self, parser, section, option, value, defaults):
367 def before_set(self, parser, section, option, value):
370 def before_read(self, parser, section, option, value):
373 def before_write(self, parser, section, option, value):
381 the same section, or values in the special default section.
394 def before_get(self, parser, section, option, value, defaults):
396 self._interpolate_some(parser, option, L, value, section, defaults, 1)
399 def before_set(self, parser, section, option, value):
407 def _interpolate_some(self, parser, option, accum, rest, section, map,
409 rawval = parser.get(section, option, raw=True, fallback=rest)
411 raise InterpolationDepthError(option, section, rawval)
428 raise InterpolationSyntaxError(option, section,
436 option, section, rawval, var) from None
439 section, map, depth + 1)
444 option, section,
455 def before_get(self, parser, section, option, value, defaults):
457 self._interpolate_some(parser, option, L, value, section, defaults, 1)
460 def before_set(self, parser, section, option, value):
468 def _interpolate_some(self, parser, option, accum, rest, section, map,
470 rawval = parser.get(section, option, raw=True, fallback=rest)
472 raise InterpolationDepthError(option, section, rawval)
489 raise InterpolationSyntaxError(option, section,
493 sect = section
505 option, section,
509 option, section, rawval, ":".join(path)) from None
518 option, section,
538 def before_get(self, parser, section, option, value, vars):
551 option, section, rawval, e.args[0]) from None
555 raise InterpolationDepthError(option, section, rawval)
558 def before_set(self, parser, section, option, value):
573 # Regular expressions for parsing section headers and options
660 """Return a list of section names, excluding [DEFAULT]"""
664 def add_section(self, section):
665 """Create a new section in the configuration.
667 Raise DuplicateSectionError if a section by the specified name
670 if section == self.default_section:
671 raise ValueError('Invalid section name: %r' % section)
673 if section in self._sections:
674 raise DuplicateSectionError(section)
675 self._sections[section] = self._dict()
676 self._proxies[section] = SectionProxy(self, section)
678 def has_section(self, section):
679 """Indicate whether the named section is present in the configuration.
681 The DEFAULT section is not acknowledged.
683 return section in self._sections
685 def options(self, section):
686 """Return a list of option names for the given section name."""
688 opts = self._sections[section].copy()
690 raise NoSectionError(section) from None
744 Keys are section names, values are dictionaries with keys and values
745 that should be present in the section. If the used dictionary type
749 reading, including section names, option names and keys.
755 for section, keys in dictionary.items():
756 section = str(section)
758 self.add_section(section)
760 if self._strict and section in elements_added:
762 elements_added.add(section)
767 if self._strict and (section, key) in elements_added:
768 raise DuplicateOptionError(section, key, source)
769 elements_added.add((section, key))
770 self.set(section, key, value)
781 def get(self, section, option, *, raw=False, vars=None, fallback=_UNSET):
782 """Get an option value for a given section.
785 in `vars` (if provided), `section`, and in `DEFAULTSECT` in that order.
794 The section DEFAULT is special.
797 d = self._unify_values(section, vars)
808 raise NoOptionError(option, section)
815 return self._interpolation.before_get(self, section, option, value,
818 def _get(self, section, conv, option, **kwargs):
819 return conv(self.get(section, option, **kwargs))
821 def _get_conv(self, section, option, conv, *, raw=False, vars=None,
824 return self._get(section, conv, option, raw=raw, vars=vars,
832 def getint(self, section, option, *, raw=False, vars=None,
834 return self._get_conv(section, option, int, raw=raw, vars=vars,
837 def getfloat(self, section, option, *, raw=False, vars=None,
839 return self._get_conv(section, option, float, raw=raw, vars=vars,
842 def getboolean(self, section, option, *, raw=False, vars=None,
844 return self._get_conv(section, option, self._convert_to_boolean,
847 def items(self, section=_UNSET, raw=False, vars=None):
848 """Return a list of (name, value) tuples for each option in a section.
856 The section DEFAULT is special.
858 if section is _UNSET:
862 d.update(self._sections[section])
864 if section != self.default_section:
865 raise NoSectionError(section)
872 section, option, d[option], d)
878 """Remove a section from the parser and return it as
879 a (section_name, section_proxy) tuple. If no section is present, raise
882 The section DEFAULT is never returned because it cannot be removed.
893 def has_option(self, section, option):
894 """Check for the existence of a given option in a given section.
895 If the specified `section` is None or an empty string, DEFAULT is
896 assumed. If the specified `section` does not exist, returns False."""
897 if not section or section == self.default_section:
900 elif section not in self._sections:
904 return (option in self._sections[section]
907 def set(self, section, option, value=None):
910 value = self._interpolation.before_set(self, section, option,
912 if not section or section == self.default_section:
916 sectdict = self._sections[section]
918 raise NoSectionError(section) from None
937 for section in self._sections:
938 self._write_section(fp, section,
939 self._sections[section].items(), d)
942 """Write a single section to the specified `fp`."""
954 def remove_option(self, section, option):
956 if not section or section == self.default_section:
960 sectdict = self._sections[section]
962 raise NoSectionError(section) from None
969 def remove_section(self, section):
970 """Remove a file section."""
971 existed = section in self._sections
973 del self._sections[section]
974 del self._proxies[section]
984 # the section.
997 raise ValueError("Cannot remove the default section.")
1006 return len(self._sections) + 1 # the default section
1015 Each section in a configuration file contains a header, indicated by
1027 section names. Please note that comments get stripped off when reading configuration files.
1077 # a section header or option header?
1080 # is it a section header?
1099 # no section header in the file?
1138 for section, options in all_sections:
1143 section,
1158 def _unify_values(self, section, vars):
1160 the 'section' which takes priority over the DEFAULTSECT.
1165 sectiondict = self._sections[section]
1167 if section != self.default_section:
1168 raise NoSectionError(section) from None
1185 def _validate_value_types(self, *, section="", option="", value=""):
1198 if not isinstance(section, str):
1199 raise TypeError("section names must be strings")
1216 def set(self, section, option, value=None):
1220 super().set(section, option, value)
1222 def add_section(self, section):
1223 """Create a new section in the configuration. Extends
1224 RawConfigParser.add_section by validating if the section name is
1226 self._validate_value_types(section=section)
1227 super().add_section(section)
1257 """A proxy for a single section from a parser."""
1260 """Creates a view on a section of the specified `name` in `parser`."""
1307 # The name of the section on a proxy is read-only.
1327 """Enables reuse of get*() methods between the parser and section proxies.
1331 section proxies to find and use the implementation on the parser class.