• Home
  • Raw
  • Download

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)
182 """Raised when no section matches a requested option."""
184 def __init__(self, section): argument
185 Error.__init__(self, 'No section: %r' % (section,))
186 self.section = section
187 self.args = (section, )
191 """Raised when a section is repeated in an input source.
194 using the API or in strict parsers when a section is found more than once
198 def __init__(self, section, source=None, lineno=None): argument
199 msg = [repr(section), " already exists"]
204 message.append(": section ")
208 msg.insert(0, "Section ")
210 self.section = section
213 self.args = (section, source, lineno)
223 def __init__(self, section, option, source=None, lineno=None): argument
224 msg = [repr(option), " in section ", repr(section),
236 self.section = section
240 self.args = (section, option, source, lineno)
246 def __init__(self, option, section): argument
247 Error.__init__(self, "No option %r in section: %r" %
248 (option, section))
250 self.section = section
251 self.args = (option, section)
257 def __init__(self, option, section, msg): argument
260 self.section = section
261 self.args = (option, section, msg)
267 def __init__(self, option, section, rawval, reference): argument
268 msg = ("Bad value substitution: option {!r} in section {!r} contains "
270 "Raw value: {!r}".format(option, section, reference, rawval))
271 InterpolationError.__init__(self, option, section, msg)
273 self.args = (option, section, rawval, reference)
287 def __init__(self, option, section, rawval): argument
289 "in section {!r} contains an interpolation key which "
291 "".format(option, section, MAX_INTERPOLATION_DEPTH,
293 InterpolationError.__init__(self, option, section, msg)
294 self.args = (option, section, rawval)
341 """Raised when a key-value pair is found before any section header."""
346 'File contains no section headers.\nfile: %r, line: %d\n%r' %
363 def before_get(self, parser, section, option, value, defaults): argument
366 def before_set(self, parser, section, option, value): argument
369 def before_read(self, parser, section, option, value): argument
372 def before_write(self, parser, section, option, value): argument
380 the same section, or values in the special default section.
393 def before_get(self, parser, section, option, value, defaults): argument
395 self._interpolate_some(parser, option, L, value, section, defaults, 1)
398 def before_set(self, parser, section, option, value): argument
406 def _interpolate_some(self, parser, option, accum, rest, section, map, argument
408 rawval = parser.get(section, option, raw=True, fallback=rest)
410 raise InterpolationDepthError(option, section, rawval)
427 raise InterpolationSyntaxError(option, section,
435 option, section, rawval, var) from None
438 section, map, depth + 1)
443 option, section,
454 def before_get(self, parser, section, option, value, defaults): argument
456 self._interpolate_some(parser, option, L, value, section, defaults, 1)
459 def before_set(self, parser, section, option, value): argument
467 def _interpolate_some(self, parser, option, accum, rest, section, map, argument
469 rawval = parser.get(section, option, raw=True, fallback=rest)
471 raise InterpolationDepthError(option, section, rawval)
488 raise InterpolationSyntaxError(option, section,
492 sect = section
504 option, section,
508 option, section, rawval, ":".join(path)) from None
517 option, section,
528 def before_get(self, parser, section, option, value, vars): argument
541 option, section, rawval, e.args[0]) from None
545 raise InterpolationDepthError(option, section, rawval)
548 def before_set(self, parser, section, option, value): argument
563 # Regular expressions for parsing section headers and options
645 """Return a list of section names, excluding [DEFAULT]"""
649 def add_section(self, section): argument
650 """Create a new section in the configuration.
652 Raise DuplicateSectionError if a section by the specified name
655 if section == self.default_section:
656 raise ValueError('Invalid section name: %r' % section)
658 if section in self._sections:
659 raise DuplicateSectionError(section)
660 self._sections[section] = self._dict()
661 self._proxies[section] = SectionProxy(self, section)
663 def has_section(self, section): argument
664 """Indicate whether the named section is present in the configuration.
666 The DEFAULT section is not acknowledged.
668 return section in self._sections
670 def options(self, section): argument
671 """Return a list of option names for the given section name."""
673 opts = self._sections[section].copy()
675 raise NoSectionError(section) from None
728 Keys are section names, values are dictionaries with keys and values
729 that should be present in the section. If the used dictionary type
733 reading, including section names, option names and keys.
739 for section, keys in dictionary.items():
740 section = str(section)
742 self.add_section(section)
744 if self._strict and section in elements_added:
746 elements_added.add(section)
751 if self._strict and (section, key) in elements_added:
752 raise DuplicateOptionError(section, key, source)
753 elements_added.add((section, key))
754 self.set(section, key, value)
765 def get(self, section, option, *, raw=False, vars=None, fallback=_UNSET): argument
766 """Get an option value for a given section.
769 in `vars' (if provided), `section', and in `DEFAULTSECT' in that order.
778 The section DEFAULT is special.
781 d = self._unify_values(section, vars)
792 raise NoOptionError(option, section)
799 return self._interpolation.before_get(self, section, option, value,
802 def _get(self, section, conv, option, **kwargs): argument
803 return conv(self.get(section, option, **kwargs))
805 def _get_conv(self, section, option, conv, *, raw=False, vars=None, argument
808 return self._get(section, conv, option, raw=raw, vars=vars,
816 def getint(self, section, option, *, raw=False, vars=None, argument
818 return self._get_conv(section, option, int, raw=raw, vars=vars,
821 def getfloat(self, section, option, *, raw=False, vars=None, argument
823 return self._get_conv(section, option, float, raw=raw, vars=vars,
826 def getboolean(self, section, option, *, raw=False, vars=None, argument
828 return self._get_conv(section, option, self._convert_to_boolean,
831 def items(self, section=_UNSET, raw=False, vars=None): argument
832 """Return a list of (name, value) tuples for each option in a section.
840 The section DEFAULT is special.
842 if section is _UNSET:
846 d.update(self._sections[section])
848 if section != self.default_section:
849 raise NoSectionError(section)
856 section, option, d[option], d)
862 """Remove a section from the parser and return it as
863 a (section_name, section_proxy) tuple. If no section is present, raise
866 The section DEFAULT is never returned because it cannot be removed.
877 def has_option(self, section, option): argument
878 """Check for the existence of a given option in a given section.
879 If the specified `section' is None or an empty string, DEFAULT is
880 assumed. If the specified `section' does not exist, returns False."""
881 if not section or section == self.default_section:
884 elif section not in self._sections:
888 return (option in self._sections[section]
891 def set(self, section, option, value=None): argument
894 value = self._interpolation.before_set(self, section, option,
896 if not section or section == self.default_section:
900 sectdict = self._sections[section]
902 raise NoSectionError(section) from None
918 for section in self._sections:
919 self._write_section(fp, section,
920 self._sections[section].items(), d)
923 """Write a single section to the specified `fp'."""
935 def remove_option(self, section, option): argument
937 if not section or section == self.default_section:
941 sectdict = self._sections[section]
943 raise NoSectionError(section) from None
950 def remove_section(self, section): argument
951 """Remove a file section."""
952 existed = section in self._sections
954 del self._sections[section]
955 del self._proxies[section]
965 # the section.
978 raise ValueError("Cannot remove the default section.")
987 return len(self._sections) + 1 # the default section
996 Each section in a configuration file contains a header, indicated by
1008 section names.
1058 # a section header or option header?
1061 # is it a section header?
1080 # no section header in the file?
1119 for section, options in all_sections:
1124 section,
1139 def _unify_values(self, section, vars): argument
1141 the 'section' which takes priority over the DEFAULTSECT.
1146 sectiondict = self._sections[section]
1148 if section != self.default_section:
1149 raise NoSectionError(section) from None
1166 def _validate_value_types(self, *, section="", option="", value=""): argument
1179 if not isinstance(section, str):
1180 raise TypeError("section names must be strings")
1197 def set(self, section, option, value=None): argument
1201 super().set(section, option, value)
1203 def add_section(self, section): argument
1204 """Create a new section in the configuration. Extends
1205 RawConfigParser.add_section by validating if the section name is
1207 self._validate_value_types(section=section)
1208 super().add_section(section)
1238 """A proxy for a single section from a parser."""
1241 """Creates a view on a section of the specified `name` in `parser`."""
1250 return '<Section: {}>'.format(self._name)
1288 # The name of the section on a proxy is read-only.
1308 """Enables reuse of get*() methods between the parser and section proxies.
1312 section proxies to find and use the implementation on the parser class.