equal
deleted
inserted
replaced
50 # this is the python function used to wrap native javascript |
50 # this is the python function used to wrap native javascript |
51 NATIVE_JS_FUNC_NAME = "JS" |
51 NATIVE_JS_FUNC_NAME = "JS" |
52 |
52 |
53 UU = "" |
53 UU = "" |
54 |
54 |
55 PYJSLIB_BUILTIN_FUNCTIONS=("cmp", |
55 PYJSLIB_BUILTIN_FUNCTIONS = ("cmp", |
56 "map", |
56 "map", |
57 "filter", |
57 "filter", |
58 "dir", |
58 "dir", |
59 "getattr", |
59 "getattr", |
60 "setattr", |
60 "setattr", |
61 "hasattr", |
61 "hasattr", |
62 "int", |
62 "int", |
63 "float", |
63 "float", |
64 "str", |
64 "str", |
65 "repr", |
65 "repr", |
66 "range", |
66 "range", |
67 "len", |
67 "len", |
68 "hash", |
68 "hash", |
69 "abs", |
69 "abs", |
70 "ord", |
70 "ord", |
71 "chr", |
71 "chr", |
72 "enumerate", |
72 "enumerate", |
73 "min", |
73 "min", |
74 "max", |
74 "max", |
75 "bool", |
75 "bool", |
76 "type", |
76 "type", |
77 "isinstance") |
77 "isinstance") |
78 |
78 |
79 PYJSLIB_BUILTIN_CLASSES=("BaseException", |
79 PYJSLIB_BUILTIN_CLASSES = ("BaseException", |
80 "Exception", |
80 "Exception", |
81 "StandardError", |
81 "StandardError", |
82 "StopIteration", |
82 "StopIteration", |
83 "AttributeError", |
83 "AttributeError", |
84 "TypeError", |
84 "TypeError", |
85 "KeyError", |
85 "KeyError", |
86 "LookupError", |
86 "LookupError", |
87 "list", |
87 "list", |
88 "dict", |
88 "dict", |
89 "object", |
89 "object", |
90 "tuple", |
90 "tuple", |
91 ) |
91 ) |
92 |
92 |
93 |
93 |
94 def pyjs_builtin_remap(name): |
94 def pyjs_builtin_remap(name): |
95 # XXX HACK! |
95 # XXX HACK! |
96 if name == 'list': |
96 if name == 'list': |
104 return name |
104 return name |
105 |
105 |
106 # XXX: this is a hack: these should be dealt with another way |
106 # XXX: this is a hack: these should be dealt with another way |
107 # however, console is currently the only global name which is causing |
107 # however, console is currently the only global name which is causing |
108 # problems. |
108 # problems. |
109 PYJS_GLOBAL_VARS=("console") |
109 PYJS_GLOBAL_VARS = ("console") |
110 |
110 |
111 # This is taken from the django project. |
111 # This is taken from the django project. |
112 # Escape every ASCII character with a value less than 32. |
112 # Escape every ASCII character with a value less than 32. |
113 JS_ESCAPES = ( |
113 JS_ESCAPES = ( |
114 ('\\', r'\x5C'), |
114 ('\\', r'\x5C'), |
402 # else: |
402 # else: |
403 # raise TranslationError("unsupported type (in _method)", default_node) |
403 # raise TranslationError("unsupported type (in _method)", default_node) |
404 |
404 |
405 default_name = arg_names[default_pos] |
405 default_name = arg_names[default_pos] |
406 print >>self.output, " if (typeof %s == 'undefined')" % (default_name) |
406 print >>self.output, " if (typeof %s == 'undefined')" % (default_name) |
407 print >>self.output, " %s=__kwargs.%s;"% (default_name, default_name) |
407 print >>self.output, " %s=__kwargs.%s;" % (default_name, default_name) |
408 default_pos += 1 |
408 default_pos += 1 |
409 |
409 |
410 #self._default_args_handler(node, arg_names, current_klass) |
410 #self._default_args_handler(node, arg_names, current_klass) |
411 if node.kwargs: arg_names += ["pyjslib.Dict(__kwargs)"] |
411 if node.kwargs: arg_names += ["pyjslib.Dict(__kwargs)"] |
412 print >>self.output, " var __r = "+"".join(["[", ", ".join(arg_names), "]"])+";" |
412 print >>self.output, " var __r = "+"".join(["[", ", ".join(arg_names), "]"])+";" |
712 |
712 |
713 def _getattr2(self, v, current_klass, attr_name): |
713 def _getattr2(self, v, current_klass, attr_name): |
714 if isinstance(v.expr, ast.Getattr): |
714 if isinstance(v.expr, ast.Getattr): |
715 call_name = self._getattr2(v.expr, current_klass, v.attrname + "." + attr_name) |
715 call_name = self._getattr2(v.expr, current_klass, v.attrname + "." + attr_name) |
716 elif isinstance(v.expr, ast.Name) and v.expr.name in self.module_imports(): |
716 elif isinstance(v.expr, ast.Name) and v.expr.name in self.module_imports(): |
717 call_name = UU+v.expr.name + '.__' +v.attrname+".prototype.__class__."+attr_name |
717 call_name = UU+v.expr.name + '.__' + v.attrname+".prototype.__class__."+attr_name |
718 else: |
718 else: |
719 obj = self.expr(v.expr, current_klass) |
719 obj = self.expr(v.expr, current_klass) |
720 call_name = obj + "." + v.attrname + "." + attr_name |
720 call_name = obj + "." + v.attrname + "." + attr_name |
721 |
721 |
722 return call_name |
722 return call_name |
1745 """ |
1745 """ |
1746 |
1746 |
1747 |
1747 |
1748 def main(): |
1748 def main(): |
1749 import sys |
1749 import sys |
1750 if len(sys.argv)<2: |
1750 if len(sys.argv) < 2: |
1751 print >> sys.stderr, usage % sys.argv[0] |
1751 print >> sys.stderr, usage % sys.argv[0] |
1752 sys.exit(1) |
1752 sys.exit(1) |
1753 file_name = os.path.abspath(sys.argv[1]) |
1753 file_name = os.path.abspath(sys.argv[1]) |
1754 if not os.path.isfile(file_name): |
1754 if not os.path.isfile(file_name): |
1755 print >> sys.stderr, "File not found %s" % file_name |
1755 print >> sys.stderr, "File not found %s" % file_name |