-
Notifications
You must be signed in to change notification settings - Fork 148
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
Make folding for lists optional #64
base: master
Are you sure you want to change the base?
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
@@ -366,7 +372,7 @@ def convert_none(key, val, attr_type, attr={}, cdata=False): | |||
|
|||
|
|||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually need this feature. because in a specification I'm implementing both cases are necessary.
@@ -11,7 +11,7 @@ | |||
|
|||
from __future__ import unicode_literals | |||
|
|||
__version__ = '1.7.4' | |||
__version__ = '1.8.0' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.