11 # distributed under the License is distributed on an "AS IS" BASIS, |
11 # distributed under the License is distributed on an "AS IS" BASIS, |
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 # See the License for the specific language governing permissions and |
13 # See the License for the specific language governing permissions and |
14 # limitations under the License. |
14 # limitations under the License. |
15 # |
15 # |
16 # pylint: disable=no-absolute-import |
16 # pylint: disable=no-absolute-import,bad-python3-import |
17 |
17 |
18 from __future__ import print_function |
18 from __future__ import print_function |
19 import sys |
19 import sys |
20 from types import StringType |
20 from types import StringType |
21 import compiler |
21 import compiler |
22 from compiler import ast |
22 from compiler import ast |
23 import os |
23 import os |
24 import copy |
24 import copy |
25 import cStringIO |
25 from six.moves import cStringIO |
26 |
26 |
27 # the standard location for builtins (e.g. pyjslib) can be |
27 # the standard location for builtins (e.g. pyjslib) can be |
28 # over-ridden by changing this. it defaults to sys.prefix |
28 # over-ridden by changing this. it defaults to sys.prefix |
29 # so that on a system-wide install of pyjamas the builtins |
29 # so that on a system-wide install of pyjamas the builtins |
30 # can be found in e.g. {sys.prefix}/share/pyjamas |
30 # can be found in e.g. {sys.prefix}/share/pyjamas |
1441 def _lambda(self, node, current_klass): |
1441 def _lambda(self, node, current_klass): |
1442 if node.varargs: |
1442 if node.varargs: |
1443 raise TranslationError("varargs are not supported in Lambdas", node) |
1443 raise TranslationError("varargs are not supported in Lambdas", node) |
1444 if node.kwargs: |
1444 if node.kwargs: |
1445 raise TranslationError("kwargs are not supported in Lambdas", node) |
1445 raise TranslationError("kwargs are not supported in Lambdas", node) |
1446 res = cStringIO.StringIO() |
1446 res = cStringIO() |
1447 arg_names = list(node.argnames) |
1447 arg_names = list(node.argnames) |
1448 function_args = ", ".join(arg_names) |
1448 function_args = ", ".join(arg_names) |
1449 for child in node.getChildNodes(): |
1449 for child in node.getChildNodes(): |
1450 expr = self.expr(child, None) |
1450 expr = self.expr(child, None) |
1451 print("function (%s){" % function_args, file=res) |
1451 print("function (%s){" % function_args, file=res) |
1532 |
1532 |
1533 def translate(file_name, module_name, debug=False): |
1533 def translate(file_name, module_name, debug=False): |
1534 f = file(file_name, "r") |
1534 f = file(file_name, "r") |
1535 src = f.read() |
1535 src = f.read() |
1536 f.close() |
1536 f.close() |
1537 output = cStringIO.StringIO() |
1537 output = cStringIO() |
1538 mod = compiler.parseFile(file_name) |
1538 mod = compiler.parseFile(file_name) |
1539 Translator(module_name, module_name, module_name, src, debug, mod, output) |
1539 Translator(module_name, module_name, module_name, src, debug, mod, output) |
1540 return output.getvalue() |
1540 return output.getvalue() |
1541 |
1541 |
1542 |
1542 |
1681 if module_name not in self.library_modules: |
1681 if module_name not in self.library_modules: |
1682 self.library_modules.append(module_name) |
1682 self.library_modules.append(module_name) |
1683 |
1683 |
1684 file_name = self.findFile(module_name + self.extension) |
1684 file_name = self.findFile(module_name + self.extension) |
1685 |
1685 |
1686 output = cStringIO.StringIO() |
1686 output = cStringIO() |
1687 |
1687 |
1688 f = file(file_name, "r") |
1688 f = file(file_name, "r") |
1689 src = f.read() |
1689 src = f.read() |
1690 f.close() |
1690 f.close() |
1691 |
1691 |
1716 |
1716 |
1717 return imported_modules_str + module_str |
1717 return imported_modules_str + module_str |
1718 |
1718 |
1719 def translate(self, module_name, is_app=True, debug=False, |
1719 def translate(self, module_name, is_app=True, debug=False, |
1720 library_modules=None): |
1720 library_modules=None): |
1721 app_code = cStringIO.StringIO() |
1721 app_code = cStringIO() |
1722 lib_code = cStringIO.StringIO() |
1722 lib_code = cStringIO() |
1723 imported_js = set() |
1723 imported_js = set() |
1724 self.library_modules = [] |
1724 self.library_modules = [] |
1725 self.overrides = {} |
1725 self.overrides = {} |
1726 if library_modules is not None: |
1726 if library_modules is not None: |
1727 for library in library_modules: |
1727 for library in library_modules: |