|
|
79af3c |
From 85001e92986b3e3f6b7dcbbe5d71cde99962fd58 Mon Sep 17 00:00:00 2001
|
|
|
79af3c |
From: Christian Heimes <cheimes@redhat.com>
|
|
|
79af3c |
Date: Tue, 28 Mar 2017 17:49:39 +0200
|
|
|
79af3c |
Subject: [PATCH 1/4] Vendor configparser-3.5.0
|
|
|
79af3c |
|
|
|
79af3c |
Signed-off-by: Christian Heimes <cheimes@redhat.com>
|
|
|
79af3c |
---
|
|
|
79af3c |
custodia/vendor/backports/__init__.py | 11 +
|
|
|
79af3c |
custodia/vendor/backports/configparser/__init__.py | 1390 ++++++++++++++++++++
|
|
|
79af3c |
custodia/vendor/backports/configparser/helpers.py | 171 +++
|
|
|
79af3c |
custodia/vendor/configparser.py | 52 +
|
|
|
79af3c |
4 files changed, 1624 insertions(+)
|
|
|
79af3c |
create mode 100644 custodia/vendor/backports/__init__.py
|
|
|
79af3c |
create mode 100644 custodia/vendor/backports/configparser/__init__.py
|
|
|
79af3c |
create mode 100644 custodia/vendor/backports/configparser/helpers.py
|
|
|
79af3c |
create mode 100644 custodia/vendor/configparser.py
|
|
|
79af3c |
|
|
|
79af3c |
diff --git a/custodia/vendor/backports/__init__.py b/custodia/vendor/backports/__init__.py
|
|
|
79af3c |
new file mode 100644
|
|
|
79af3c |
index 0000000..f84d25c
|
|
|
79af3c |
--- /dev/null
|
|
|
79af3c |
+++ b/custodia/vendor/backports/__init__.py
|
|
|
79af3c |
@@ -0,0 +1,11 @@
|
|
|
79af3c |
+# A Python "namespace package" http://www.python.org/dev/peps/pep-0382/
|
|
|
79af3c |
+# This always goes inside of a namespace package's __init__.py
|
|
|
79af3c |
+
|
|
|
79af3c |
+from pkgutil import extend_path
|
|
|
79af3c |
+__path__ = extend_path(__path__, __name__)
|
|
|
79af3c |
+
|
|
|
79af3c |
+try:
|
|
|
79af3c |
+ import pkg_resources
|
|
|
79af3c |
+ pkg_resources.declare_namespace(__name__)
|
|
|
79af3c |
+except ImportError:
|
|
|
79af3c |
+ pass
|
|
|
79af3c |
diff --git a/custodia/vendor/backports/configparser/__init__.py b/custodia/vendor/backports/configparser/__init__.py
|
|
|
79af3c |
new file mode 100644
|
|
|
79af3c |
index 0000000..06d7a08
|
|
|
79af3c |
--- /dev/null
|
|
|
79af3c |
+++ b/custodia/vendor/backports/configparser/__init__.py
|
|
|
79af3c |
@@ -0,0 +1,1390 @@
|
|
|
79af3c |
+#!/usr/bin/env python
|
|
|
79af3c |
+# -*- coding: utf-8 -*-
|
|
|
79af3c |
+
|
|
|
79af3c |
+"""Configuration file parser.
|
|
|
79af3c |
+
|
|
|
79af3c |
+A configuration file consists of sections, lead by a "[section]" header,
|
|
|
79af3c |
+and followed by "name: value" entries, with continuations and such in
|
|
|
79af3c |
+the style of RFC 822.
|
|
|
79af3c |
+
|
|
|
79af3c |
+Intrinsic defaults can be specified by passing them into the
|
|
|
79af3c |
+ConfigParser constructor as a dictionary.
|
|
|
79af3c |
+
|
|
|
79af3c |
+class:
|
|
|
79af3c |
+
|
|
|
79af3c |
+ConfigParser -- responsible for parsing a list of
|
|
|
79af3c |
+ configuration files, and managing the parsed database.
|
|
|
79af3c |
+
|
|
|
79af3c |
+ methods:
|
|
|
79af3c |
+
|
|
|
79af3c |
+ __init__(defaults=None, dict_type=_default_dict, allow_no_value=False,
|
|
|
79af3c |
+ delimiters=('=', ':'), comment_prefixes=('#', ';'),
|
|
|
79af3c |
+ inline_comment_prefixes=None, strict=True,
|
|
|
79af3c |
+ empty_lines_in_values=True, default_section='DEFAULT',
|
|
|
79af3c |
+ interpolation=<unset>, converters=<unset>):
|
|
|
79af3c |
+ Create the parser. When `defaults' is given, it is initialized into the
|
|
|
79af3c |
+ dictionary or intrinsic defaults. The keys must be strings, the values
|
|
|
79af3c |
+ must be appropriate for %()s string interpolation.
|
|
|
79af3c |
+
|
|
|
79af3c |
+ When `dict_type' is given, it will be used to create the dictionary
|
|
|
79af3c |
+ objects for the list of sections, for the options within a section, and
|
|
|
79af3c |
+ for the default values.
|
|
|
79af3c |
+
|
|
|
79af3c |
+ When `delimiters' is given, it will be used as the set of substrings
|
|
|
79af3c |
+ that divide keys from values.
|
|
|
79af3c |
+
|
|
|
79af3c |
+ When `comment_prefixes' is given, it will be used as the set of
|
|
|
79af3c |
+ substrings that prefix comments in empty lines. Comments can be
|
|
|
79af3c |
+ indented.
|
|
|
79af3c |
+
|
|
|
79af3c |
+ When `inline_comment_prefixes' is given, it will be used as the set of
|
|
|
79af3c |
+ substrings that prefix comments in non-empty lines.
|
|
|
79af3c |
+
|
|
|
79af3c |
+ When `strict` is True, the parser won't allow for any section or option
|
|
|
79af3c |
+ duplicates while reading from a single source (file, string or
|
|
|
79af3c |
+ dictionary). Default is True.
|
|
|
79af3c |
+
|
|
|
79af3c |
+ When `empty_lines_in_values' is False (default: True), each empty line
|
|
|
79af3c |
+ marks the end of an option. Otherwise, internal empty lines of
|
|
|
79af3c |
+ a multiline option are kept as part of the value.
|
|
|
79af3c |
+
|
|
|
79af3c |
+ When `allow_no_value' is True (default: False), options without
|
|
|
79af3c |
+ values are accepted; the value presented for these is None.
|
|
|
79af3c |
+
|
|
|
79af3c |
+ sections()
|
|
|
79af3c |
+ Return all the configuration section names, sans DEFAULT.
|
|
|
79af3c |
+
|
|
|
79af3c |
+ has_section(section)
|
|
|
79af3c |
+ Return whether the given section exists.
|
|
|
79af3c |
+
|
|
|
79af3c |
+ has_option(section, option)
|
|
|
79af3c |
+ Return whether the given option exists in the given section.
|
|
|
79af3c |
+
|
|
|
79af3c |
+ options(section)
|
|
|
79af3c |
+ Return list of configuration options for the named section.
|
|
|
79af3c |
+
|
|
|
79af3c |
+ read(filenames, encoding=None)
|
|
|
79af3c |
+ Read and parse the list of named configuration files, given by
|
|
|
79af3c |
+ name. A single filename is also allowed. Non-existing files
|
|
|
79af3c |
+ are ignored. Return list of successfully read files.
|
|
|
79af3c |
+
|
|
|
79af3c |
+ read_file(f, filename=None)
|
|
|
79af3c |
+ Read and parse one configuration file, given as a file object.
|
|
|
79af3c |
+ The filename defaults to f.name; it is only used in error
|
|
|
79af3c |
+ messages (if f has no `name' attribute, the string `' is used).
|
|
|
79af3c |
+
|
|
|
79af3c |
+ read_string(string)
|
|
|
79af3c |
+ Read configuration from a given string.
|
|
|
79af3c |
+
|
|
|
79af3c |
+ read_dict(dictionary)
|
|
|
79af3c |
+ Read configuration from a dictionary. Keys are section names,
|
|
|
79af3c |
+ values are dictionaries with keys and values that should be present
|
|
|
79af3c |
+ in the section. If the used dictionary type preserves order, sections
|
|
|
79af3c |
+ and their keys will be added in order. Values are automatically
|
|
|
79af3c |
+ converted to strings.
|
|
|
79af3c |
+
|
|
|
79af3c |
+ get(section, option, raw=False, vars=None, fallback=_UNSET)
|
|
|
79af3c |
+ Return a string value for the named option. All % interpolations are
|
|
|
79af3c |
+ expanded in the return values, based on the defaults passed into the
|
|
|
79af3c |
+ constructor and the DEFAULT section. Additional substitutions may be
|
|
|
79af3c |
+ provided using the `vars' argument, which must be a dictionary whose
|
|
|
79af3c |
+ contents override any pre-existing defaults. If `option' is a key in
|
|
|
79af3c |
+ `vars', the value from `vars' is used.
|
|
|
79af3c |
+
|
|
|
79af3c |
+ getint(section, options, raw=False, vars=None, fallback=_UNSET)
|
|
|
79af3c |
+ Like get(), but convert value to an integer.
|
|
|
79af3c |
+
|
|
|
79af3c |
+ getfloat(section, options, raw=False, vars=None, fallback=_UNSET)
|
|
|
79af3c |
+ Like get(), but convert value to a float.
|
|
|
79af3c |
+
|
|
|
79af3c |
+ getboolean(section, options, raw=False, vars=None, fallback=_UNSET)
|
|
|
79af3c |
+ Like get(), but convert value to a boolean (currently case
|
|
|
79af3c |
+ insensitively defined as 0, false, no, off for False, and 1, true,
|
|
|
79af3c |
+ yes, on for True). Returns False or True.
|
|
|
79af3c |
+
|
|
|
79af3c |
+ items(section=_UNSET, raw=False, vars=None)
|
|
|
79af3c |
+ If section is given, return a list of tuples with (name, value) for
|
|
|
79af3c |
+ each option in the section. Otherwise, return a list of tuples with
|
|
|
79af3c |
+ (section_name, section_proxy) for each section, including DEFAULTSECT.
|
|
|
79af3c |
+
|
|
|
79af3c |
+ remove_section(section)
|
|
|
79af3c |
+ Remove the given file section and all its options.
|
|
|
79af3c |
+
|
|
|
79af3c |
+ remove_option(section, option)
|
|
|
79af3c |
+ Remove the given option from the given section.
|
|
|
79af3c |
+
|
|
|
79af3c |
+ set(section, option, value)
|
|
|
79af3c |
+ Set the given option.
|
|
|
79af3c |
+
|
|
|
79af3c |
+ write(fp, space_around_delimiters=True)
|
|
|
79af3c |
+ Write the configuration state in .ini format. If
|
|
|
79af3c |
+ `space_around_delimiters' is True (the default), delimiters
|
|
|
79af3c |
+ between keys and values are surrounded by spaces.
|
|
|
79af3c |
+"""
|
|
|
79af3c |
+
|
|
|
79af3c |
+from __future__ import absolute_import
|
|
|
79af3c |
+from __future__ import division
|
|
|
79af3c |
+from __future__ import print_function
|
|
|
79af3c |
+from __future__ import unicode_literals
|
|
|
79af3c |
+
|
|
|
79af3c |
+from collections import MutableMapping
|
|
|
79af3c |
+import functools
|
|
|
79af3c |
+import io
|
|
|
79af3c |
+import itertools
|
|
|
79af3c |
+import re
|
|
|
79af3c |
+import sys
|
|
|
79af3c |
+import warnings
|
|
|
79af3c |
+
|
|
|
79af3c |
+from backports.configparser.helpers import OrderedDict as _default_dict
|
|
|
79af3c |
+from backports.configparser.helpers import ChainMap as _ChainMap
|
|
|
79af3c |
+from backports.configparser.helpers import from_none, open, str, PY2
|
|
|
79af3c |
+
|
|
|
79af3c |
+__all__ = ["NoSectionError", "DuplicateOptionError", "DuplicateSectionError",
|
|
|
79af3c |
+ "NoOptionError", "InterpolationError", "InterpolationDepthError",
|
|
|
79af3c |
+ "InterpolationMissingOptionError", "InterpolationSyntaxError",
|
|
|
79af3c |
+ "ParsingError", "MissingSectionHeaderError",
|
|
|
79af3c |
+ "ConfigParser", "SafeConfigParser", "RawConfigParser",
|
|
|
79af3c |
+ "Interpolation", "BasicInterpolation", "ExtendedInterpolation",
|
|
|
79af3c |
+ "LegacyInterpolation", "SectionProxy", "ConverterMapping",
|
|
|
79af3c |
+ "DEFAULTSECT", "MAX_INTERPOLATION_DEPTH"]
|
|
|
79af3c |
+
|
|
|
79af3c |
+DEFAULTSECT = "DEFAULT"
|
|
|
79af3c |
+
|
|
|
79af3c |
+MAX_INTERPOLATION_DEPTH = 10
|
|
|
79af3c |
+
|
|
|
79af3c |
+
|
|
|
79af3c |
+# exception classes
|
|
|
79af3c |
+class Error(Exception):
|
|
|
79af3c |
+ """Base class for ConfigParser exceptions."""
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def __init__(self, msg=''):
|
|
|
79af3c |
+ self.message = msg
|
|
|
79af3c |
+ Exception.__init__(self, msg)
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def __repr__(self):
|
|
|
79af3c |
+ return self.message
|
|
|
79af3c |
+
|
|
|
79af3c |
+ __str__ = __repr__
|
|
|
79af3c |
+
|
|
|
79af3c |
+
|
|
|
79af3c |
+class NoSectionError(Error):
|
|
|
79af3c |
+ """Raised when no section matches a requested option."""
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def __init__(self, section):
|
|
|
79af3c |
+ Error.__init__(self, 'No section: %r' % (section,))
|
|
|
79af3c |
+ self.section = section
|
|
|
79af3c |
+ self.args = (section, )
|
|
|
79af3c |
+
|
|
|
79af3c |
+
|
|
|
79af3c |
+class DuplicateSectionError(Error):
|
|
|
79af3c |
+ """Raised when a section is repeated in an input source.
|
|
|
79af3c |
+
|
|
|
79af3c |
+ Possible repetitions that raise this exception are: multiple creation
|
|
|
79af3c |
+ using the API or in strict parsers when a section is found more than once
|
|
|
79af3c |
+ in a single input file, string or dictionary.
|
|
|
79af3c |
+ """
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def __init__(self, section, source=None, lineno=None):
|
|
|
79af3c |
+ msg = [repr(section), " already exists"]
|
|
|
79af3c |
+ if source is not None:
|
|
|
79af3c |
+ message = ["While reading from ", repr(source)]
|
|
|
79af3c |
+ if lineno is not None:
|
|
|
79af3c |
+ message.append(" [line {0:2d}]".format(lineno))
|
|
|
79af3c |
+ message.append(": section ")
|
|
|
79af3c |
+ message.extend(msg)
|
|
|
79af3c |
+ msg = message
|
|
|
79af3c |
+ else:
|
|
|
79af3c |
+ msg.insert(0, "Section ")
|
|
|
79af3c |
+ Error.__init__(self, "".join(msg))
|
|
|
79af3c |
+ self.section = section
|
|
|
79af3c |
+ self.source = source
|
|
|
79af3c |
+ self.lineno = lineno
|
|
|
79af3c |
+ self.args = (section, source, lineno)
|
|
|
79af3c |
+
|
|
|
79af3c |
+
|
|
|
79af3c |
+class DuplicateOptionError(Error):
|
|
|
79af3c |
+ """Raised by strict parsers when an option is repeated in an input source.
|
|
|
79af3c |
+
|
|
|
79af3c |
+ Current implementation raises this exception only when an option is found
|
|
|
79af3c |
+ more than once in a single file, string or dictionary.
|
|
|
79af3c |
+ """
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def __init__(self, section, option, source=None, lineno=None):
|
|
|
79af3c |
+ msg = [repr(option), " in section ", repr(section),
|
|
|
79af3c |
+ " already exists"]
|
|
|
79af3c |
+ if source is not None:
|
|
|
79af3c |
+ message = ["While reading from ", repr(source)]
|
|
|
79af3c |
+ if lineno is not None:
|
|
|
79af3c |
+ message.append(" [line {0:2d}]".format(lineno))
|
|
|
79af3c |
+ message.append(": option ")
|
|
|
79af3c |
+ message.extend(msg)
|
|
|
79af3c |
+ msg = message
|
|
|
79af3c |
+ else:
|
|
|
79af3c |
+ msg.insert(0, "Option ")
|
|
|
79af3c |
+ Error.__init__(self, "".join(msg))
|
|
|
79af3c |
+ self.section = section
|
|
|
79af3c |
+ self.option = option
|
|
|
79af3c |
+ self.source = source
|
|
|
79af3c |
+ self.lineno = lineno
|
|
|
79af3c |
+ self.args = (section, option, source, lineno)
|
|
|
79af3c |
+
|
|
|
79af3c |
+
|
|
|
79af3c |
+class NoOptionError(Error):
|
|
|
79af3c |
+ """A requested option was not found."""
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def __init__(self, option, section):
|
|
|
79af3c |
+ Error.__init__(self, "No option %r in section: %r" %
|
|
|
79af3c |
+ (option, section))
|
|
|
79af3c |
+ self.option = option
|
|
|
79af3c |
+ self.section = section
|
|
|
79af3c |
+ self.args = (option, section)
|
|
|
79af3c |
+
|
|
|
79af3c |
+
|
|
|
79af3c |
+class InterpolationError(Error):
|
|
|
79af3c |
+ """Base class for interpolation-related exceptions."""
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def __init__(self, option, section, msg):
|
|
|
79af3c |
+ Error.__init__(self, msg)
|
|
|
79af3c |
+ self.option = option
|
|
|
79af3c |
+ self.section = section
|
|
|
79af3c |
+ self.args = (option, section, msg)
|
|
|
79af3c |
+
|
|
|
79af3c |
+
|
|
|
79af3c |
+class InterpolationMissingOptionError(InterpolationError):
|
|
|
79af3c |
+ """A string substitution required a setting which was not available."""
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def __init__(self, option, section, rawval, reference):
|
|
|
79af3c |
+ msg = ("Bad value substitution: option {0!r} in section {1!r} contains "
|
|
|
79af3c |
+ "an interpolation key {2!r} which is not a valid option name. "
|
|
|
79af3c |
+ "Raw value: {3!r}".format(option, section, reference, rawval))
|
|
|
79af3c |
+ InterpolationError.__init__(self, option, section, msg)
|
|
|
79af3c |
+ self.reference = reference
|
|
|
79af3c |
+ self.args = (option, section, rawval, reference)
|
|
|
79af3c |
+
|
|
|
79af3c |
+
|
|
|
79af3c |
+class InterpolationSyntaxError(InterpolationError):
|
|
|
79af3c |
+ """Raised when the source text contains invalid syntax.
|
|
|
79af3c |
+
|
|
|
79af3c |
+ Current implementation raises this exception when the source text into
|
|
|
79af3c |
+ which substitutions are made does not conform to the required syntax.
|
|
|
79af3c |
+ """
|
|
|
79af3c |
+
|
|
|
79af3c |
+
|
|
|
79af3c |
+class InterpolationDepthError(InterpolationError):
|
|
|
79af3c |
+ """Raised when substitutions are nested too deeply."""
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def __init__(self, option, section, rawval):
|
|
|
79af3c |
+ msg = ("Recursion limit exceeded in value substitution: option {0!r} "
|
|
|
79af3c |
+ "in section {1!r} contains an interpolation key which "
|
|
|
79af3c |
+ "cannot be substituted in {2} steps. Raw value: {3!r}"
|
|
|
79af3c |
+ "".format(option, section, MAX_INTERPOLATION_DEPTH,
|
|
|
79af3c |
+ rawval))
|
|
|
79af3c |
+ InterpolationError.__init__(self, option, section, msg)
|
|
|
79af3c |
+ self.args = (option, section, rawval)
|
|
|
79af3c |
+
|
|
|
79af3c |
+
|
|
|
79af3c |
+class ParsingError(Error):
|
|
|
79af3c |
+ """Raised when a configuration file does not follow legal syntax."""
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def __init__(self, source=None, filename=None):
|
|
|
79af3c |
+ # Exactly one of `source'/`filename' arguments has to be given.
|
|
|
79af3c |
+ # `filename' kept for compatibility.
|
|
|
79af3c |
+ if filename and source:
|
|
|
79af3c |
+ raise ValueError("Cannot specify both `filename' and `source'. "
|
|
|
79af3c |
+ "Use `source'.")
|
|
|
79af3c |
+ elif not filename and not source:
|
|
|
79af3c |
+ raise ValueError("Required argument `source' not given.")
|
|
|
79af3c |
+ elif filename:
|
|
|
79af3c |
+ source = filename
|
|
|
79af3c |
+ Error.__init__(self, 'Source contains parsing errors: %r' % source)
|
|
|
79af3c |
+ self.source = source
|
|
|
79af3c |
+ self.errors = []
|
|
|
79af3c |
+ self.args = (source, )
|
|
|
79af3c |
+
|
|
|
79af3c |
+ @property
|
|
|
79af3c |
+ def filename(self):
|
|
|
79af3c |
+ """Deprecated, use `source'."""
|
|
|
79af3c |
+ warnings.warn(
|
|
|
79af3c |
+ "The 'filename' attribute will be removed in future versions. "
|
|
|
79af3c |
+ "Use 'source' instead.",
|
|
|
79af3c |
+ DeprecationWarning, stacklevel=2
|
|
|
79af3c |
+ )
|
|
|
79af3c |
+ return self.source
|
|
|
79af3c |
+
|
|
|
79af3c |
+ @filename.setter
|
|
|
79af3c |
+ def filename(self, value):
|
|
|
79af3c |
+ """Deprecated, user `source'."""
|
|
|
79af3c |
+ warnings.warn(
|
|
|
79af3c |
+ "The 'filename' attribute will be removed in future versions. "
|
|
|
79af3c |
+ "Use 'source' instead.",
|
|
|
79af3c |
+ DeprecationWarning, stacklevel=2
|
|
|
79af3c |
+ )
|
|
|
79af3c |
+ self.source = value
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def append(self, lineno, line):
|
|
|
79af3c |
+ self.errors.append((lineno, line))
|
|
|
79af3c |
+ self.message += '\n\t[line %2d]: %s' % (lineno, line)
|
|
|
79af3c |
+
|
|
|
79af3c |
+
|
|
|
79af3c |
+class MissingSectionHeaderError(ParsingError):
|
|
|
79af3c |
+ """Raised when a key-value pair is found before any section header."""
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def __init__(self, filename, lineno, line):
|
|
|
79af3c |
+ Error.__init__(
|
|
|
79af3c |
+ self,
|
|
|
79af3c |
+ 'File contains no section headers.\nfile: %r, line: %d\n%r' %
|
|
|
79af3c |
+ (filename, lineno, line))
|
|
|
79af3c |
+ self.source = filename
|
|
|
79af3c |
+ self.lineno = lineno
|
|
|
79af3c |
+ self.line = line
|
|
|
79af3c |
+ self.args = (filename, lineno, line)
|
|
|
79af3c |
+
|
|
|
79af3c |
+
|
|
|
79af3c |
+# Used in parser getters to indicate the default behaviour when a specific
|
|
|
79af3c |
+# option is not found it to raise an exception. Created to enable `None' as
|
|
|
79af3c |
+# a valid fallback value.
|
|
|
79af3c |
+_UNSET = object()
|
|
|
79af3c |
+
|
|
|
79af3c |
+
|
|
|
79af3c |
+class Interpolation(object):
|
|
|
79af3c |
+ """Dummy interpolation that passes the value through with no changes."""
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def before_get(self, parser, section, option, value, defaults):
|
|
|
79af3c |
+ return value
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def before_set(self, parser, section, option, value):
|
|
|
79af3c |
+ return value
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def before_read(self, parser, section, option, value):
|
|
|
79af3c |
+ return value
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def before_write(self, parser, section, option, value):
|
|
|
79af3c |
+ return value
|
|
|
79af3c |
+
|
|
|
79af3c |
+
|
|
|
79af3c |
+class BasicInterpolation(Interpolation):
|
|
|
79af3c |
+ """Interpolation as implemented in the classic ConfigParser.
|
|
|
79af3c |
+
|
|
|
79af3c |
+ The option values can contain format strings which refer to other values in
|
|
|
79af3c |
+ the same section, or values in the special default section.
|
|
|
79af3c |
+
|
|
|
79af3c |
+ For example:
|
|
|
79af3c |
+
|
|
|
79af3c |
+ something: %(dir)s/whatever
|
|
|
79af3c |
+
|
|
|
79af3c |
+ would resolve the "%(dir)s" to the value of dir. All reference
|
|
|
79af3c |
+ expansions are done late, on demand. If a user needs to use a bare % in
|
|
|
79af3c |
+ a configuration file, she can escape it by writing %%. Other % usage
|
|
|
79af3c |
+ is considered a user error and raises `InterpolationSyntaxError'."""
|
|
|
79af3c |
+
|
|
|
79af3c |
+ _KEYCRE = re.compile(r"%\(([^)]+)\)s")
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def before_get(self, parser, section, option, value, defaults):
|
|
|
79af3c |
+ L = []
|
|
|
79af3c |
+ self._interpolate_some(parser, option, L, value, section, defaults, 1)
|
|
|
79af3c |
+ return ''.join(L)
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def before_set(self, parser, section, option, value):
|
|
|
79af3c |
+ tmp_value = value.replace('%%', '') # escaped percent signs
|
|
|
79af3c |
+ tmp_value = self._KEYCRE.sub('', tmp_value) # valid syntax
|
|
|
79af3c |
+ if '%' in tmp_value:
|
|
|
79af3c |
+ raise ValueError("invalid interpolation syntax in %r at "
|
|
|
79af3c |
+ "position %d" % (value, tmp_value.find('%')))
|
|
|
79af3c |
+ return value
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def _interpolate_some(self, parser, option, accum, rest, section, map,
|
|
|
79af3c |
+ depth):
|
|
|
79af3c |
+ rawval = parser.get(section, option, raw=True, fallback=rest)
|
|
|
79af3c |
+ if depth > MAX_INTERPOLATION_DEPTH:
|
|
|
79af3c |
+ raise InterpolationDepthError(option, section, rawval)
|
|
|
79af3c |
+ while rest:
|
|
|
79af3c |
+ p = rest.find("%")
|
|
|
79af3c |
+ if p < 0:
|
|
|
79af3c |
+ accum.append(rest)
|
|
|
79af3c |
+ return
|
|
|
79af3c |
+ if p > 0:
|
|
|
79af3c |
+ accum.append(rest[:p])
|
|
|
79af3c |
+ rest = rest[p:]
|
|
|
79af3c |
+ # p is no longer used
|
|
|
79af3c |
+ c = rest[1:2]
|
|
|
79af3c |
+ if c == "%":
|
|
|
79af3c |
+ accum.append("%")
|
|
|
79af3c |
+ rest = rest[2:]
|
|
|
79af3c |
+ elif c == "(":
|
|
|
79af3c |
+ m = self._KEYCRE.match(rest)
|
|
|
79af3c |
+ if m is None:
|
|
|
79af3c |
+ raise InterpolationSyntaxError(option, section,
|
|
|
79af3c |
+ "bad interpolation variable reference %r" % rest)
|
|
|
79af3c |
+ var = parser.optionxform(m.group(1))
|
|
|
79af3c |
+ rest = rest[m.end():]
|
|
|
79af3c |
+ try:
|
|
|
79af3c |
+ v = map[var]
|
|
|
79af3c |
+ except KeyError:
|
|
|
79af3c |
+ raise from_none(InterpolationMissingOptionError(
|
|
|
79af3c |
+ option, section, rawval, var))
|
|
|
79af3c |
+ if "%" in v:
|
|
|
79af3c |
+ self._interpolate_some(parser, option, accum, v,
|
|
|
79af3c |
+ section, map, depth + 1)
|
|
|
79af3c |
+ else:
|
|
|
79af3c |
+ accum.append(v)
|
|
|
79af3c |
+ else:
|
|
|
79af3c |
+ raise InterpolationSyntaxError(
|
|
|
79af3c |
+ option, section,
|
|
|
79af3c |
+ "'%%' must be followed by '%%' or '(', "
|
|
|
79af3c |
+ "found: %r" % (rest,))
|
|
|
79af3c |
+
|
|
|
79af3c |
+
|
|
|
79af3c |
+class ExtendedInterpolation(Interpolation):
|
|
|
79af3c |
+ """Advanced variant of interpolation, supports the syntax used by
|
|
|
79af3c |
+ `zc.buildout'. Enables interpolation between sections."""
|
|
|
79af3c |
+
|
|
|
79af3c |
+ _KEYCRE = re.compile(r"\$\{([^}]+)\}")
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def before_get(self, parser, section, option, value, defaults):
|
|
|
79af3c |
+ L = []
|
|
|
79af3c |
+ self._interpolate_some(parser, option, L, value, section, defaults, 1)
|
|
|
79af3c |
+ return ''.join(L)
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def before_set(self, parser, section, option, value):
|
|
|
79af3c |
+ tmp_value = value.replace('$$', '') # escaped dollar signs
|
|
|
79af3c |
+ tmp_value = self._KEYCRE.sub('', tmp_value) # valid syntax
|
|
|
79af3c |
+ if '$' in tmp_value:
|
|
|
79af3c |
+ raise ValueError("invalid interpolation syntax in %r at "
|
|
|
79af3c |
+ "position %d" % (value, tmp_value.find('$')))
|
|
|
79af3c |
+ return value
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def _interpolate_some(self, parser, option, accum, rest, section, map,
|
|
|
79af3c |
+ depth):
|
|
|
79af3c |
+ rawval = parser.get(section, option, raw=True, fallback=rest)
|
|
|
79af3c |
+ if depth > MAX_INTERPOLATION_DEPTH:
|
|
|
79af3c |
+ raise InterpolationDepthError(option, section, rawval)
|
|
|
79af3c |
+ while rest:
|
|
|
79af3c |
+ p = rest.find("$")
|
|
|
79af3c |
+ if p < 0:
|
|
|
79af3c |
+ accum.append(rest)
|
|
|
79af3c |
+ return
|
|
|
79af3c |
+ if p > 0:
|
|
|
79af3c |
+ accum.append(rest[:p])
|
|
|
79af3c |
+ rest = rest[p:]
|
|
|
79af3c |
+ # p is no longer used
|
|
|
79af3c |
+ c = rest[1:2]
|
|
|
79af3c |
+ if c == "$":
|
|
|
79af3c |
+ accum.append("$")
|
|
|
79af3c |
+ rest = rest[2:]
|
|
|
79af3c |
+ elif c == "{":
|
|
|
79af3c |
+ m = self._KEYCRE.match(rest)
|
|
|
79af3c |
+ if m is None:
|
|
|
79af3c |
+ raise InterpolationSyntaxError(option, section,
|
|
|
79af3c |
+ "bad interpolation variable reference %r" % rest)
|
|
|
79af3c |
+ path = m.group(1).split(':')
|
|
|
79af3c |
+ rest = rest[m.end():]
|
|
|
79af3c |
+ sect = section
|
|
|
79af3c |
+ opt = option
|
|
|
79af3c |
+ try:
|
|
|
79af3c |
+ if len(path) == 1:
|
|
|
79af3c |
+ opt = parser.optionxform(path[0])
|
|
|
79af3c |
+ v = map[opt]
|
|
|
79af3c |
+ elif len(path) == 2:
|
|
|
79af3c |
+ sect = path[0]
|
|
|
79af3c |
+ opt = parser.optionxform(path[1])
|
|
|
79af3c |
+ v = parser.get(sect, opt, raw=True)
|
|
|
79af3c |
+ else:
|
|
|
79af3c |
+ raise InterpolationSyntaxError(
|
|
|
79af3c |
+ option, section,
|
|
|
79af3c |
+ "More than one ':' found: %r" % (rest,))
|
|
|
79af3c |
+ except (KeyError, NoSectionError, NoOptionError):
|
|
|
79af3c |
+ raise from_none(InterpolationMissingOptionError(
|
|
|
79af3c |
+ option, section, rawval, ":".join(path)))
|
|
|
79af3c |
+ if "$" in v:
|
|
|
79af3c |
+ self._interpolate_some(parser, opt, accum, v, sect,
|
|
|
79af3c |
+ dict(parser.items(sect, raw=True)),
|
|
|
79af3c |
+ depth + 1)
|
|
|
79af3c |
+ else:
|
|
|
79af3c |
+ accum.append(v)
|
|
|
79af3c |
+ else:
|
|
|
79af3c |
+ raise InterpolationSyntaxError(
|
|
|
79af3c |
+ option, section,
|
|
|
79af3c |
+ "'$' must be followed by '$' or '{', "
|
|
|
79af3c |
+ "found: %r" % (rest,))
|
|
|
79af3c |
+
|
|
|
79af3c |
+
|
|
|
79af3c |
+class LegacyInterpolation(Interpolation):
|
|
|
79af3c |
+ """Deprecated interpolation used in old versions of ConfigParser.
|
|
|
79af3c |
+ Use BasicInterpolation or ExtendedInterpolation instead."""
|
|
|
79af3c |
+
|
|
|
79af3c |
+ _KEYCRE = re.compile(r"%\(([^)]*)\)s|.")
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def before_get(self, parser, section, option, value, vars):
|
|
|
79af3c |
+ rawval = value
|
|
|
79af3c |
+ depth = MAX_INTERPOLATION_DEPTH
|
|
|
79af3c |
+ while depth: # Loop through this until it's done
|
|
|
79af3c |
+ depth -= 1
|
|
|
79af3c |
+ if value and "%(" in value:
|
|
|
79af3c |
+ replace = functools.partial(self._interpolation_replace,
|
|
|
79af3c |
+ parser=parser)
|
|
|
79af3c |
+ value = self._KEYCRE.sub(replace, value)
|
|
|
79af3c |
+ try:
|
|
|
79af3c |
+ value = value % vars
|
|
|
79af3c |
+ except KeyError as e:
|
|
|
79af3c |
+ raise from_none(InterpolationMissingOptionError(
|
|
|
79af3c |
+ option, section, rawval, e.args[0]))
|
|
|
79af3c |
+ else:
|
|
|
79af3c |
+ break
|
|
|
79af3c |
+ if value and "%(" in value:
|
|
|
79af3c |
+ raise InterpolationDepthError(option, section, rawval)
|
|
|
79af3c |
+ return value
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def before_set(self, parser, section, option, value):
|
|
|
79af3c |
+ return value
|
|
|
79af3c |
+
|
|
|
79af3c |
+ @staticmethod
|
|
|
79af3c |
+ def _interpolation_replace(match, parser):
|
|
|
79af3c |
+ s = match.group(1)
|
|
|
79af3c |
+ if s is None:
|
|
|
79af3c |
+ return match.group()
|
|
|
79af3c |
+ else:
|
|
|
79af3c |
+ return "%%(%s)s" % parser.optionxform(s)
|
|
|
79af3c |
+
|
|
|
79af3c |
+
|
|
|
79af3c |
+class RawConfigParser(MutableMapping):
|
|
|
79af3c |
+ """ConfigParser that does not do interpolation."""
|
|
|
79af3c |
+
|
|
|
79af3c |
+ # Regular expressions for parsing section headers and options
|
|
|
79af3c |
+ _SECT_TMPL = r"""
|
|
|
79af3c |
+ \[ # [
|
|
|
79af3c |
+ (?P<header>[^]]+) # very permissive!
|
|
|
79af3c |
+ \] # ]
|
|
|
79af3c |
+ """
|
|
|
79af3c |
+ _OPT_TMPL = r"""
|
|
|
79af3c |
+ (?P<option>.*?) # very permissive!
|
|
|
79af3c |
+ \s*(?P<vi>{delim})\s* # any number of space/tab,
|
|
|
79af3c |
+ # followed by any of the
|
|
|
79af3c |
+ # allowed delimiters,
|
|
|
79af3c |
+ # followed by any space/tab
|
|
|
79af3c |
+ (?P<value>.*)$ # everything up to eol
|
|
|
79af3c |
+ """
|
|
|
79af3c |
+ _OPT_NV_TMPL = r"""
|
|
|
79af3c |
+ (?P<option>.*?) # very permissive!
|
|
|
79af3c |
+ \s*(?: # any number of space/tab,
|
|
|
79af3c |
+ (?P<vi>{delim})\s* # optionally followed by
|
|
|
79af3c |
+ # any of the allowed
|
|
|
79af3c |
+ # delimiters, followed by any
|
|
|
79af3c |
+ # space/tab
|
|
|
79af3c |
+ (?P<value>.*))?$ # everything up to eol
|
|
|
79af3c |
+ """
|
|
|
79af3c |
+ # Interpolation algorithm to be used if the user does not specify another
|
|
|
79af3c |
+ _DEFAULT_INTERPOLATION = Interpolation()
|
|
|
79af3c |
+ # Compiled regular expression for matching sections
|
|
|
79af3c |
+ SECTCRE = re.compile(_SECT_TMPL, re.VERBOSE)
|
|
|
79af3c |
+ # Compiled regular expression for matching options with typical separators
|
|
|
79af3c |
+ OPTCRE = re.compile(_OPT_TMPL.format(delim="=|:"), re.VERBOSE)
|
|
|
79af3c |
+ # Compiled regular expression for matching options with optional values
|
|
|
79af3c |
+ # delimited using typical separators
|
|
|
79af3c |
+ OPTCRE_NV = re.compile(_OPT_NV_TMPL.format(delim="=|:"), re.VERBOSE)
|
|
|
79af3c |
+ # Compiled regular expression for matching leading whitespace in a line
|
|
|
79af3c |
+ NONSPACECRE = re.compile(r"\S")
|
|
|
79af3c |
+ # Possible boolean values in the configuration.
|
|
|
79af3c |
+ BOOLEAN_STATES = {'1': True, 'yes': True, 'true': True, 'on': True,
|
|
|
79af3c |
+ '0': False, 'no': False, 'false': False, 'off': False}
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def __init__(self, defaults=None, dict_type=_default_dict,
|
|
|
79af3c |
+ allow_no_value=False, **kwargs):
|
|
|
79af3c |
+
|
|
|
79af3c |
+ # keyword-only arguments
|
|
|
79af3c |
+ delimiters = kwargs.get('delimiters', ('=', ':'))
|
|
|
79af3c |
+ comment_prefixes = kwargs.get('comment_prefixes', ('#', ';'))
|
|
|
79af3c |
+ inline_comment_prefixes = kwargs.get('inline_comment_prefixes', None)
|
|
|
79af3c |
+ strict = kwargs.get('strict', True)
|
|
|
79af3c |
+ empty_lines_in_values = kwargs.get('empty_lines_in_values', True)
|
|
|
79af3c |
+ default_section = kwargs.get('default_section', DEFAULTSECT)
|
|
|
79af3c |
+ interpolation = kwargs.get('interpolation', _UNSET)
|
|
|
79af3c |
+ converters = kwargs.get('converters', _UNSET)
|
|
|
79af3c |
+
|
|
|
79af3c |
+ self._dict = dict_type
|
|
|
79af3c |
+ self._sections = self._dict()
|
|
|
79af3c |
+ self._defaults = self._dict()
|
|
|
79af3c |
+ self._converters = ConverterMapping(self)
|
|
|
79af3c |
+ self._proxies = self._dict()
|
|
|
79af3c |
+ self._proxies[default_section] = SectionProxy(self, default_section)
|
|
|
79af3c |
+ if defaults:
|
|
|
79af3c |
+ for key, value in defaults.items():
|
|
|
79af3c |
+ self._defaults[self.optionxform(key)] = value
|
|
|
79af3c |
+ self._delimiters = tuple(delimiters)
|
|
|
79af3c |
+ if delimiters == ('=', ':'):
|
|
|
79af3c |
+ self._optcre = self.OPTCRE_NV if allow_no_value else self.OPTCRE
|
|
|
79af3c |
+ else:
|
|
|
79af3c |
+ d = "|".join(re.escape(d) for d in delimiters)
|
|
|
79af3c |
+ if allow_no_value:
|
|
|
79af3c |
+ self._optcre = re.compile(self._OPT_NV_TMPL.format(delim=d),
|
|
|
79af3c |
+ re.VERBOSE)
|
|
|
79af3c |
+ else:
|
|
|
79af3c |
+ self._optcre = re.compile(self._OPT_TMPL.format(delim=d),
|
|
|
79af3c |
+ re.VERBOSE)
|
|
|
79af3c |
+ self._comment_prefixes = tuple(comment_prefixes or ())
|
|
|
79af3c |
+ self._inline_comment_prefixes = tuple(inline_comment_prefixes or ())
|
|
|
79af3c |
+ self._strict = strict
|
|
|
79af3c |
+ self._allow_no_value = allow_no_value
|
|
|
79af3c |
+ self._empty_lines_in_values = empty_lines_in_values
|
|
|
79af3c |
+ self.default_section=default_section
|
|
|
79af3c |
+ self._interpolation = interpolation
|
|
|
79af3c |
+ if self._interpolation is _UNSET:
|
|
|
79af3c |
+ self._interpolation = self._DEFAULT_INTERPOLATION
|
|
|
79af3c |
+ if self._interpolation is None:
|
|
|
79af3c |
+ self._interpolation = Interpolation()
|
|
|
79af3c |
+ if converters is not _UNSET:
|
|
|
79af3c |
+ self._converters.update(converters)
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def defaults(self):
|
|
|
79af3c |
+ return self._defaults
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def sections(self):
|
|
|
79af3c |
+ """Return a list of section names, excluding [DEFAULT]"""
|
|
|
79af3c |
+ # self._sections will never have [DEFAULT] in it
|
|
|
79af3c |
+ return list(self._sections.keys())
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def add_section(self, section):
|
|
|
79af3c |
+ """Create a new section in the configuration.
|
|
|
79af3c |
+
|
|
|
79af3c |
+ Raise DuplicateSectionError if a section by the specified name
|
|
|
79af3c |
+ already exists. Raise ValueError if name is DEFAULT.
|
|
|
79af3c |
+ """
|
|
|
79af3c |
+ if section == self.default_section:
|
|
|
79af3c |
+ raise ValueError('Invalid section name: %r' % section)
|
|
|
79af3c |
+
|
|
|
79af3c |
+ if section in self._sections:
|
|
|
79af3c |
+ raise DuplicateSectionError(section)
|
|
|
79af3c |
+ self._sections[section] = self._dict()
|
|
|
79af3c |
+ self._proxies[section] = SectionProxy(self, section)
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def has_section(self, section):
|
|
|
79af3c |
+ """Indicate whether the named section is present in the configuration.
|
|
|
79af3c |
+
|
|
|
79af3c |
+ The DEFAULT section is not acknowledged.
|
|
|
79af3c |
+ """
|
|
|
79af3c |
+ return section in self._sections
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def options(self, section):
|
|
|
79af3c |
+ """Return a list of option names for the given section name."""
|
|
|
79af3c |
+ try:
|
|
|
79af3c |
+ opts = self._sections[section].copy()
|
|
|
79af3c |
+ except KeyError:
|
|
|
79af3c |
+ raise from_none(NoSectionError(section))
|
|
|
79af3c |
+ opts.update(self._defaults)
|
|
|
79af3c |
+ return list(opts.keys())
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def read(self, filenames, encoding=None):
|
|
|
79af3c |
+ """Read and parse a filename or a list of filenames.
|
|
|
79af3c |
+
|
|
|
79af3c |
+ Files that cannot be opened are silently ignored; this is
|
|
|
79af3c |
+ designed so that you can specify a list of potential
|
|
|
79af3c |
+ configuration file locations (e.g. current directory, user's
|
|
|
79af3c |
+ home directory, systemwide directory), and all existing
|
|
|
79af3c |
+ configuration files in the list will be read. A single
|
|
|
79af3c |
+ filename may also be given.
|
|
|
79af3c |
+
|
|
|
79af3c |
+ Return list of successfully read files.
|
|
|
79af3c |
+ """
|
|
|
79af3c |
+ if PY2 and isinstance(filenames, bytes):
|
|
|
79af3c |
+ # we allow for a little unholy magic for Python 2 so that
|
|
|
79af3c |
+ # people not using unicode_literals can still use the library
|
|
|
79af3c |
+ # conveniently
|
|
|
79af3c |
+ warnings.warn(
|
|
|
79af3c |
+ "You passed a bytestring as `filenames`. This will not work"
|
|
|
79af3c |
+ " on Python 3. Use `cp.read_file()` or switch to using Unicode"
|
|
|
79af3c |
+ " strings across the board.",
|
|
|
79af3c |
+ DeprecationWarning,
|
|
|
79af3c |
+ stacklevel=2,
|
|
|
79af3c |
+ )
|
|
|
79af3c |
+ filenames = [filenames]
|
|
|
79af3c |
+ elif isinstance(filenames, str):
|
|
|
79af3c |
+ filenames = [filenames]
|
|
|
79af3c |
+ read_ok = []
|
|
|
79af3c |
+ for filename in filenames:
|
|
|
79af3c |
+ try:
|
|
|
79af3c |
+ with open(filename, encoding=encoding) as fp:
|
|
|
79af3c |
+ self._read(fp, filename)
|
|
|
79af3c |
+ except IOError:
|
|
|
79af3c |
+ continue
|
|
|
79af3c |
+ read_ok.append(filename)
|
|
|
79af3c |
+ return read_ok
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def read_file(self, f, source=None):
|
|
|
79af3c |
+ """Like read() but the argument must be a file-like object.
|
|
|
79af3c |
+
|
|
|
79af3c |
+ The `f' argument must be iterable, returning one line at a time.
|
|
|
79af3c |
+ Optional second argument is the `source' specifying the name of the
|
|
|
79af3c |
+ file being read. If not given, it is taken from f.name. If `f' has no
|
|
|
79af3c |
+ `name' attribute, `' is used.
|
|
|
79af3c |
+ """
|
|
|
79af3c |
+ if source is None:
|
|
|
79af3c |
+ try:
|
|
|
79af3c |
+ source = f.name
|
|
|
79af3c |
+ except AttributeError:
|
|
|
79af3c |
+ source = ''
|
|
|
79af3c |
+ self._read(f, source)
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def read_string(self, string, source='<string>'):
|
|
|
79af3c |
+ """Read configuration from a given string."""
|
|
|
79af3c |
+ sfile = io.StringIO(string)
|
|
|
79af3c |
+ self.read_file(sfile, source)
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def read_dict(self, dictionary, source='<dict>'):
|
|
|
79af3c |
+ """Read configuration from a dictionary.
|
|
|
79af3c |
+
|
|
|
79af3c |
+ Keys are section names, values are dictionaries with keys and values
|
|
|
79af3c |
+ that should be present in the section. If the used dictionary type
|
|
|
79af3c |
+ preserves order, sections and their keys will be added in order.
|
|
|
79af3c |
+
|
|
|
79af3c |
+ All types held in the dictionary are converted to strings during
|
|
|
79af3c |
+ reading, including section names, option names and keys.
|
|
|
79af3c |
+
|
|
|
79af3c |
+ Optional second argument is the `source' specifying the name of the
|
|
|
79af3c |
+ dictionary being read.
|
|
|
79af3c |
+ """
|
|
|
79af3c |
+ elements_added = set()
|
|
|
79af3c |
+ for section, keys in dictionary.items():
|
|
|
79af3c |
+ section = str(section)
|
|
|
79af3c |
+ try:
|
|
|
79af3c |
+ self.add_section(section)
|
|
|
79af3c |
+ except (DuplicateSectionError, ValueError):
|
|
|
79af3c |
+ if self._strict and section in elements_added:
|
|
|
79af3c |
+ raise
|
|
|
79af3c |
+ elements_added.add(section)
|
|
|
79af3c |
+ for key, value in keys.items():
|
|
|
79af3c |
+ key = self.optionxform(str(key))
|
|
|
79af3c |
+ if value is not None:
|
|
|
79af3c |
+ value = str(value)
|
|
|
79af3c |
+ if self._strict and (section, key) in elements_added:
|
|
|
79af3c |
+ raise DuplicateOptionError(section, key, source)
|
|
|
79af3c |
+ elements_added.add((section, key))
|
|
|
79af3c |
+ self.set(section, key, value)
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def readfp(self, fp, filename=None):
|
|
|
79af3c |
+ """Deprecated, use read_file instead."""
|
|
|
79af3c |
+ warnings.warn(
|
|
|
79af3c |
+ "This method will be removed in future versions. "
|
|
|
79af3c |
+ "Use 'parser.read_file()' instead.",
|
|
|
79af3c |
+ DeprecationWarning, stacklevel=2
|
|
|
79af3c |
+ )
|
|
|
79af3c |
+ self.read_file(fp, source=filename)
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def get(self, section, option, **kwargs):
|
|
|
79af3c |
+ """Get an option value for a given section.
|
|
|
79af3c |
+
|
|
|
79af3c |
+ If `vars' is provided, it must be a dictionary. The option is looked up
|
|
|
79af3c |
+ in `vars' (if provided), `section', and in `DEFAULTSECT' in that order.
|
|
|
79af3c |
+ If the key is not found and `fallback' is provided, it is used as
|
|
|
79af3c |
+ a fallback value. `None' can be provided as a `fallback' value.
|
|
|
79af3c |
+
|
|
|
79af3c |
+ If interpolation is enabled and the optional argument `raw' is False,
|
|
|
79af3c |
+ all interpolations are expanded in the return values.
|
|
|
79af3c |
+
|
|
|
79af3c |
+ Arguments `raw', `vars', and `fallback' are keyword only.
|
|
|
79af3c |
+
|
|
|
79af3c |
+ The section DEFAULT is special.
|
|
|
79af3c |
+ """
|
|
|
79af3c |
+ # keyword-only arguments
|
|
|
79af3c |
+ raw = kwargs.get('raw', False)
|
|
|
79af3c |
+ vars = kwargs.get('vars', None)
|
|
|
79af3c |
+ fallback = kwargs.get('fallback', _UNSET)
|
|
|
79af3c |
+
|
|
|
79af3c |
+ try:
|
|
|
79af3c |
+ d = self._unify_values(section, vars)
|
|
|
79af3c |
+ except NoSectionError:
|
|
|
79af3c |
+ if fallback is _UNSET:
|
|
|
79af3c |
+ raise
|
|
|
79af3c |
+ else:
|
|
|
79af3c |
+ return fallback
|
|
|
79af3c |
+ option = self.optionxform(option)
|
|
|
79af3c |
+ try:
|
|
|
79af3c |
+ value = d[option]
|
|
|
79af3c |
+ except KeyError:
|
|
|
79af3c |
+ if fallback is _UNSET:
|
|
|
79af3c |
+ raise NoOptionError(option, section)
|
|
|
79af3c |
+ else:
|
|
|
79af3c |
+ return fallback
|
|
|
79af3c |
+
|
|
|
79af3c |
+ if raw or value is None:
|
|
|
79af3c |
+ return value
|
|
|
79af3c |
+ else:
|
|
|
79af3c |
+ return self._interpolation.before_get(self, section, option, value,
|
|
|
79af3c |
+ d)
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def _get(self, section, conv, option, **kwargs):
|
|
|
79af3c |
+ return conv(self.get(section, option, **kwargs))
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def _get_conv(self, section, option, conv, **kwargs):
|
|
|
79af3c |
+ # keyword-only arguments
|
|
|
79af3c |
+ kwargs.setdefault('raw', False)
|
|
|
79af3c |
+ kwargs.setdefault('vars', None)
|
|
|
79af3c |
+ fallback = kwargs.pop('fallback', _UNSET)
|
|
|
79af3c |
+ try:
|
|
|
79af3c |
+ return self._get(section, conv, option, **kwargs)
|
|
|
79af3c |
+ except (NoSectionError, NoOptionError):
|
|
|
79af3c |
+ if fallback is _UNSET:
|
|
|
79af3c |
+ raise
|
|
|
79af3c |
+ return fallback
|
|
|
79af3c |
+
|
|
|
79af3c |
+ # getint, getfloat and getboolean provided directly for backwards compat
|
|
|
79af3c |
+ def getint(self, section, option, **kwargs):
|
|
|
79af3c |
+ # keyword-only arguments
|
|
|
79af3c |
+ kwargs.setdefault('raw', False)
|
|
|
79af3c |
+ kwargs.setdefault('vars', None)
|
|
|
79af3c |
+ kwargs.setdefault('fallback', _UNSET)
|
|
|
79af3c |
+ return self._get_conv(section, option, int, **kwargs)
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def getfloat(self, section, option, **kwargs):
|
|
|
79af3c |
+ # keyword-only arguments
|
|
|
79af3c |
+ kwargs.setdefault('raw', False)
|
|
|
79af3c |
+ kwargs.setdefault('vars', None)
|
|
|
79af3c |
+ kwargs.setdefault('fallback', _UNSET)
|
|
|
79af3c |
+ return self._get_conv(section, option, float, **kwargs)
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def getboolean(self, section, option, **kwargs):
|
|
|
79af3c |
+ # keyword-only arguments
|
|
|
79af3c |
+ kwargs.setdefault('raw', False)
|
|
|
79af3c |
+ kwargs.setdefault('vars', None)
|
|
|
79af3c |
+ kwargs.setdefault('fallback', _UNSET)
|
|
|
79af3c |
+ return self._get_conv(section, option, self._convert_to_boolean,
|
|
|
79af3c |
+ **kwargs)
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def items(self, section=_UNSET, raw=False, vars=None):
|
|
|
79af3c |
+ """Return a list of (name, value) tuples for each option in a section.
|
|
|
79af3c |
+
|
|
|
79af3c |
+ All % interpolations are expanded in the return values, based on the
|
|
|
79af3c |
+ defaults passed into the constructor, unless the optional argument
|
|
|
79af3c |
+ `raw' is true. Additional substitutions may be provided using the
|
|
|
79af3c |
+ `vars' argument, which must be a dictionary whose contents overrides
|
|
|
79af3c |
+ any pre-existing defaults.
|
|
|
79af3c |
+
|
|
|
79af3c |
+ The section DEFAULT is special.
|
|
|
79af3c |
+ """
|
|
|
79af3c |
+ if section is _UNSET:
|
|
|
79af3c |
+ return super(RawConfigParser, self).items()
|
|
|
79af3c |
+ d = self._defaults.copy()
|
|
|
79af3c |
+ try:
|
|
|
79af3c |
+ d.update(self._sections[section])
|
|
|
79af3c |
+ except KeyError:
|
|
|
79af3c |
+ if section != self.default_section:
|
|
|
79af3c |
+ raise NoSectionError(section)
|
|
|
79af3c |
+ # Update with the entry specific variables
|
|
|
79af3c |
+ if vars:
|
|
|
79af3c |
+ for key, value in vars.items():
|
|
|
79af3c |
+ d[self.optionxform(key)] = value
|
|
|
79af3c |
+ value_getter = lambda option: self._interpolation.before_get(self,
|
|
|
79af3c |
+ section, option, d[option], d)
|
|
|
79af3c |
+ if raw:
|
|
|
79af3c |
+ value_getter = lambda option: d[option]
|
|
|
79af3c |
+ return [(option, value_getter(option)) for option in d.keys()]
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def popitem(self):
|
|
|
79af3c |
+ """Remove a section from the parser and return it as
|
|
|
79af3c |
+ a (section_name, section_proxy) tuple. If no section is present, raise
|
|
|
79af3c |
+ KeyError.
|
|
|
79af3c |
+
|
|
|
79af3c |
+ The section DEFAULT is never returned because it cannot be removed.
|
|
|
79af3c |
+ """
|
|
|
79af3c |
+ for key in self.sections():
|
|
|
79af3c |
+ value = self[key]
|
|
|
79af3c |
+ del self[key]
|
|
|
79af3c |
+ return key, value
|
|
|
79af3c |
+ raise KeyError
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def optionxform(self, optionstr):
|
|
|
79af3c |
+ return optionstr.lower()
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def has_option(self, section, option):
|
|
|
79af3c |
+ """Check for the existence of a given option in a given section.
|
|
|
79af3c |
+ If the specified `section' is None or an empty string, DEFAULT is
|
|
|
79af3c |
+ assumed. If the specified `section' does not exist, returns False."""
|
|
|
79af3c |
+ if not section or section == self.default_section:
|
|
|
79af3c |
+ option = self.optionxform(option)
|
|
|
79af3c |
+ return option in self._defaults
|
|
|
79af3c |
+ elif section not in self._sections:
|
|
|
79af3c |
+ return False
|
|
|
79af3c |
+ else:
|
|
|
79af3c |
+ option = self.optionxform(option)
|
|
|
79af3c |
+ return (option in self._sections[section]
|
|
|
79af3c |
+ or option in self._defaults)
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def set(self, section, option, value=None):
|
|
|
79af3c |
+ """Set an option."""
|
|
|
79af3c |
+ if value:
|
|
|
79af3c |
+ value = self._interpolation.before_set(self, section, option,
|
|
|
79af3c |
+ value)
|
|
|
79af3c |
+ if not section or section == self.default_section:
|
|
|
79af3c |
+ sectdict = self._defaults
|
|
|
79af3c |
+ else:
|
|
|
79af3c |
+ try:
|
|
|
79af3c |
+ sectdict = self._sections[section]
|
|
|
79af3c |
+ except KeyError:
|
|
|
79af3c |
+ raise from_none(NoSectionError(section))
|
|
|
79af3c |
+ sectdict[self.optionxform(option)] = value
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def write(self, fp, space_around_delimiters=True):
|
|
|
79af3c |
+ """Write an .ini-format representation of the configuration state.
|
|
|
79af3c |
+
|
|
|
79af3c |
+ If `space_around_delimiters' is True (the default), delimiters
|
|
|
79af3c |
+ between keys and values are surrounded by spaces.
|
|
|
79af3c |
+ """
|
|
|
79af3c |
+ if space_around_delimiters:
|
|
|
79af3c |
+ d = " {0} ".format(self._delimiters[0])
|
|
|
79af3c |
+ else:
|
|
|
79af3c |
+ d = self._delimiters[0]
|
|
|
79af3c |
+ if self._defaults:
|
|
|
79af3c |
+ self._write_section(fp, self.default_section,
|
|
|
79af3c |
+ self._defaults.items(), d)
|
|
|
79af3c |
+ for section in self._sections:
|
|
|
79af3c |
+ self._write_section(fp, section,
|
|
|
79af3c |
+ self._sections[section].items(), d)
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def _write_section(self, fp, section_name, section_items, delimiter):
|
|
|
79af3c |
+ """Write a single section to the specified `fp'."""
|
|
|
79af3c |
+ fp.write("[{0}]\n".format(section_name))
|
|
|
79af3c |
+ for key, value in section_items:
|
|
|
79af3c |
+ value = self._interpolation.before_write(self, section_name, key,
|
|
|
79af3c |
+ value)
|
|
|
79af3c |
+ if value is not None or not self._allow_no_value:
|
|
|
79af3c |
+ value = delimiter + str(value).replace('\n', '\n\t')
|
|
|
79af3c |
+ else:
|
|
|
79af3c |
+ value = ""
|
|
|
79af3c |
+ fp.write("{0}{1}\n".format(key, value))
|
|
|
79af3c |
+ fp.write("\n")
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def remove_option(self, section, option):
|
|
|
79af3c |
+ """Remove an option."""
|
|
|
79af3c |
+ if not section or section == self.default_section:
|
|
|
79af3c |
+ sectdict = self._defaults
|
|
|
79af3c |
+ else:
|
|
|
79af3c |
+ try:
|
|
|
79af3c |
+ sectdict = self._sections[section]
|
|
|
79af3c |
+ except KeyError:
|
|
|
79af3c |
+ raise from_none(NoSectionError(section))
|
|
|
79af3c |
+ option = self.optionxform(option)
|
|
|
79af3c |
+ existed = option in sectdict
|
|
|
79af3c |
+ if existed:
|
|
|
79af3c |
+ del sectdict[option]
|
|
|
79af3c |
+ return existed
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def remove_section(self, section):
|
|
|
79af3c |
+ """Remove a file section."""
|
|
|
79af3c |
+ existed = section in self._sections
|
|
|
79af3c |
+ if existed:
|
|
|
79af3c |
+ del self._sections[section]
|
|
|
79af3c |
+ del self._proxies[section]
|
|
|
79af3c |
+ return existed
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def __getitem__(self, key):
|
|
|
79af3c |
+ if key != self.default_section and not self.has_section(key):
|
|
|
79af3c |
+ raise KeyError(key)
|
|
|
79af3c |
+ return self._proxies[key]
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def __setitem__(self, key, value):
|
|
|
79af3c |
+ # To conform with the mapping protocol, overwrites existing values in
|
|
|
79af3c |
+ # the section.
|
|
|
79af3c |
+
|
|
|
79af3c |
+ # XXX this is not atomic if read_dict fails at any point. Then again,
|
|
|
79af3c |
+ # no update method in configparser is atomic in this implementation.
|
|
|
79af3c |
+ if key == self.default_section:
|
|
|
79af3c |
+ self._defaults.clear()
|
|
|
79af3c |
+ elif key in self._sections:
|
|
|
79af3c |
+ self._sections[key].clear()
|
|
|
79af3c |
+ self.read_dict({key: value})
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def __delitem__(self, key):
|
|
|
79af3c |
+ if key == self.default_section:
|
|
|
79af3c |
+ raise ValueError("Cannot remove the default section.")
|
|
|
79af3c |
+ if not self.has_section(key):
|
|
|
79af3c |
+ raise KeyError(key)
|
|
|
79af3c |
+ self.remove_section(key)
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def __contains__(self, key):
|
|
|
79af3c |
+ return key == self.default_section or self.has_section(key)
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def __len__(self):
|
|
|
79af3c |
+ return len(self._sections) + 1 # the default section
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def __iter__(self):
|
|
|
79af3c |
+ # XXX does it break when underlying container state changed?
|
|
|
79af3c |
+ return itertools.chain((self.default_section,), self._sections.keys())
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def _read(self, fp, fpname):
|
|
|
79af3c |
+ """Parse a sectioned configuration file.
|
|
|
79af3c |
+
|
|
|
79af3c |
+ Each section in a configuration file contains a header, indicated by
|
|
|
79af3c |
+ a name in square brackets (`[]'), plus key/value options, indicated by
|
|
|
79af3c |
+ `name' and `value' delimited with a specific substring (`=' or `:' by
|
|
|
79af3c |
+ default).
|
|
|
79af3c |
+
|
|
|
79af3c |
+ Values can span multiple lines, as long as they are indented deeper
|
|
|
79af3c |
+ than the first line of the value. Depending on the parser's mode, blank
|
|
|
79af3c |
+ lines may be treated as parts of multiline values or ignored.
|
|
|
79af3c |
+
|
|
|
79af3c |
+ Configuration files may include comments, prefixed by specific
|
|
|
79af3c |
+ characters (`#' and `;' by default). Comments may appear on their own
|
|
|
79af3c |
+ in an otherwise empty line or may be entered in lines holding values or
|
|
|
79af3c |
+ section names.
|
|
|
79af3c |
+ """
|
|
|
79af3c |
+ elements_added = set()
|
|
|
79af3c |
+ cursect = None # None, or a dictionary
|
|
|
79af3c |
+ sectname = None
|
|
|
79af3c |
+ optname = None
|
|
|
79af3c |
+ lineno = 0
|
|
|
79af3c |
+ indent_level = 0
|
|
|
79af3c |
+ e = None # None, or an exception
|
|
|
79af3c |
+ for lineno, line in enumerate(fp, start=1):
|
|
|
79af3c |
+ comment_start = sys.maxsize
|
|
|
79af3c |
+ # strip inline comments
|
|
|
79af3c |
+ inline_prefixes = dict(
|
|
|
79af3c |
+ (p, -1) for p in self._inline_comment_prefixes)
|
|
|
79af3c |
+ while comment_start == sys.maxsize and inline_prefixes:
|
|
|
79af3c |
+ next_prefixes = {}
|
|
|
79af3c |
+ for prefix, index in inline_prefixes.items():
|
|
|
79af3c |
+ index = line.find(prefix, index+1)
|
|
|
79af3c |
+ if index == -1:
|
|
|
79af3c |
+ continue
|
|
|
79af3c |
+ next_prefixes[prefix] = index
|
|
|
79af3c |
+ if index == 0 or (index > 0 and line[index-1].isspace()):
|
|
|
79af3c |
+ comment_start = min(comment_start, index)
|
|
|
79af3c |
+ inline_prefixes = next_prefixes
|
|
|
79af3c |
+ # strip full line comments
|
|
|
79af3c |
+ for prefix in self._comment_prefixes:
|
|
|
79af3c |
+ if line.strip().startswith(prefix):
|
|
|
79af3c |
+ comment_start = 0
|
|
|
79af3c |
+ break
|
|
|
79af3c |
+ if comment_start == sys.maxsize:
|
|
|
79af3c |
+ comment_start = None
|
|
|
79af3c |
+ value = line[:comment_start].strip()
|
|
|
79af3c |
+ if not value:
|
|
|
79af3c |
+ if self._empty_lines_in_values:
|
|
|
79af3c |
+ # add empty line to the value, but only if there was no
|
|
|
79af3c |
+ # comment on the line
|
|
|
79af3c |
+ if (comment_start is None and
|
|
|
79af3c |
+ cursect is not None and
|
|
|
79af3c |
+ optname and
|
|
|
79af3c |
+ cursect[optname] is not None):
|
|
|
79af3c |
+ cursect[optname].append('') # newlines added at join
|
|
|
79af3c |
+ else:
|
|
|
79af3c |
+ # empty line marks end of value
|
|
|
79af3c |
+ indent_level = sys.maxsize
|
|
|
79af3c |
+ continue
|
|
|
79af3c |
+ # continuation line?
|
|
|
79af3c |
+ first_nonspace = self.NONSPACECRE.search(line)
|
|
|
79af3c |
+ cur_indent_level = first_nonspace.start() if first_nonspace else 0
|
|
|
79af3c |
+ if (cursect is not None and optname and
|
|
|
79af3c |
+ cur_indent_level > indent_level):
|
|
|
79af3c |
+ cursect[optname].append(value)
|
|
|
79af3c |
+ # a section header or option header?
|
|
|
79af3c |
+ else:
|
|
|
79af3c |
+ indent_level = cur_indent_level
|
|
|
79af3c |
+ # is it a section header?
|
|
|
79af3c |
+ mo = self.SECTCRE.match(value)
|
|
|
79af3c |
+ if mo:
|
|
|
79af3c |
+ sectname = mo.group('header')
|
|
|
79af3c |
+ if sectname in self._sections:
|
|
|
79af3c |
+ if self._strict and sectname in elements_added:
|
|
|
79af3c |
+ raise DuplicateSectionError(sectname, fpname,
|
|
|
79af3c |
+ lineno)
|
|
|
79af3c |
+ cursect = self._sections[sectname]
|
|
|
79af3c |
+ elements_added.add(sectname)
|
|
|
79af3c |
+ elif sectname == self.default_section:
|
|
|
79af3c |
+ cursect = self._defaults
|
|
|
79af3c |
+ else:
|
|
|
79af3c |
+ cursect = self._dict()
|
|
|
79af3c |
+ self._sections[sectname] = cursect
|
|
|
79af3c |
+ self._proxies[sectname] = SectionProxy(self, sectname)
|
|
|
79af3c |
+ elements_added.add(sectname)
|
|
|
79af3c |
+ # So sections can't start with a continuation line
|
|
|
79af3c |
+ optname = None
|
|
|
79af3c |
+ # no section header in the file?
|
|
|
79af3c |
+ elif cursect is None:
|
|
|
79af3c |
+ raise MissingSectionHeaderError(fpname, lineno, line)
|
|
|
79af3c |
+ # an option line?
|
|
|
79af3c |
+ else:
|
|
|
79af3c |
+ mo = self._optcre.match(value)
|
|
|
79af3c |
+ if mo:
|
|
|
79af3c |
+ optname, vi, optval = mo.group('option', 'vi', 'value')
|
|
|
79af3c |
+ if not optname:
|
|
|
79af3c |
+ e = self._handle_error(e, fpname, lineno, line)
|
|
|
79af3c |
+ optname = self.optionxform(optname.rstrip())
|
|
|
79af3c |
+ if (self._strict and
|
|
|
79af3c |
+ (sectname, optname) in elements_added):
|
|
|
79af3c |
+ raise DuplicateOptionError(sectname, optname,
|
|
|
79af3c |
+ fpname, lineno)
|
|
|
79af3c |
+ elements_added.add((sectname, optname))
|
|
|
79af3c |
+ # This check is fine because the OPTCRE cannot
|
|
|
79af3c |
+ # match if it would set optval to None
|
|
|
79af3c |
+ if optval is not None:
|
|
|
79af3c |
+ optval = optval.strip()
|
|
|
79af3c |
+ cursect[optname] = [optval]
|
|
|
79af3c |
+ else:
|
|
|
79af3c |
+ # valueless option handling
|
|
|
79af3c |
+ cursect[optname] = None
|
|
|
79af3c |
+ else:
|
|
|
79af3c |
+ # a non-fatal parsing error occurred. set up the
|
|
|
79af3c |
+ # exception but keep going. the exception will be
|
|
|
79af3c |
+ # raised at the end of the file and will contain a
|
|
|
79af3c |
+ # list of all bogus lines
|
|
|
79af3c |
+ e = self._handle_error(e, fpname, lineno, line)
|
|
|
79af3c |
+ # if any parsing errors occurred, raise an exception
|
|
|
79af3c |
+ if e:
|
|
|
79af3c |
+ raise e
|
|
|
79af3c |
+ self._join_multiline_values()
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def _join_multiline_values(self):
|
|
|
79af3c |
+ defaults = self.default_section, self._defaults
|
|
|
79af3c |
+ all_sections = itertools.chain((defaults,),
|
|
|
79af3c |
+ self._sections.items())
|
|
|
79af3c |
+ for section, options in all_sections:
|
|
|
79af3c |
+ for name, val in options.items():
|
|
|
79af3c |
+ if isinstance(val, list):
|
|
|
79af3c |
+ val = '\n'.join(val).rstrip()
|
|
|
79af3c |
+ options[name] = self._interpolation.before_read(self,
|
|
|
79af3c |
+ section,
|
|
|
79af3c |
+ name, val)
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def _handle_error(self, exc, fpname, lineno, line):
|
|
|
79af3c |
+ if not exc:
|
|
|
79af3c |
+ exc = ParsingError(fpname)
|
|
|
79af3c |
+ exc.append(lineno, repr(line))
|
|
|
79af3c |
+ return exc
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def _unify_values(self, section, vars):
|
|
|
79af3c |
+ """Create a sequence of lookups with 'vars' taking priority over
|
|
|
79af3c |
+ the 'section' which takes priority over the DEFAULTSECT.
|
|
|
79af3c |
+
|
|
|
79af3c |
+ """
|
|
|
79af3c |
+ sectiondict = {}
|
|
|
79af3c |
+ try:
|
|
|
79af3c |
+ sectiondict = self._sections[section]
|
|
|
79af3c |
+ except KeyError:
|
|
|
79af3c |
+ if section != self.default_section:
|
|
|
79af3c |
+ raise NoSectionError(section)
|
|
|
79af3c |
+ # Update with the entry specific variables
|
|
|
79af3c |
+ vardict = {}
|
|
|
79af3c |
+ if vars:
|
|
|
79af3c |
+ for key, value in vars.items():
|
|
|
79af3c |
+ if value is not None:
|
|
|
79af3c |
+ value = str(value)
|
|
|
79af3c |
+ vardict[self.optionxform(key)] = value
|
|
|
79af3c |
+ return _ChainMap(vardict, sectiondict, self._defaults)
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def _convert_to_boolean(self, value):
|
|
|
79af3c |
+ """Return a boolean value translating from other types if necessary.
|
|
|
79af3c |
+ """
|
|
|
79af3c |
+ if value.lower() not in self.BOOLEAN_STATES:
|
|
|
79af3c |
+ raise ValueError('Not a boolean: %s' % value)
|
|
|
79af3c |
+ return self.BOOLEAN_STATES[value.lower()]
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def _validate_value_types(self, **kwargs):
|
|
|
79af3c |
+ """Raises a TypeError for non-string values.
|
|
|
79af3c |
+
|
|
|
79af3c |
+ The only legal non-string value if we allow valueless
|
|
|
79af3c |
+ options is None, so we need to check if the value is a
|
|
|
79af3c |
+ string if:
|
|
|
79af3c |
+ - we do not allow valueless options, or
|
|
|
79af3c |
+ - we allow valueless options but the value is not None
|
|
|
79af3c |
+
|
|
|
79af3c |
+ For compatibility reasons this method is not used in classic set()
|
|
|
79af3c |
+ for RawConfigParsers. It is invoked in every case for mapping protocol
|
|
|
79af3c |
+ access and in ConfigParser.set().
|
|
|
79af3c |
+ """
|
|
|
79af3c |
+ # keyword-only arguments
|
|
|
79af3c |
+ section = kwargs.get('section', "")
|
|
|
79af3c |
+ option = kwargs.get('option', "")
|
|
|
79af3c |
+ value = kwargs.get('value', "")
|
|
|
79af3c |
+
|
|
|
79af3c |
+ if PY2 and bytes in (type(section), type(option), type(value)):
|
|
|
79af3c |
+ # we allow for a little unholy magic for Python 2 so that
|
|
|
79af3c |
+ # people not using unicode_literals can still use the library
|
|
|
79af3c |
+ # conveniently
|
|
|
79af3c |
+ warnings.warn(
|
|
|
79af3c |
+ "You passed a bytestring. Implicitly decoding as UTF-8 string."
|
|
|
79af3c |
+ " This will not work on Python 3. Please switch to using"
|
|
|
79af3c |
+ " Unicode strings across the board.",
|
|
|
79af3c |
+ DeprecationWarning,
|
|
|
79af3c |
+ stacklevel=2,
|
|
|
79af3c |
+ )
|
|
|
79af3c |
+ if isinstance(section, bytes):
|
|
|
79af3c |
+ section = section.decode('utf8')
|
|
|
79af3c |
+ if isinstance(option, bytes):
|
|
|
79af3c |
+ option = option.decode('utf8')
|
|
|
79af3c |
+ if isinstance(value, bytes):
|
|
|
79af3c |
+ value = value.decode('utf8')
|
|
|
79af3c |
+
|
|
|
79af3c |
+ if not isinstance(section, str):
|
|
|
79af3c |
+ raise TypeError("section names must be strings")
|
|
|
79af3c |
+ if not isinstance(option, str):
|
|
|
79af3c |
+ raise TypeError("option keys must be strings")
|
|
|
79af3c |
+ if not self._allow_no_value or value:
|
|
|
79af3c |
+ if not isinstance(value, str):
|
|
|
79af3c |
+ raise TypeError("option values must be strings")
|
|
|
79af3c |
+
|
|
|
79af3c |
+ return section, option, value
|
|
|
79af3c |
+
|
|
|
79af3c |
+ @property
|
|
|
79af3c |
+ def converters(self):
|
|
|
79af3c |
+ return self._converters
|
|
|
79af3c |
+
|
|
|
79af3c |
+
|
|
|
79af3c |
+class ConfigParser(RawConfigParser):
|
|
|
79af3c |
+ """ConfigParser implementing interpolation."""
|
|
|
79af3c |
+
|
|
|
79af3c |
+ _DEFAULT_INTERPOLATION = BasicInterpolation()
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def set(self, section, option, value=None):
|
|
|
79af3c |
+ """Set an option. Extends RawConfigParser.set by validating type and
|
|
|
79af3c |
+ interpolation syntax on the value."""
|
|
|
79af3c |
+ _, option, value = self._validate_value_types(option=option, value=value)
|
|
|
79af3c |
+ super(ConfigParser, self).set(section, option, value)
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def add_section(self, section):
|
|
|
79af3c |
+ """Create a new section in the configuration. Extends
|
|
|
79af3c |
+ RawConfigParser.add_section by validating if the section name is
|
|
|
79af3c |
+ a string."""
|
|
|
79af3c |
+ section, _, _ = self._validate_value_types(section=section)
|
|
|
79af3c |
+ super(ConfigParser, self).add_section(section)
|
|
|
79af3c |
+
|
|
|
79af3c |
+
|
|
|
79af3c |
+class SafeConfigParser(ConfigParser):
|
|
|
79af3c |
+ """ConfigParser alias for backwards compatibility purposes."""
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def __init__(self, *args, **kwargs):
|
|
|
79af3c |
+ super(SafeConfigParser, self).__init__(*args, **kwargs)
|
|
|
79af3c |
+ warnings.warn(
|
|
|
79af3c |
+ "The SafeConfigParser class has been renamed to ConfigParser "
|
|
|
79af3c |
+ "in Python 3.2. This alias will be removed in future versions."
|
|
|
79af3c |
+ " Use ConfigParser directly instead.",
|
|
|
79af3c |
+ DeprecationWarning, stacklevel=2
|
|
|
79af3c |
+ )
|
|
|
79af3c |
+
|
|
|
79af3c |
+
|
|
|
79af3c |
+class SectionProxy(MutableMapping):
|
|
|
79af3c |
+ """A proxy for a single section from a parser."""
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def __init__(self, parser, name):
|
|
|
79af3c |
+ """Creates a view on a section of the specified `name` in `parser`."""
|
|
|
79af3c |
+ self._parser = parser
|
|
|
79af3c |
+ self._name = name
|
|
|
79af3c |
+ for conv in parser.converters:
|
|
|
79af3c |
+ key = 'get' + conv
|
|
|
79af3c |
+ getter = functools.partial(self.get, _impl=getattr(parser, key))
|
|
|
79af3c |
+ setattr(self, key, getter)
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def __repr__(self):
|
|
|
79af3c |
+ return '<Section: {0}>'.format(self._name)
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def __getitem__(self, key):
|
|
|
79af3c |
+ if not self._parser.has_option(self._name, key):
|
|
|
79af3c |
+ raise KeyError(key)
|
|
|
79af3c |
+ return self._parser.get(self._name, key)
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def __setitem__(self, key, value):
|
|
|
79af3c |
+ _, key, value = self._parser._validate_value_types(option=key, value=value)
|
|
|
79af3c |
+ return self._parser.set(self._name, key, value)
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def __delitem__(self, key):
|
|
|
79af3c |
+ if not (self._parser.has_option(self._name, key) and
|
|
|
79af3c |
+ self._parser.remove_option(self._name, key)):
|
|
|
79af3c |
+ raise KeyError(key)
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def __contains__(self, key):
|
|
|
79af3c |
+ return self._parser.has_option(self._name, key)
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def __len__(self):
|
|
|
79af3c |
+ return len(self._options())
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def __iter__(self):
|
|
|
79af3c |
+ return self._options().__iter__()
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def _options(self):
|
|
|
79af3c |
+ if self._name != self._parser.default_section:
|
|
|
79af3c |
+ return self._parser.options(self._name)
|
|
|
79af3c |
+ else:
|
|
|
79af3c |
+ return self._parser.defaults()
|
|
|
79af3c |
+
|
|
|
79af3c |
+ @property
|
|
|
79af3c |
+ def parser(self):
|
|
|
79af3c |
+ # The parser object of the proxy is read-only.
|
|
|
79af3c |
+ return self._parser
|
|
|
79af3c |
+
|
|
|
79af3c |
+ @property
|
|
|
79af3c |
+ def name(self):
|
|
|
79af3c |
+ # The name of the section on a proxy is read-only.
|
|
|
79af3c |
+ return self._name
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def get(self, option, fallback=None, **kwargs):
|
|
|
79af3c |
+ """Get an option value.
|
|
|
79af3c |
+
|
|
|
79af3c |
+ Unless `fallback` is provided, `None` will be returned if the option
|
|
|
79af3c |
+ is not found.
|
|
|
79af3c |
+
|
|
|
79af3c |
+ """
|
|
|
79af3c |
+ # keyword-only arguments
|
|
|
79af3c |
+ kwargs.setdefault('raw', False)
|
|
|
79af3c |
+ kwargs.setdefault('vars', None)
|
|
|
79af3c |
+ _impl = kwargs.pop('_impl', None)
|
|
|
79af3c |
+ # If `_impl` is provided, it should be a getter method on the parser
|
|
|
79af3c |
+ # object that provides the desired type conversion.
|
|
|
79af3c |
+ if not _impl:
|
|
|
79af3c |
+ _impl = self._parser.get
|
|
|
79af3c |
+ return _impl(self._name, option, fallback=fallback, **kwargs)
|
|
|
79af3c |
+
|
|
|
79af3c |
+
|
|
|
79af3c |
+class ConverterMapping(MutableMapping):
|
|
|
79af3c |
+ """Enables reuse of get*() methods between the parser and section proxies.
|
|
|
79af3c |
+
|
|
|
79af3c |
+ If a parser class implements a getter directly, the value for the given
|
|
|
79af3c |
+ key will be ``None``. The presence of the converter name here enables
|
|
|
79af3c |
+ section proxies to find and use the implementation on the parser class.
|
|
|
79af3c |
+ """
|
|
|
79af3c |
+
|
|
|
79af3c |
+ GETTERCRE = re.compile(r"^get(?P<name>.+)$")
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def __init__(self, parser):
|
|
|
79af3c |
+ self._parser = parser
|
|
|
79af3c |
+ self._data = {}
|
|
|
79af3c |
+ for getter in dir(self._parser):
|
|
|
79af3c |
+ m = self.GETTERCRE.match(getter)
|
|
|
79af3c |
+ if not m or not callable(getattr(self._parser, getter)):
|
|
|
79af3c |
+ continue
|
|
|
79af3c |
+ self._data[m.group('name')] = None # See class docstring.
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def __getitem__(self, key):
|
|
|
79af3c |
+ return self._data[key]
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def __setitem__(self, key, value):
|
|
|
79af3c |
+ try:
|
|
|
79af3c |
+ k = 'get' + key
|
|
|
79af3c |
+ except TypeError:
|
|
|
79af3c |
+ raise ValueError('Incompatible key: {} (type: {})'
|
|
|
79af3c |
+ ''.format(key, type(key)))
|
|
|
79af3c |
+ if k == 'get':
|
|
|
79af3c |
+ raise ValueError('Incompatible key: cannot use "" as a name')
|
|
|
79af3c |
+ self._data[key] = value
|
|
|
79af3c |
+ func = functools.partial(self._parser._get_conv, conv=value)
|
|
|
79af3c |
+ func.converter = value
|
|
|
79af3c |
+ setattr(self._parser, k, func)
|
|
|
79af3c |
+ for proxy in self._parser.values():
|
|
|
79af3c |
+ getter = functools.partial(proxy.get, _impl=func)
|
|
|
79af3c |
+ setattr(proxy, k, getter)
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def __delitem__(self, key):
|
|
|
79af3c |
+ try:
|
|
|
79af3c |
+ k = 'get' + (key or None)
|
|
|
79af3c |
+ except TypeError:
|
|
|
79af3c |
+ raise KeyError(key)
|
|
|
79af3c |
+ del self._data[key]
|
|
|
79af3c |
+ for inst in itertools.chain((self._parser,), self._parser.values()):
|
|
|
79af3c |
+ try:
|
|
|
79af3c |
+ delattr(inst, k)
|
|
|
79af3c |
+ except AttributeError:
|
|
|
79af3c |
+ # don't raise since the entry was present in _data, silently
|
|
|
79af3c |
+ # clean up
|
|
|
79af3c |
+ continue
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def __iter__(self):
|
|
|
79af3c |
+ return iter(self._data)
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def __len__(self):
|
|
|
79af3c |
+ return len(self._data)
|
|
|
79af3c |
diff --git a/custodia/vendor/backports/configparser/helpers.py b/custodia/vendor/backports/configparser/helpers.py
|
|
|
79af3c |
new file mode 100644
|
|
|
79af3c |
index 0000000..c47662f
|
|
|
79af3c |
--- /dev/null
|
|
|
79af3c |
+++ b/custodia/vendor/backports/configparser/helpers.py
|
|
|
79af3c |
@@ -0,0 +1,171 @@
|
|
|
79af3c |
+#!/usr/bin/env python
|
|
|
79af3c |
+# -*- coding: utf-8 -*-
|
|
|
79af3c |
+
|
|
|
79af3c |
+from __future__ import absolute_import
|
|
|
79af3c |
+from __future__ import division
|
|
|
79af3c |
+from __future__ import print_function
|
|
|
79af3c |
+from __future__ import unicode_literals
|
|
|
79af3c |
+
|
|
|
79af3c |
+from collections import MutableMapping
|
|
|
79af3c |
+try:
|
|
|
79af3c |
+ from collections import UserDict
|
|
|
79af3c |
+except ImportError:
|
|
|
79af3c |
+ from UserDict import UserDict
|
|
|
79af3c |
+
|
|
|
79af3c |
+try:
|
|
|
79af3c |
+ from collections import OrderedDict
|
|
|
79af3c |
+except ImportError:
|
|
|
79af3c |
+ from ordereddict import OrderedDict
|
|
|
79af3c |
+
|
|
|
79af3c |
+from io import open
|
|
|
79af3c |
+import sys
|
|
|
79af3c |
+try:
|
|
|
79af3c |
+ from thread import get_ident
|
|
|
79af3c |
+except ImportError:
|
|
|
79af3c |
+ try:
|
|
|
79af3c |
+ from _thread import get_ident
|
|
|
79af3c |
+ except ImportError:
|
|
|
79af3c |
+ from _dummy_thread import get_ident
|
|
|
79af3c |
+
|
|
|
79af3c |
+
|
|
|
79af3c |
+PY2 = sys.version_info[0] == 2
|
|
|
79af3c |
+PY3 = sys.version_info[0] == 3
|
|
|
79af3c |
+
|
|
|
79af3c |
+str = type('str')
|
|
|
79af3c |
+
|
|
|
79af3c |
+
|
|
|
79af3c |
+def from_none(exc):
|
|
|
79af3c |
+ """raise from_none(ValueError('a')) == raise ValueError('a') from None"""
|
|
|
79af3c |
+ exc.__cause__ = None
|
|
|
79af3c |
+ exc.__suppress_context__ = True
|
|
|
79af3c |
+ return exc
|
|
|
79af3c |
+
|
|
|
79af3c |
+
|
|
|
79af3c |
+# from reprlib 3.2.1
|
|
|
79af3c |
+def recursive_repr(fillvalue='...'):
|
|
|
79af3c |
+ 'Decorator to make a repr function return fillvalue for a recursive call'
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def decorating_function(user_function):
|
|
|
79af3c |
+ repr_running = set()
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def wrapper(self):
|
|
|
79af3c |
+ key = id(self), get_ident()
|
|
|
79af3c |
+ if key in repr_running:
|
|
|
79af3c |
+ return fillvalue
|
|
|
79af3c |
+ repr_running.add(key)
|
|
|
79af3c |
+ try:
|
|
|
79af3c |
+ result = user_function(self)
|
|
|
79af3c |
+ finally:
|
|
|
79af3c |
+ repr_running.discard(key)
|
|
|
79af3c |
+ return result
|
|
|
79af3c |
+
|
|
|
79af3c |
+ # Can't use functools.wraps() here because of bootstrap issues
|
|
|
79af3c |
+ wrapper.__module__ = getattr(user_function, '__module__')
|
|
|
79af3c |
+ wrapper.__doc__ = getattr(user_function, '__doc__')
|
|
|
79af3c |
+ wrapper.__name__ = getattr(user_function, '__name__')
|
|
|
79af3c |
+ wrapper.__annotations__ = getattr(user_function, '__annotations__', {})
|
|
|
79af3c |
+ return wrapper
|
|
|
79af3c |
+
|
|
|
79af3c |
+ return decorating_function
|
|
|
79af3c |
+
|
|
|
79af3c |
+# from collections 3.2.1
|
|
|
79af3c |
+class _ChainMap(MutableMapping):
|
|
|
79af3c |
+ ''' A ChainMap groups multiple dicts (or other mappings) together
|
|
|
79af3c |
+ to create a single, updateable view.
|
|
|
79af3c |
+
|
|
|
79af3c |
+ The underlying mappings are stored in a list. That list is public and can
|
|
|
79af3c |
+ accessed or updated using the *maps* attribute. There is no other state.
|
|
|
79af3c |
+
|
|
|
79af3c |
+ Lookups search the underlying mappings successively until a key is found.
|
|
|
79af3c |
+ In contrast, writes, updates, and deletions only operate on the first
|
|
|
79af3c |
+ mapping.
|
|
|
79af3c |
+
|
|
|
79af3c |
+ '''
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def __init__(self, *maps):
|
|
|
79af3c |
+ '''Initialize a ChainMap by setting *maps* to the given mappings.
|
|
|
79af3c |
+ If no mappings are provided, a single empty dictionary is used.
|
|
|
79af3c |
+
|
|
|
79af3c |
+ '''
|
|
|
79af3c |
+ self.maps = list(maps) or [{}] # always at least one map
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def __missing__(self, key):
|
|
|
79af3c |
+ raise KeyError(key)
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def __getitem__(self, key):
|
|
|
79af3c |
+ for mapping in self.maps:
|
|
|
79af3c |
+ try:
|
|
|
79af3c |
+ return mapping[key] # can't use 'key in mapping' with defaultdict
|
|
|
79af3c |
+ except KeyError:
|
|
|
79af3c |
+ pass
|
|
|
79af3c |
+ return self.__missing__(key) # support subclasses that define __missing__
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def get(self, key, default=None):
|
|
|
79af3c |
+ return self[key] if key in self else default
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def __len__(self):
|
|
|
79af3c |
+ return len(set().union(*self.maps)) # reuses stored hash values if possible
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def __iter__(self):
|
|
|
79af3c |
+ return iter(set().union(*self.maps))
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def __contains__(self, key):
|
|
|
79af3c |
+ return any(key in m for m in self.maps)
|
|
|
79af3c |
+
|
|
|
79af3c |
+ @recursive_repr()
|
|
|
79af3c |
+ def __repr__(self):
|
|
|
79af3c |
+ return '{0.__class__.__name__}({1})'.format(
|
|
|
79af3c |
+ self, ', '.join(map(repr, self.maps)))
|
|
|
79af3c |
+
|
|
|
79af3c |
+ @classmethod
|
|
|
79af3c |
+ def fromkeys(cls, iterable, *args):
|
|
|
79af3c |
+ 'Create a ChainMap with a single dict created from the iterable.'
|
|
|
79af3c |
+ return cls(dict.fromkeys(iterable, *args))
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def copy(self):
|
|
|
79af3c |
+ 'New ChainMap or subclass with a new copy of maps[0] and refs to maps[1:]'
|
|
|
79af3c |
+ return self.__class__(self.maps[0].copy(), *self.maps[1:])
|
|
|
79af3c |
+
|
|
|
79af3c |
+ __copy__ = copy
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def new_child(self): # like Django's Context.push()
|
|
|
79af3c |
+ 'New ChainMap with a new dict followed by all previous maps.'
|
|
|
79af3c |
+ return self.__class__({}, *self.maps)
|
|
|
79af3c |
+
|
|
|
79af3c |
+ @property
|
|
|
79af3c |
+ def parents(self): # like Django's Context.pop()
|
|
|
79af3c |
+ 'New ChainMap from maps[1:].'
|
|
|
79af3c |
+ return self.__class__(*self.maps[1:])
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def __setitem__(self, key, value):
|
|
|
79af3c |
+ self.maps[0][key] = value
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def __delitem__(self, key):
|
|
|
79af3c |
+ try:
|
|
|
79af3c |
+ del self.maps[0][key]
|
|
|
79af3c |
+ except KeyError:
|
|
|
79af3c |
+ raise KeyError('Key not found in the first mapping: {!r}'.format(key))
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def popitem(self):
|
|
|
79af3c |
+ 'Remove and return an item pair from maps[0]. Raise KeyError is maps[0] is empty.'
|
|
|
79af3c |
+ try:
|
|
|
79af3c |
+ return self.maps[0].popitem()
|
|
|
79af3c |
+ except KeyError:
|
|
|
79af3c |
+ raise KeyError('No keys found in the first mapping.')
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def pop(self, key, *args):
|
|
|
79af3c |
+ 'Remove *key* from maps[0] and return its value. Raise KeyError if *key* not in maps[0].'
|
|
|
79af3c |
+ try:
|
|
|
79af3c |
+ return self.maps[0].pop(key, *args)
|
|
|
79af3c |
+ except KeyError:
|
|
|
79af3c |
+ raise KeyError('Key not found in the first mapping: {!r}'.format(key))
|
|
|
79af3c |
+
|
|
|
79af3c |
+ def clear(self):
|
|
|
79af3c |
+ 'Clear maps[0], leaving maps[1:] intact.'
|
|
|
79af3c |
+ self.maps[0].clear()
|
|
|
79af3c |
+
|
|
|
79af3c |
+
|
|
|
79af3c |
+try:
|
|
|
79af3c |
+ from collections import ChainMap
|
|
|
79af3c |
+except ImportError:
|
|
|
79af3c |
+ ChainMap = _ChainMap
|
|
|
79af3c |
diff --git a/custodia/vendor/configparser.py b/custodia/vendor/configparser.py
|
|
|
79af3c |
new file mode 100644
|
|
|
79af3c |
index 0000000..b899f9e
|
|
|
79af3c |
--- /dev/null
|
|
|
79af3c |
+++ b/custodia/vendor/configparser.py
|
|
|
79af3c |
@@ -0,0 +1,52 @@
|
|
|
79af3c |
+#!/usr/bin/env python
|
|
|
79af3c |
+# -*- coding: utf-8 -*-
|
|
|
79af3c |
+
|
|
|
79af3c |
+"""Convenience module importing everything from backports.configparser."""
|
|
|
79af3c |
+
|
|
|
79af3c |
+from __future__ import absolute_import
|
|
|
79af3c |
+from __future__ import division
|
|
|
79af3c |
+from __future__ import print_function
|
|
|
79af3c |
+from __future__ import unicode_literals
|
|
|
79af3c |
+
|
|
|
79af3c |
+
|
|
|
79af3c |
+from backports.configparser import (
|
|
|
79af3c |
+ RawConfigParser,
|
|
|
79af3c |
+ ConfigParser,
|
|
|
79af3c |
+ SafeConfigParser,
|
|
|
79af3c |
+ SectionProxy,
|
|
|
79af3c |
+
|
|
|
79af3c |
+ Interpolation,
|
|
|
79af3c |
+ BasicInterpolation,
|
|
|
79af3c |
+ ExtendedInterpolation,
|
|
|
79af3c |
+ LegacyInterpolation,
|
|
|
79af3c |
+
|
|
|
79af3c |
+ Error,
|
|
|
79af3c |
+ NoSectionError,
|
|
|
79af3c |
+ DuplicateSectionError,
|
|
|
79af3c |
+ DuplicateOptionError,
|
|
|
79af3c |
+ NoOptionError,
|
|
|
79af3c |
+ InterpolationError,
|
|
|
79af3c |
+ InterpolationMissingOptionError,
|
|
|
79af3c |
+ InterpolationSyntaxError,
|
|
|
79af3c |
+ InterpolationDepthError,
|
|
|
79af3c |
+ ParsingError,
|
|
|
79af3c |
+ MissingSectionHeaderError,
|
|
|
79af3c |
+ ConverterMapping,
|
|
|
79af3c |
+
|
|
|
79af3c |
+ _UNSET,
|
|
|
79af3c |
+ DEFAULTSECT,
|
|
|
79af3c |
+ MAX_INTERPOLATION_DEPTH,
|
|
|
79af3c |
+ _default_dict,
|
|
|
79af3c |
+ _ChainMap,
|
|
|
79af3c |
+)
|
|
|
79af3c |
+
|
|
|
79af3c |
+__all__ = ["NoSectionError", "DuplicateOptionError", "DuplicateSectionError",
|
|
|
79af3c |
+ "NoOptionError", "InterpolationError", "InterpolationDepthError",
|
|
|
79af3c |
+ "InterpolationMissingOptionError", "InterpolationSyntaxError",
|
|
|
79af3c |
+ "ParsingError", "MissingSectionHeaderError",
|
|
|
79af3c |
+ "ConfigParser", "SafeConfigParser", "RawConfigParser",
|
|
|
79af3c |
+ "Interpolation", "BasicInterpolation", "ExtendedInterpolation",
|
|
|
79af3c |
+ "LegacyInterpolation", "SectionProxy", "ConverterMapping",
|
|
|
79af3c |
+ "DEFAULTSECT", "MAX_INTERPOLATION_DEPTH"]
|
|
|
79af3c |
+
|
|
|
79af3c |
+# NOTE: names missing from __all__ imported anyway for backwards compatibility.
|
|
|
79af3c |
--
|
|
|
79af3c |
2.9.3
|
|
|
79af3c |
|