• Home
  • Raw
  • Download

Lines Matching full: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 without section are accepted: the section for these is
76 Return all the configuration section names, sans DEFAULT.
78 has_section(section)
79 Return whether the given section exists.
81 has_option(section, option)
82 Return whether the given option exists in the given section.
84 options(section)
85 Return list of configuration options for the named section.
101 Read configuration from a dictionary. Keys are section names,
103 in the section. If the used dictionary type preserves order, sections
107 get(section, option, raw=False, vars=None, fallback=_UNSET)
110 constructor and the DEFAULT section. Additional substitutions may be
115 getint(section, options, raw=False, vars=None, fallback=_UNSET)
118 getfloat(section, options, raw=False, vars=None, fallback=_UNSET)
121 getboolean(section, options, raw=False, vars=None, fallback=_UNSET)
126 items(section=_UNSET, raw=False, vars=None)
127 If section is given, return a list of tuples with (name, value) for
128 each option in the section. Otherwise, return a list of tuples with
129 (section_name, section_proxy) for each section, including DEFAULTSECT.
131 remove_section(section)
132 Remove the given file section and all its options.
134 remove_option(section, option)
135 Remove the given option from the given section.
137 set(section, option, value)
191 """Raised when no section matches a requested option."""
193 def __init__(self, section): argument
194 Error.__init__(self, 'No section: %r' % (section,))
195 self.section = section
196 self.args = (section, )
200 """Raised when a section is repeated in an input source.
203 using the API or in strict parsers when a section is found more than once
207 def __init__(self, section, source=None, lineno=None): argument
208 msg = [repr(section), " already exists"]
213 message.append(": section ")
217 msg.insert(0, "Section ")
219 self.section = section
222 self.args = (section, source, lineno)
232 def __init__(self, section, option, source=None, lineno=None): argument
233 msg = [repr(option), " in section ", repr(section),
245 self.section = section
249 self.args = (section, option, source, lineno)
255 def __init__(self, option, section): argument
256 Error.__init__(self, "No option %r in section: %r" %
257 (option, section))
259 self.section = section
260 self.args = (option, section)
266 def __init__(self, option, section, msg): argument
269 self.section = section
270 self.args = (option, section, msg)
276 def __init__(self, option, section, rawval, reference): argument
277 msg = ("Bad value substitution: option {!r} in section {!r} contains "
279 "Raw value: {!r}".format(option, section, reference, rawval))
280 InterpolationError.__init__(self, option, section, msg)
282 self.args = (option, section, rawval, reference)
296 def __init__(self, option, section, rawval): argument
298 "in section {!r} contains an interpolation key which "
300 "".format(option, section, MAX_INTERPOLATION_DEPTH,
302 InterpolationError.__init__(self, option, section, msg)
303 self.args = (option, section, rawval)
339 """Raised when a key-value pair is found before any section header."""
344 'File contains no section headers.\nfile: %r, line: %d\n%r' %
383 def before_get(self, parser, section, option, value, defaults): argument
386 def before_set(self, parser, section, option, value): argument
389 def before_read(self, parser, section, option, value): argument
392 def before_write(self, parser, section, option, value): argument
400 the same section, or values in the special default section.
413 def before_get(self, parser, section, option, value, defaults): argument
415 self._interpolate_some(parser, option, L, value, section, defaults, 1)
418 def before_set(self, parser, section, option, value): argument
426 def _interpolate_some(self, parser, option, accum, rest, section, map, argument
428 rawval = parser.get(section, option, raw=True, fallback=rest)
430 raise InterpolationDepthError(option, section, rawval)
447 raise InterpolationSyntaxError(option, section,
455 option, section, rawval, var) from None
458 section, map, depth + 1)
463 option, section,
474 def before_get(self, parser, section, option, value, defaults): argument
476 self._interpolate_some(parser, option, L, value, section, defaults, 1)
479 def before_set(self, parser, section, option, value): argument
487 def _interpolate_some(self, parser, option, accum, rest, section, map, argument
489 rawval = parser.get(section, option, raw=True, fallback=rest)
491 raise InterpolationDepthError(option, section, rawval)
508 raise InterpolationSyntaxError(option, section,
512 sect = section
524 option, section,
528 option, section, rawval, ":".join(path)) from None
537 option, section,
591 # Regular expressions for parsing section headers and options
682 """Return a list of section names, excluding [DEFAULT]"""
686 def add_section(self, section): argument
687 """Create a new section in the configuration.
689 Raise DuplicateSectionError if a section by the specified name
692 if section == self.default_section:
693 raise ValueError('Invalid section name: %r' % section)
695 if section in self._sections:
696 raise DuplicateSectionError(section)
697 self._sections[section] = self._dict()
698 self._proxies[section] = SectionProxy(self, section)
700 def has_section(self, section): argument
701 """Indicate whether the named section is present in the configuration.
703 The DEFAULT section is not acknowledged.
705 return section in self._sections
707 def options(self, section): argument
708 """Return a list of option names for the given section name."""
710 opts = self._sections[section].copy()
712 raise NoSectionError(section) from None
766 Keys are section names, values are dictionaries with keys and values
767 that should be present in the section. If the used dictionary type
771 reading, including section names, option names and keys.
777 for section, keys in dictionary.items():
778 section = str(section)
780 self.add_section(section)
782 if self._strict and section in elements_added:
784 elements_added.add(section)
789 if self._strict and (section, key) in elements_added:
790 raise DuplicateOptionError(section, key, source)
791 elements_added.add((section, key))
792 self.set(section, key, value)
794 def get(self, section, option, *, raw=False, vars=None, fallback=_UNSET): argument
795 """Get an option value for a given section.
798 in `vars` (if provided), `section`, and in `DEFAULTSECT` in that order.
807 The section DEFAULT is special.
810 d = self._unify_values(section, vars)
821 raise NoOptionError(option, section)
828 return self._interpolation.before_get(self, section, option, value,
831 def _get(self, section, conv, option, **kwargs): argument
832 return conv(self.get(section, option, **kwargs))
834 def _get_conv(self, section, option, conv, *, raw=False, vars=None, argument
837 return self._get(section, conv, option, raw=raw, vars=vars,
845 def getint(self, section, option, *, raw=False, vars=None, argument
847 return self._get_conv(section, option, int, raw=raw, vars=vars,
850 def getfloat(self, section, option, *, raw=False, vars=None, argument
852 return self._get_conv(section, option, float, raw=raw, vars=vars,
855 def getboolean(self, section, option, *, raw=False, vars=None, argument
857 return self._get_conv(section, option, self._convert_to_boolean,
860 def items(self, section=_UNSET, raw=False, vars=None): argument
861 """Return a list of (name, value) tuples for each option in a section.
869 The section DEFAULT is special.
871 if section is _UNSET:
875 d.update(self._sections[section])
877 if section != self.default_section:
878 raise NoSectionError(section)
885 section, option, d[option], d)
891 """Remove a section from the parser and return it as
892 a (section_name, section_proxy) tuple. If no section is present, raise
895 The section DEFAULT is never returned because it cannot be removed.
906 def has_option(self, section, option): argument
907 """Check for the existence of a given option in a given section.
908 If the specified `section` is None or an empty string, DEFAULT is
909 assumed. If the specified `section` does not exist, returns False."""
910 if not section or section == self.default_section:
913 elif section not in self._sections:
917 return (option in self._sections[section]
920 def set(self, section, option, value=None): argument
923 value = self._interpolation.before_set(self, section, option,
925 if not section or section == self.default_section:
929 sectdict = self._sections[section]
931 raise NoSectionError(section) from None
953 for section in self._sections:
954 if section is UNNAMED_SECTION:
956 self._write_section(fp, section,
957 self._sections[section].items(), d)
960 """Write a single section to the specified `fp'."""
973 def remove_option(self, section, option): argument
975 if not section or section == self.default_section:
979 sectdict = self._sections[section]
981 raise NoSectionError(section) from None
988 def remove_section(self, section): argument
989 """Remove a file section."""
990 existed = section in self._sections
992 del self._sections[section]
993 del self._proxies[section]
1003 # the section.
1016 raise ValueError("Cannot remove the default section.")
1025 return len(self._sections) + 1 # the default section
1034 Each section in a configuration file contains a header, indicated by
1046 section names. Please note that comments get stripped off when reading configuration files.
1094 # a section header or option header?
1103 # is it a section header?
1164 for section, options in all_sections:
1169 section,
1178 def _unify_values(self, section, vars): argument
1180 the 'section' which takes priority over the DEFAULTSECT.
1185 sectiondict = self._sections[section]
1187 if section != self.default_section:
1188 raise NoSectionError(section) from None
1205 def _validate_value_types(self, *, section="", option="", value=""): argument
1218 if not isinstance(section, str):
1219 raise TypeError("section names must be strings")
1236 def set(self, section, option, value=None): argument
1240 super().set(section, option, value)
1242 def add_section(self, section): argument
1243 """Create a new section in the configuration. Extends
1244 RawConfigParser.add_section by validating if the section name is
1246 self._validate_value_types(section=section)
1247 super().add_section(section)
1264 """A proxy for a single section from a parser."""
1267 """Creates a view on a section of the specified `name` in `parser`."""
1276 return '<Section: {}>'.format(self._name)
1314 # The name of the section on a proxy is read-only.
1334 """Enables reuse of get*() methods between the parser and section proxies.
1338 section proxies to find and use the implementation on the parser class.