fabiocaccamo / python-benedict

:blue_book: dict subclass with keylist/keypath support, built-in I/O operations (base64, csv, html, ini, json, pickle, plist, query-string, toml, xls, xml, yaml), s3 support and many utilities.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

INI support for case sensitive keys

catchthemonster opened this issue · comments

Python version
3.10.8

Package versionpython-benedict latest

Current behavior (bug description)
optionxform = str if passed as **kwargs to
d = benedict.from_ini(s, **kwargs)
will raise the error

Expected behavior
i need support for dict keys to be camel case?

It would be nice that benedict wrapper for RawConfigParser supports this

@catchthemonster thank you for reporting this, I will fix it as soon as possible.

Thanks, @fabiocaccamo !
It looks like that only thing that needs to be done in the wrapper should be something like this:

self.a = RawConfigParser()

def confMe(**kwargs):
for key, value in kwargs.items():
if key == 'optionxform':
setattr(a, key, value)

Regards,

@catchthemonster I'm wondering if keys should be case sensitive by default when reading .ini files, what do you think?

@fabiocaccamo I think both ways, red and write in my opinion. INI is a simple but powerful template engine. Your projects are perfectly suited to be used to actually manipulate INI templates for requirements like change INI template across different working cloud environments.
I use configObj (nested sections) library to create modifications in templates ...
confObj allows me do something like this:
[iniTempalte1]
[[sec1]]
keySerer = abc
on original template, iniTemplate as:
[[sec1]]
keySerer = abc

with Benedict this becomes a piece of cake exercise of three to four line of code. The only missing part is keySensitivity and most senior devs like me, love camel case instead of Pep thing with _.

I think that overloading wrapper for configParser and allowing **kwargs to be used a vehicle to pass optionxform=str key = vaule pair and then setup by default on read and write would be a way to go and enhance this perfect work ...

btw. thank you for writing this lib...

You can upgrade to 0.30.0 version:

  • ini serializer is case-sensitive by default
  • you can now pass an optionxform option via kwargs.

Thanks, Fabio,
much appreciated ...