jwodder / javaproperties

Python library for reading & writing Java .properties files
MIT License
30 stars 10 forks source link

Support for multilevel dict #6

Closed BrotherLavarius closed 5 years ago

BrotherLavarius commented 5 years ago

Hi i wanted to write an ansible module using your lib, but stumbled to the issue that it for some reason doesn't support multilevel dict.

example:


properties=(''' 
--- 
aeron:
  cluster:
    dir: some/cool/text
''')

    return re.sub(r'[^\x20-\x7E]|[\\#!=:]', _esc, field)
  File "/usr/lib/python3.6/re.py", line 191, in sub
    return _compile(pattern, flags).sub(repl, string, count)
TypeError: expected string or bytes-like object

and i'm just using this code

    import yaml
    import javaproperties

    p = yaml.load(properties)

    print(javaproperties.dumps(p))

Am i doing something wrong here? Just didn't fund any hint in the doc's that it maybe unsupported

jwodder commented 5 years ago

.properties files themselves only represent flat, string-to-string mappings (no nested dicts), and so this library has no choice but to do likewise. If your intention is for this:

aeron:
  cluster:
    dir: some/cool/text

to be transformed into this:

aeron.cluster.dir: some/cool/text

your code will need to do the conversion itself.