117 ('<', r'\x3C'), |
118 ('<', r'\x3C'), |
118 ('&', r'\x26'), |
119 ('&', r'\x26'), |
119 (';', r'\x3B') |
120 (';', r'\x3B') |
120 ) + tuple([('%c' % z, '\\x%02X' % z) for z in range(32)]) |
121 ) + tuple([('%c' % z, '\\x%02X' % z) for z in range(32)]) |
121 |
122 |
|
123 |
122 def escapejs(value): |
124 def escapejs(value): |
123 """Hex encodes characters for use in JavaScript strings.""" |
125 """Hex encodes characters for use in JavaScript strings.""" |
124 for bad, good in JS_ESCAPES: |
126 for bad, good in JS_ESCAPES: |
125 value = value.replace(bad, good) |
127 value = value.replace(bad, good) |
126 return value |
128 return value |
127 |
129 |
|
130 |
128 def uuprefix(name, leave_alone=0): |
131 def uuprefix(name, leave_alone=0): |
129 name = name.split(".") |
132 name = name.split(".") |
130 name = name[:leave_alone] + map(lambda x: "__%s" % x, name[leave_alone:]) |
133 name = name[:leave_alone] + map(lambda x: "__%s" % x, name[leave_alone:]) |
131 return '.'.join(name) |
134 return '.'.join(name) |
|
135 |
132 |
136 |
133 class Klass: |
137 class Klass: |
134 |
138 |
135 klasses = {} |
139 klasses = {} |
136 |
140 |
152 self.message = "line %s:\n%s\n%s" % (node.lineno, message, node) |
156 self.message = "line %s:\n%s\n%s" % (node.lineno, message, node) |
153 |
157 |
154 def __str__(self): |
158 def __str__(self): |
155 return self.message |
159 return self.message |
156 |
160 |
|
161 |
157 def strip_py(name): |
162 def strip_py(name): |
158 return name |
163 return name |
|
164 |
159 |
165 |
160 def mod_var_name_decl(raw_module_name): |
166 def mod_var_name_decl(raw_module_name): |
161 """ function to get the last component of the module e.g. |
167 """ function to get the last component of the module e.g. |
162 pyjamas.ui.DOM into the "namespace". i.e. doing |
168 pyjamas.ui.DOM into the "namespace". i.e. doing |
163 "import pyjamas.ui.DOM" actually ends up with _two_ |
169 "import pyjamas.ui.DOM" actually ends up with _two_ |
172 if len(name) == 1: |
178 if len(name) == 1: |
173 return '' |
179 return '' |
174 child_name = name[-1] |
180 child_name = name[-1] |
175 return "var %s = %s;\n" % (child_name, raw_module_name) |
181 return "var %s = %s;\n" % (child_name, raw_module_name) |
176 |
182 |
|
183 |
177 def gen_mod_import(parentName, importName, dynamic=1): |
184 def gen_mod_import(parentName, importName, dynamic=1): |
178 #pyjs_ajax_eval("%(n)s.cache.js", null, true); |
185 #pyjs_ajax_eval("%(n)s.cache.js", null, true); |
179 return """ |
186 return """ |
180 pyjslib.import_module(sys.loadpath, '%(p)s', '%(n)s', %(d)d, false); |
187 pyjslib.import_module(sys.loadpath, '%(p)s', '%(n)s', %(d)d, false); |
181 """ % ({'p': parentName, 'd': dynamic, 'n': importName}) + \ |
188 """ % ({'p': parentName, 'd': dynamic, 'n': importName}) + \ |
182 mod_var_name_decl(importName) |
189 mod_var_name_decl(importName) |
|
190 |
183 |
191 |
184 class Translator: |
192 class Translator: |
185 |
193 |
186 def __init__(self, mn, module_name, raw_module_name, src, debug, mod, output, |
194 def __init__(self, mn, module_name, raw_module_name, src, debug, mod, output, |
187 dynamic=0, optimize=False, |
195 dynamic=0, optimize=False, |
1631 target.code = source.code |
1640 target.code = source.code |
1632 target.argnames = source.argnames |
1641 target.argnames = source.argnames |
1633 target.defaults = source.defaults |
1642 target.defaults = source.defaults |
1634 target.doc = source.doc # @@@ not sure we need to do this any more |
1643 target.doc = source.doc # @@@ not sure we need to do this any more |
1635 |
1644 |
|
1645 |
1636 def dotreplace(fname): |
1646 def dotreplace(fname): |
1637 path, ext = os.path.splitext(fname) |
1647 path, ext = os.path.splitext(fname) |
1638 return path.replace(".", "/") + ext |
1648 return path.replace(".", "/") + ext |
|
1649 |
1639 |
1650 |
1640 class AppTranslator: |
1651 class AppTranslator: |
1641 |
1652 |
1642 def __init__(self, library_dirs=[], parser=None, dynamic=False, |
1653 def __init__(self, library_dirs=[], parser=None, dynamic=False, |
1643 optimize=False, verbose=True): |
1654 optimize=False, verbose=True): |