PiotrDabkowski / Js2Py

JavaScript to Python Translator & JavaScript interpreter written in 100% pure Python🚀 Try it online:
http://piter.io/projects/js2py
MIT License
2.47k stars 261 forks source link

decodeURIComponent ERROR report #62

Open pendave opened 8 years ago

pendave commented 8 years ago

js2py.base.PyJsException: ReferenceError: decodeURIComponent is not defined

Is this js command not supported? Thanks

worstperson commented 8 years ago

No, not implemented yet. You can always define them though:

import js2py
context = js2py.EvalJs()
context.execute("""escape = function(text){pyimport urllib; return urllib.quote(text)};
unescape = function(text){pyimport urllib; return urllib.unquote(text)};
encodeURI = function(text){pyimport urllib; return urllib.quote(text, safe='~@#$&()*!+=:;,.?/\\'')};
decodeURI = unescape;
encodeURIComponent = function(text){pyimport urllib; return urllib.quote(text, safe='~()*!.\\'')};
decodeURIComponent = unescape;""")

That's just a basic example that can handle most common instances, you might need to extend on it if you need unicode support or hit a corner case.

pendave commented 8 years ago

Cool

PiotrDabkowski commented 8 years ago

That's an omission, will fix that problem soon!

miigotu commented 4 years ago

This is still broken =P