• 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
729 Keys are section names, values are dictionaries with keys and values
730 that should be present in the section. If the used dictionary type
734 reading, including section names, option names and keys.
740 for section, keys in dictionary.items():
741 section = str(section)
743 self.add_section(section)
745 if self._strict and section in elements_added:
747 elements_added.add(section)
752 if self._strict and (section, key) in elements_added:
753 raise DuplicateOptionError(section, key, source)
754 elements_added.add((section, key))
755 self.set(section, key, value)
766 def get(self, section, option, *, raw=False, vars=None, fallback=_UNSET): argument
767 """Get an option value for a given section.
770 in `vars' (if provided), `section', and in `DEFAULTSECT' in that order.
779 The section DEFAULT is special.
782 d = self._unify_values(section, vars)
793 raise NoOptionError(option, section)
800 return self._interpolation.before_get(self, section, option, value,
803 def _get(self, section, conv, option, **kwargs): argument
804 return conv(self.get(section, option, **kwargs))
806 def _get_conv(self, section, option, conv, *, raw=False, vars=None, argument
809 return self._get(section, conv, option, raw=raw, vars=vars,
817 def getint(self, section, option, *, raw=False, vars=None, argument
819 return self._get_conv(section, option, int, raw=raw, vars=vars,
822 def getfloat(self, section, option, *, raw=False, vars=None, argument
824 return self._get_conv(section, option, float, raw=raw, vars=vars,
827 def getboolean(self, section, option, *, raw=False, vars=None, argument
829 return self._get_conv(section, option, self._convert_to_boolean,
832 def items(self, section=_UNSET, raw=False, vars=None): argument
833 """Return a list of (name, value) tuples for each option in a section.
841 The section DEFAULT is special.
843 if section is _UNSET:
847 d.update(self._sections[section])
849 if section != self.default_section:
850 raise NoSectionError(section)
857 section, option, d[option], d)
863 """Remove a section from the parser and return it as
864 a (section_name, section_proxy) tuple. If no section is present, raise
867 The section DEFAULT is never returned because it cannot be removed.
878 def has_option(self, section, option): argument
879 """Check for the existence of a given option in a given section.
880 If the specified `section' is None or an empty string, DEFAULT is
881 assumed. If the specified `section' does not exist, returns False."""
882 if not section or section == self.default_section:
885 elif section not in self._sections:
889 return (option in self._sections[section]
892 def set(self, section, option, value=None): argument
895 value = self._interpolation.before_set(self, section, option,
897 if not section or section == self.default_section:
901 sectdict = self._sections[section]
903 raise NoSectionError(section) from None
922 for section in self._sections:
923 self._write_section(fp, section,
924 self._sections[section].items(), d)
927 """Write a single section to the specified `fp'."""
939 def remove_option(self, section, option): argument
941 if not section or section == self.default_section:
945 sectdict = self._sections[section]
947 raise NoSectionError(section) from None
954 def remove_section(self, section): argument
955 """Remove a file section."""
956 existed = section in self._sections
958 del self._sections[section]
959 del self._proxies[section]
969 # the section.
982 raise ValueError("Cannot remove the default section.")
991 return len(self._sections) + 1 # the default section
1000 Each section in a configuration file contains a header, indicated by
1012 section names. Please note that comments get stripped off when reading configuration files.
1062 # a section header or option header?
1065 # is it a section header?
1084 # no section header in the file?
1123 for section, options in all_sections:
1128 section,
1143 def _unify_values(self, section, vars): argument
1145 the 'section' which takes priority over the DEFAULTSECT.
1150 sectiondict = self._sections[section]
1152 if section != self.default_section:
1153 raise NoSectionError(section) from None
1170 def _validate_value_types(self, *, section="", option="", value=""): argument
1183 if not isinstance(section, str):
1184 raise TypeError("section names must be strings")
1201 def set(self, section, option, value=None): argument
1205 super().set(section, option, value)
1207 def add_section(self, section): argument
1208 """Create a new section in the configuration. Extends
1209 RawConfigParser.add_section by validating if the section name is
1211 self._validate_value_types(section=section)
1212 super().add_section(section)
1242 """A proxy for a single section from a parser."""
1245 """Creates a view on a section of the specified `name` in `parser`."""
1254 return '<Section: {}>'.format(self._name)
1292 # The name of the section on a proxy is read-only.
1312 """Enables reuse of get*() methods between the parser and section proxies.
1316 section proxies to find and use the implementation on the parser class.