Conversation
Give users the ability to define dictionary or a list, where the dictionary key becomes the item name of list entries.
|
For the sake of documentation, when using the option To control the list item names per hierarchy level, a combination of nested dicts and lists shall be used. Example: Output: |
|
Looks as if this fixes #59 |
Simon-Campbell
left a comment
There was a problem hiding this comment.
Looks good, thanks for taking the time!
I am not sure if the upstream repo is accepting PRs but have left some comments to consider.
I'll pull this code into my own fork so I can make use of it.
| if fold_list: | ||
| item_name = item_func(parent) | ||
| else: | ||
| item_name = parent |
There was a problem hiding this comment.
Maybe you could explicitly fail-fast if item_func is explicitly input into dicttoxml API and fold_list is also explicitly defined to be False? Might be preferable instead of silently ignoring and causing a surprise.
|
|
||
| def dicttoxml(obj, root=True, custom_root='root', ids=False, attr_type=True, | ||
| item_func=default_item_func, cdata=False): | ||
| item_func=default_item_func, cdata=False, fold_list=True): |
There was a problem hiding this comment.
An alternative design may be to vary the result of item_func for folding. What do you think about something along the lines of the following?
# Using a dict may be a bit lazy here, but it should communicate the idea. You'd have
# to check the return type in places that use the result for backward compat.
def custom_item_func(parent):
if parent == 'Special':
return { 'name': parent, 'should_fold': True }
else:
return { 'name': parent, 'should_fold': False }
dicttoxml(…, item_func = custom_item_func)This would enable you to vary the behavior based on the element or some condition. It may also simplify the number of parameters being passed about in the implementation?
As another note: in VS Code that there is no doc comment for the new parameter, it might be worth adding it to help with visibility and documentation 😄
There was a problem hiding this comment.
I actually need this feature. because in a specification I'm implementing both cases are necessary.
| from __future__ import unicode_literals | ||
|
|
||
| __version__ = '1.7.4' | ||
| __version__ = '1.8.0' |
There was a problem hiding this comment.
Might also want to bump this in setup.py so it's recognized by pip :-)
|
Hi @BobStein and @Simon-Campbell, fold_list feature looks useful for me as well. Do you know when it will be released to pip? Thanks |
|
@sonaysevik I am not a maintainer, that question would have to be directed at @quandyfactory 👍 At the moment I have forked the branch I need and am pulling it into pip using a zip e.g. GitHub has a feature to pull zip based on commit hash. I'm using this as a poor man's version lock for the package. |
|
@Simon-Campbell @quandyfactory I could use this functionality to meet schema requirements by a vendor but I can't in good conscience deploy production using a commit hash on a fork. Any plans to merge this into master? |
|
The same requirements as @optik-aper, is there any blocking issues of merging? |
|
Is @quandyfactory alive? |
|
Any possibility that this PR can be merged, or is there something I can help with to get it merged? |
|
Taken and fixed in (fork) https://github.com/Ousret/dicttoxml/releases/tag/2.1.0 |
Give users the ability to define dictionary or a list, where the dictionary key becomes the item name of list entries.
This pull request is merging PR#42 with the latest release 1.7.4 of dicttoxml.