ssato / python-anyconfig

Python library provides common APIs to load and dump configuration files in various formats
MIT License
278 stars 31 forks source link

anyconfig_cli cannot load and dump XML files as expected #106

Closed ssato closed 5 years ago

ssato commented 5 years ago
ssato@x1-carbon-gen6% anyconfig_cli -I xml /etc/xml/catalog
Traceback (most recent call last):
  File "/usr/bin/anyconfig_cli", line 11, in <module>
    load_entry_point('anyconfig==0.9.8', 'console_scripts', 'anyconfig_cli')()
  File "/usr/lib/python3.7/site-packages/anyconfig/cli.py", line 381, in main
    _output_result(cnf, args.output, args.otype, args.inputs, args.itype)
  File "/usr/lib/python3.7/site-packages/anyconfig/cli.py", line 319, in _output_result
    _try_dump(cnf, outpath, otype, fmsg)
  File "/usr/lib/python3.7/site-packages/anyconfig/cli.py", line 293, in _try_dump
    API.dump(cnf, outpath, otype)
  File "/usr/lib/python3.7/site-packages/anyconfig/api.py", line 545, in dump
    psr.dump(data, ioi, **options)
  File "/usr/lib/python3.7/site-packages/anyconfig/backend/base.py", line 377, in dump
    self.dump_to_stream(cnf, ioi.src, **kwargs)
  File "/usr/lib/python3.7/site-packages/anyconfig/backend/xml.py", line 544, in dump_to_stream
    etree_write(tree, stream)
  File "/usr/lib/python3.7/site-packages/anyconfig/backend/xml.py", line 462, in etree_write
    tree.write(stream, encoding='UTF-8', xml_declaration=True)
  File "/usr/lib64/python3.7/xml/etree/ElementTree.py", line 777, in write
    short_empty_elements=short_empty_elements)
  File "/usr/lib64/python3.7/contextlib.py", line 119, in __exit__
    next(self.gen)
  File "/usr/lib64/python3.7/xml/etree/ElementTree.py", line 836, in _get_writer
    yield file.write
  File "/usr/lib64/python3.7/contextlib.py", line 511, in __exit__
    raise exc_details[1]
  File "/usr/lib64/python3.7/contextlib.py", line 496, in __exit__
    if cb(*exc_details):
  File "/usr/lib64/python3.7/contextlib.py", line 383, in _exit_wrapper
    callback(*args, **kwds)
TypeError: write() argument must be str, not bytes
ssato@x1-carbon-gen6%
ssato commented 5 years ago

It may be fixed by the commit 0266f5b.

$ PYTHONPATH=src python3 src/anyconfig/cli.py tests/res/00-01-cnf.json --extra-opts indent:2
{
  "b": {
    "b": [
      1,
      2
    ],
    "c": "C"
  }
}$