Skip to content

Improved with ast2dict and ast2json and compatible with python2 and python3.#1

Open
edelvalle wants to merge 4 commits intoYoloSwagTeam:masterfrom
edelvalle:master
Open

Improved with ast2dict and ast2json and compatible with python2 and python3.#1
edelvalle wants to merge 4 commits intoYoloSwagTeam:masterfrom
edelvalle:master

Conversation

@edelvalle
Copy link
Copy Markdown

No description provided.

@Psycojoker
Copy link
Copy Markdown
Member

Hello,

Thanks for your PR :)

I've been trying to prettify the xml and while doing this, I've discovered that your code doesn't correctly escape strings which causes minidom to complain. You can test this by doing:

python ast2json.py ast2json.py

My code is here: https://github.com/Psycojoker/ast2json/tree/xml_and_stuff

I guess that we'll have to find a way to correctly escape the strings or to build the xml another way using a lib lke minidom https://docs.python.org/2/library/xml.dom.minidom.html

My current (dirty) attempt to do this is:

attrs.append('%(attr)s=%(value)s' % {"attr": attr, "value": json.dumps(value) if isinstance(value, basestring) else '"%s"' % value})

for this line https://github.com/Psycojoker/ast2json/blob/943039a363c3fa0080c740c787c2243d6d61048c/ast2json.py#L87 and it's not a success at all.

This new feature should also be added to the documentation.

Kind regards,

@edelvalle
Copy link
Copy Markdown
Author

Hi,

Ohh.. you are right... sorry. It will be nice to have a propper XML.

We also need to add the pyyaml dependency in the setup.py becuase I also added a YAML encoder.

I will check your code later.

See you around, Ed.

@Psycojoker
Copy link
Copy Markdown
Member

Psycojoker commented Sep 14, 2015 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants