Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ConfigParser can't interpolate values from other sections #54085

Closed
asolovyov mannequin opened this issue Sep 16, 2010 · 3 comments
Closed

ConfigParser can't interpolate values from other sections #54085

asolovyov mannequin opened this issue Sep 16, 2010 · 3 comments
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@asolovyov
Copy link
Mannequin

asolovyov mannequin commented Sep 16, 2010

BPO 9876
Nosy @freddrake, @merwok, @ambv
Superseder
  • bpo-10499: Modular interpolation in configparser
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2010-11-22.03:20:05.036>
    created_at = <Date 2010-09-16.16:38:04.774>
    labels = ['type-feature', 'library']
    title = "ConfigParser can't interpolate values from other sections"
    updated_at = <Date 2010-11-22.03:20:05.034>
    user = 'https://bugs.python.org/asolovyov'

    bugs.python.org fields:

    activity = <Date 2010-11-22.03:20:05.034>
    actor = 'lukasz.langa'
    assignee = 'none'
    closed = True
    closed_date = <Date 2010-11-22.03:20:05.036>
    closer = 'lukasz.langa'
    components = ['Library (Lib)']
    creation = <Date 2010-09-16.16:38:04.774>
    creator = 'asolovyov'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 9876
    keywords = []
    message_count = 3.0
    messages = ['116573', '116609', '122080']
    nosy_count = 4.0
    nosy_names = ['fdrake', 'eric.araujo', 'lukasz.langa', 'asolovyov']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = None
    status = 'closed'
    superseder = '10499'
    type = 'enhancement'
    url = 'https://bugs.python.org/issue9876'
    versions = ['Python 3.2']

    @asolovyov
    Copy link
    Mannequin Author

    asolovyov mannequin commented Sep 16, 2010

    Often it is useful to access some variable in other section for interpolation needs: for example, parent directory declared in common section could be used in configuration of certain components. Included patch can fix that (using syntax 'section.variable'), is there any chances that it could be applied? :)

    --- ConfigParser.old.py	2010-09-16 19:20:27.000000000 +0300
    +++ ConfigParser.py	2010-09-16 19:22:33.000000000 +0300
    @@ -585,7 +585,7 @@
                 if "%(" in value:
                     value = self._KEYCRE.sub(self._interpolation_replace, value)
                     try:
    -                    value = value % vars
    +                    value = value % _Context(self, section)
                     except KeyError, e:
                         raise InterpolationMissingOptionError(
                             option, section, rawval, e.args[0])
    @@ -667,3 +667,15 @@
                 raise ValueError("invalid interpolation syntax in %r at "
                                  "position %d" % (value, m.start()))
             ConfigParser.set(self, section, option, value)
    +
    +
    +class _Context(object):
    +    def __init__(self, config, section):
    +        self.config = config
    +        self.section = section
    +
    +    def __getitem__(self, key):
    +        if '.' in key:
    +            return self.config.get(*key.split('.'))
    +        else:
    +            return self.config.get(self.section, key)

    @asolovyov asolovyov mannequin added stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Sep 16, 2010
    @merwok
    Copy link
    Member

    merwok commented Sep 16, 2010

    Stable versions don’t get new features, only bug fixes.

    @ambv
    Copy link
    Contributor

    ambv commented Nov 22, 2010

    Hopefully a form of this feature will be introduced as part of bpo-10499. The discussion goes on there.

    @ambv ambv closed this as completed Nov 22, 2010
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants