pythonjs / pythonjs Goto Github PK
View Code? Open in Web Editor NEWPythonJS development has moved to Rusthon
Home Page: https://github.com/rusthon/Rusthon
License: Other
PythonJS development has moved to Rusthon
Home Page: https://github.com/rusthon/Rusthon
License: Other
According to this article http://sporto.github.io/blog/2013/04/12/comparison-angular-backbone-can-ember/ a modern framework should contain:
This looks great! I actually have abandoned my tornado code for Node.js/Express. Are there any benchmarks? How does this stack up against the real Tornado?
right now there is not filtering that is possible only the following syntax is supported
try:
raise SomethingIfYouWant
except:
if __exception__ == SomethingIfYouWant:
print 'ouhou'
Create more tests and implement a run_tests
function for complete check:
PythonJS very promising project.
Couple of feature suggestions after playing around for a while:
Trying to compile the simple code 10**2
gives a SyntaxError
with PythonJS 0.8.3 (installed with pip), but I noticed it works with the latest version on GitHub.
Might be a good idea to update the version on PyPi.
I have changed setup.py (line 15)
pythonscript=pythonscript.main:command
to
pythonscript=pythonscript.pythonscript:command
and it works.
This project is awesome !, i like it.
The following Python code
with javascript:
print 'o' in 'kok'
Is translated as:
console.log(Object.hasOwnProperty.call("kok", "__contains__")
&& "kok"["__contains__"]("o")
|| Object.hasOwnProperty.call("kok", "o"));
The previous code does not work, but this trivial code works as expected:
console.log("kok".__contains__('o'))
getattr is broken by a bug in test_if_true, there is the patch :
--- a/runtime/builtins.py
+++ b/runtime/builtins.py
@@ -39,6 +39,8 @@ with javascript:
return True
def __test_if_true__( ob ):
+ if JS("! ob"):
+ return False
if instanceof(ob, Array):
return ob.length != 0
elif isinstance(ob, dict):
You may add a regression test regtests/class/attr.py:
"""instance attributes"""
class A:
g = 6
def __init__(self):
self.b = 5
def main():
a = A()
TestError(a.b == 5)
TestWarning(a.g == 6)
try:
x = a.c
TestWarning(not 'No exception: on undefined attribute')
except AttributeError:
pass
TestError(getattr(a, 'b') == 5)
TestWarning(getattr(a, 'g') == 6)
# TestWarning(getattr(a, 'c', 42) == 42)
try:
getattr(a, 'c')
TestWarning(not 'No exception: getattr on undefined attribute')
except AttributeError:
pass
I did not submit a tree because I can no more recreate the same pythonjs.js file than original one, there is tons of:
- __sig__ = {"kwargs": {"property": false}, "args": __create_array__("ob", "attr", "property")};
+ __sig__ = { kwargs:{"property": false},args:__create_array__("ob", "attr", "property") };
How this should be handled since it's compiled it should maybe generate a dependency file or concate everything ?
Or just implement Python mro cf. http://www.cafepy.com/article/python_attributes_and_methods/python_attributes_and_methods.html
metaclass support is clunky right now, one must repeat in each class which behavior must overriden define the __metaclass__
attribute. Also it doesn't support class metaclasses
class A:
def init (self, _args, *_kwargs):
pass
class B( A ):
def init (self, _args, *_kwargs):
pass
var A, A_attrs, __A_parents;
__A_attrs = {};
__A_parents = create_array();
var __A___init = function(args, kwargs) {
var signature, arguments;
signature = {"kwargs": {}, "args": create_array("self"), "vararg": "args", "varkwarg": "kwargs"};
arguments = get_arguments(signature, args, kwargs);
var self = arguments['self'];
args = get_attribute(list, "call")(create_array(args));
var kwargs = arguments["kwargs"];
kwargs = get_attribute(dict, "call")(create_array(kwargs));
}
A_attrs.__init = A___init;
A = create_class("A", A_parents, __A_attrs);
var B, __B_attrs, __B_parents;
__B_attrs = {};
__B_parents = create_array();
__B_parents.push(A);
var __B___init = function(args, kwargs) {
var signature, arguments;
signature = {"kwargs": {}, "args": create_array("self"), "vararg": "args", "varkwarg": "kwargs"};
arguments = get_arguments(signature, args, kwargs);
var self = arguments['self'];
args = get_attribute(list, "call")(create_array(args));
var kwargs = arguments["kwargs"];
kwargs = get_attribute(dict, "call")(create_array(kwargs));
}
B_attrs.__init = B___init;
B = create_class("B", __B_parents, __B_attrs);
Create a pythonscript command that compiles a full project based on an entry file, something like pythonscript main.py -o app.js
which will take into account from spam import egg
Right now for loops can be buggy in certains situation not sure which yet but #13 must be fixed
...
File "...lib\ast.py", line 241, in visit
return visitor(node)
File "...PythonJS\pythonjs\pythonjs.py", line 138, in visit_Subscript
return '%s[%s]' % (self.visit(node.value), self.visit(node.slice.value))
AttributeError: 'Slice' object has no attribute 'value'
see for instance jQuery.click callback populated arguments
When translated in 'javascript' mode, 'dict' is translated as a Javascript 'Object'.
Is it possible to add some builtins methods to the Javascript 'Object' in order to better emulate a Python 'dict'?
I use for example:
@Object.prototype.get
def func(key, default_value=None):
if key in this:
return this[key]
return default_value
I believe they are alone very good for people with Python background. Let's import Python stdlib into JavaScript world. :)
How should we separate source for translation and the end products?
Documentation. It is impossible to import all Python functions, so some kind of auto-generated compatibility table would be nice. Like this one: http://buildbot.pypy.org/numpy-status/latest.html
Hi,
I am failing to get my Python module translated. PythonJS gives stack traces and I am unable to quickly determine the input lines that are causing this harm.
Is it possible to add a high level exceptional handler that is rethrows exception if it occurs, but also reports about lines in input file at the time this occurred? I think it will be a valuable property for every input processor.
sudo python is not useful as is, make it autonomous.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.