Open dairiki opened 4 years ago
Some comments extracted/duplicated from PR #185
Problem: I had been relying on a hack to support JSON-esque serialization of values containing literal javascript using json.JSONEncoder from python’s standard library. It seems that my hack is not feasible in any version of python after 2.6 (). (My hack involved overriding JSONEncoder._iterencode, which does not exist in python >= 2.7.)
My hacked up version of JSONEncoder
is JSONConfigSerializer
in widget.py, which works with the new literal_js
marker class which is defined just above it. The two unit tests which are currently failing are a result of these hacks not working in recent versions of python.
I see two ways forward:
@stevepiercy responded:
Does this thread describe the same issue https://stackoverflow.com/a/53848267/2214933?
Does
jsons
do what is needed?
No, I think this is a different problem. At the root is the fact that we want to be able to serialize python data structures to javascript expressions which are not necessarily valid JSON. E.g. one would like to be able to include javascript function expressions, as well as function and variable names in the serialized result.
This is a redo of PR #185, rebased onto the current master branch.