--- a/Beremiz_service.py Fri Sep 22 10:52:44 2017 +0300
+++ b/Beremiz_service.py Fri Sep 22 10:54:42 2017 +0300
@@ -23,6 +23,8 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+from __future__ import print_function @@ -37,7 +39,7 @@
Usage of Beremiz PLC execution service :\n
%s {[-n servicename] [-i IP] [-p port] [-x enabletaskbar] [-a autostart]|-h|--help} working_dir
-n - zeroconf service name (default:disabled)
@@ -52,14 +54,14 @@
-e - python extension (absolute path .py)
working_dir - directory where are stored PLC files
opts, argv = getopt.getopt(sys.argv[1:], "i:p:n:x:t:a:w:c:e:h")
except getopt.GetoptError, err:
# print help information and exit:
- print str(err) # will print something like "option -a not recognized"
+ print(str(err)) # will print something like "option -a not recognized" @@ -172,7 +174,7 @@
- print "Wx unavailable !"
+ print("Wx unavailable !") @@ -302,14 +304,14 @@
if plcstatus is "Stopped":
self.pyroserver.plcobj.StartPLC()
- print _("PLC is empty or already started.")
+ print(_("PLC is empty or already started.")) def OnTaskBarStopPLC(self, evt):
if self.pyroserver.plcobj is not None:
if self.pyroserver.plcobj.GetPLCstatus()[0] == "Started":
Thread(target=self.pyroserver.plcobj.StopPLC).start()
- print _("PLC is not started.")
+ print(_("PLC is not started.")) def OnTaskBarChangeInterface(self, evt):
ip_addr = self.pyroserver.ip_addr
@@ -433,13 +435,13 @@
uri = self.daemon.connect(self.plcobj, "PLCObject")
- print _("Pyro port :"), self.port
- print _("Pyro object's uri :"), uri
+ print(_("Pyro port :"), self.port) + print(_("Pyro object's uri :"), uri) # Beremiz IDE detects daemon start by looking
# for self.workdir in the daemon's stdout.
# Therefore don't delete the following line
- print _("Current working directory :"), self.workdir
+ print(_("Current working directory :"), self.workdir) # Configure and publish service
# Not publish service if localhost in address params
@@ -447,7 +449,7 @@
self.ip_addr is not None and \
self.ip_addr != "localhost" and \
self.ip_addr != "127.0.0.1":
- print _("Publishing service on local network")
+ print(_("Publishing service on local network")) self.servicepublisher = ServicePublisher.ServicePublisher()
self.servicepublisher.RegisterService(self.servicename, self.ip_addr, self.port)
@@ -484,7 +486,7 @@
- print _("Twisted unavailable.")
+ print(_("Twisted unavailable.")) @@ -570,7 +572,7 @@
import runtime.NevowServer as NS
- print _("Nevow/Athena import failed :"), e
+ print(_("Nevow/Athena import failed :"), e) NS.WorkingDir = WorkingDir
@@ -578,7 +580,7 @@
import runtime.WampClient as WC
- print _("WAMP import failed :"), e
+ print(_("WAMP import failed :"), e) @@ -594,7 +596,7 @@
pyruntimevars["website"] = website
statuschange.append(NS.website_statuslistener_factory(website))
- print _("Nevow Web service failed. "), e
+ print(_("Nevow Web service failed. "), e) @@ -602,7 +604,7 @@
pyruntimevars["wampsession"] = WC.GetSession
- print _("WAMP client startup failed. "), e
+ print(_("WAMP client startup failed. "), e) if havetwisted or havewx:
--- a/svgui/pyjs/build.py Fri Sep 22 10:52:44 2017 +0300
+++ b/svgui/pyjs/build.py Fri Sep 22 10:54:42 2017 +0300
@@ -1,5 +1,6 @@
+from __future__ import print_function @@ -103,7 +104,7 @@
except (IOError, os.error), why:
errors.append((srcname, dstname, why))
def check_html_file(source_file, dest_path):
@@ -175,24 +176,24 @@
msg = "Building '%(app_name)s' to output directory '%(output)s'" % locals()
msg += " with debugging statements"
# check the output directory
if os.path.exists(output) and not os.path.isdir(output):
- print >>sys.stderr, "Output destination %s exists and is not a directory" % output
+ print("Output destination %s exists and is not a directory" % output, file=sys.stderr) if not os.path.isdir(output):
- print "Creating output directory"
+ print("Creating output directory") - print >>sys.stderr, "Exception creating output directory %s: %s" % (output, e)
+ print("Exception creating output directory %s: %s" % (output, e), file=sys.stderr) pub_dir = join(p, 'public')
- print "Copying: public directory of library %r" % p
+ print("Copying: public directory of library %r" % p) copytree_exists(pub_dir, output)
# AppName.html - can be in current or public directory
@@ -205,27 +206,27 @@
shutil.copy(html_input_filename, html_output_filename)
- print >>sys.stderr, "Warning: Missing module HTML file %s" % html_input_filename
+ print("Warning: Missing module HTML file %s" % html_input_filename, file=sys.stderr) - print "Copying: %(html_input_filename)s" % locals()
+ print("Copying: %(html_input_filename)s" % locals()) if check_html_file(html_input_filename, output):
- print >>sys.stderr, "Warning: Module HTML file %s has been auto-generated" % html_input_filename
+ print("Warning: Module HTML file %s has been auto-generated" % html_input_filename, file=sys.stderr) - print "Copying: pygwt.js"
+ print("Copying: pygwt.js") pygwt_js_template = read_boilerplate(data_dir, "pygwt.js")
pygwt_js_output = open(join(output, "pygwt.js"), "w")
- print >>pygwt_js_output, pygwt_js_template
+ print(pygwt_js_template, file=pygwt_js_output) - print "Copying: Images and History"
+ print("Copying: Images and History") copy_boilerplate(data_dir, "corner_dialog_topleft_black.png", output)
copy_boilerplate(data_dir, "corner_dialog_topright_black.png", output)
copy_boilerplate(data_dir, "corner_dialog_bottomright_black.png", output)
@@ -247,7 +248,7 @@
- print "Creating: %(app_name)s.nocache.html" % locals()
+ print("Creating: %(app_name)s.nocache.html" % locals()) home_nocache_html_template = read_boilerplate(data_dir, "home.nocache.html")
home_nocache_html_output = open(join(output, app_name + ".nocache.html"),
@@ -258,16 +259,17 @@
script_selectors = StringIO()
for platform, file_prefix in app_files:
- print >> script_selectors, select_tmpl % (platform, file_prefix)
+ print(select_tmpl % (platform, file_prefix), file=script_selectors) - print >>home_nocache_html_output, home_nocache_html_template % dict(
- script_selectors=script_selectors.getvalue(),
+ home_nocache_html_template % dict( + script_selectors=script_selectors.getvalue(), + ), file=home_nocache_html_output) home_nocache_html_output.close()
- print "Done. You can run your app by opening '%(html_output_filename)s' in a browser" % locals()
+ print("Done. You can run your app by opening '%(html_output_filename)s' in a browser" % locals()) def generateAppFiles(data_dir, js_includes, app_name, debug, output, dynamic,
@@ -280,7 +282,7 @@
for name in os.listdir(output):
if CACHE_HTML_PAT.match(name):
- print "Deleting existing app file %s" % p
+ print("Deleting existing app file %s" % p) @@ -334,7 +336,7 @@
pd = overrides.setdefault(mname, {})
# mod_code[platform][app_name] = appcode
# platform.Module.cache.js
@@ -432,7 +434,7 @@
mod_cache_name = "%s.cache.js" % (mod_name)
- print "Creating: " + mod_cache_name
+ print("Creating: " + mod_cache_name) modlevels = make_deps(None, dependencies, dependencies[mod_name])
@@ -456,7 +458,7 @@
mod_cache_html_output = StringIO()
- print >>mod_cache_html_output, mod_cache_html_template % dict(
+ print(mod_cache_html_template % dict( @@ -464,7 +466,7 @@
mod_libs=mod_libs[platform][mod_name],
+ ), file=mod_cache_html_output) mod_cache_html_output.close()
@@ -518,8 +520,8 @@
out_file.write(file_contents)
app_files.append((platform.lower(), file_name))
- print "Created app file %s:%s: %s" % (
- app_name, platform, out_path)
+ print("Created app file %s:%s: %s" % ( + app_name, platform, out_path)) @@ -619,7 +621,7 @@
def make_deps(app_name, deps, mod_list):
- print "Calculating Dependencies ..."
+ print("Calculating Dependencies ...") mod_list = filter_mods(app_name, mod_list)
deps = filter_deps(app_name, deps)
--- a/svgui/pyjs/pyjs.py Fri Sep 22 10:52:44 2017 +0300
+++ b/svgui/pyjs/pyjs.py Fri Sep 22 10:54:42 2017 +0300
@@ -14,6 +14,7 @@
# limitations under the License.
+from __future__ import print_function from types import StringType
@@ -226,36 +227,36 @@
- print >>self.output, UU+"%s%s = function (__mod_name__) {" % (vdec, module_name)
+ self.printo(UU+"%s%s = function (__mod_name__) {" % (vdec, module_name)) - print >>self.output, " if("+module_name+".__was_initialized__) return;"
- print >>self.output, " "+UU+module_name+".__was_initialized__ = true;"
- print >>self.output, UU+"if (__mod_name__ == null) __mod_name__ = '%s';" % (mn)
- print >>self.output, UU+"%s.__name__ = __mod_name__;" % (raw_module_name)
+ self.printo(" if("+module_name+".__was_initialized__) return;") + self.printo(" "+UU+module_name+".__was_initialized__ = true;") + self.printo(UU+"if (__mod_name__ == null) __mod_name__ = '%s';" % (mn)) + self.printo(UU+"%s.__name__ = __mod_name__;" % (raw_module_name)) decl = mod_var_name_decl(raw_module_name)
- print >>self.output, decl
haltException = self.module_prefix + "HaltException"
- print >>self.output, haltException + ' = function () {'
- print >>self.output, ' this.message = "Program Halted";'
- print >>self.output, ' this.name = "' + haltException + '";'
- print >>self.output, '}'
- print >>self.output, ''
- print >>self.output, haltException + ".prototype.__str__ = function()"
- print >>self.output, '{'
- print >>self.output, 'return this.message ;'
- print >>self.output, '}'
+ self.printo(haltException + ' = function () {') + self.printo(' this.message = "Program Halted";') + self.printo(' this.name = "' + haltException + '";') + self.printo(haltException + ".prototype.__str__ = function()") + self.printo('return this.message ;') - print >>self.output, haltException + ".prototype.toString = function()"
- print >>self.output, '{'
- print >>self.output, 'return this.name + ": \\"" + this.message + "\\"";'
- print >>self.output, '}'
+ self.printo(haltException + ".prototype.toString = function()") + self.printo('return this.name + ": \\"" + this.message + "\\"";') isHaltFunction = self.module_prefix + "IsHaltException"
- print >>self.output, """
var suffix="HaltException";
if (s.length < suffix.length) {
@@ -267,7 +268,7 @@
if isinstance(child, ast.Function):
self.top_level_functions.add(child.name)
@@ -323,14 +324,17 @@
raise TranslationError("unsupported type (in __init__)", child)
# Initialize all classes for this module
- # print >> self.output, "__"+self.modpfx()+\
- # "classes_initialize = function() {\n"
+ # self.printo("__"+self.modpfx()+\ + # "classes_initialize = function() {\n") # for className in self.top_level_classes:
- # print >> self.output, "\t"+UU+self.modpfx()+"__"+className+"_initialize();"
- # print >> self.output, "};\n"
+ # self.printo("\t"+UU+self.modpfx()+"__"+className+"_initialize();") - print >> self.output, "return this;\n"
- print >> self.output, "}; /* end %s */ \n" % module_name
+ self.printo("return this;\n") + self.printo("}; /* end %s */ \n" % module_name) + def printo(self, *args): + print(*args, file=self.output) def module_imports(self):
return self.imported_modules + self.imported_modules_as
@@ -354,9 +358,9 @@
# module import directory structure!
self.imported_modules_as.append(child_name)
- print >> self.output, gen_mod_import(self.raw_module_name,
+ self.printo(gen_mod_import(self.raw_module_name, def _default_args_handler(self, node, arg_names, current_klass,
@@ -377,21 +381,21 @@
default_name = arg_names[default_pos]
- print >> output, " if (typeof %s == 'undefined') %s=%s;" % (default_name, default_name, default_value)
+ self.printo(" if (typeof %s == 'undefined') %s=%s;" % (default_name, default_name, default_value)) def _varargs_handler(self, node, varargname, arg_names, current_klass):
- print >>self.output, " var", varargname, '= new pyjslib.Tuple();'
- print >>self.output, " for(var __va_arg="+str(len(arg_names))+"; __va_arg < arguments.length; __va_arg++) {"
- print >>self.output, " var __arg = arguments[__va_arg];"
- print >>self.output, " "+varargname+".append(__arg);"
- print >>self.output, " }"
+ self.printo(" var", varargname, '= new pyjslib.Tuple();') + self.printo(" for(var __va_arg="+str(len(arg_names))+"; __va_arg < arguments.length; __va_arg++) {") + self.printo(" var __arg = arguments[__va_arg];") + self.printo(" "+varargname+".append(__arg);") def _kwargs_parser(self, node, function_name, arg_names, current_klass):
if len(node.defaults) or node.kwargs:
default_pos = len(arg_names) - len(node.defaults)
if arg_names and arg_names[0] == self.method_self:
- print >>self.output, function_name+'.parse_kwargs = function (', ", ".join(["__kwargs"]+arg_names), ") {"
+ self.printo(function_name+'.parse_kwargs = function (', ", ".join(["__kwargs"]+arg_names), ") {") for default_node in node.defaults:
default_value = self.expr(default_node, current_klass)
# if isinstance(default_node, ast.Const):
@@ -404,19 +408,19 @@
# raise TranslationError("unsupported type (in _method)", default_node)
default_name = arg_names[default_pos]
- print >>self.output, " if (typeof %s == 'undefined')" % (default_name)
- print >>self.output, " %s=__kwargs.%s;" % (default_name, default_name)
+ self.printo(" if (typeof %s == 'undefined')" % (default_name)) + self.printo(" %s=__kwargs.%s;" % (default_name, default_name)) # self._default_args_handler(node, arg_names, current_klass)
arg_names += ["pyjslib.Dict(__kwargs)"]
- print >>self.output, " var __r = "+"".join(["[", ", ".join(arg_names), "]"])+";"
+ self.printo(" var __r = "+"".join(["[", ", ".join(arg_names), "]"])+";") self._varargs_handler(node, "__args", arg_names, current_klass)
- print >>self.output, " __r.push.apply(__r, __args.getArray())"
- print >>self.output, " return __r;"
- print >>self.output, "};"
+ self.printo(" __r.push.apply(__r, __args.getArray())") + self.printo(" return __r;") def _function(self, node, local=False):
@@ -436,7 +440,7 @@
declared_arg_names.append(kwargname)
function_args = "(" + ", ".join(declared_arg_names) + ")"
- print >>self.output, "%s = function%s {" % (function_name, function_args)
+ self.printo("%s = function%s {" % (function_name, function_args)) self._default_args_handler(node, normal_arg_names, None)
local_arg_names = normal_arg_names + declared_arg_names
@@ -458,10 +462,10 @@
lastStmt = [p for p in node.code][-1]
if not isinstance(lastStmt, ast.Return):
if not self._isNativeFunc(lastStmt):
- print >>self.output, " return null;"
+ self.printo(" return null;") - print >>self.output, "};"
- print >>self.output, "%s.__name__ = '%s';\n" % (function_name, node.name)
+ self.printo("%s.__name__ = '%s';\n" % (function_name, node.name)) self._kwargs_parser(node, function_name, normal_arg_names, None)
@@ -469,13 +473,13 @@
expr = self.expr(node.value, current_klass)
# in python a function call always returns None, so we do it
- print >>self.output, " return " + expr + ";"
+ self.printo(" return " + expr + ";") def _break(self, node, current_klass):
- print >>self.output, " break;"
def _continue(self, node, current_klass):
- print >>self.output, " continue;"
+ self.printo(" continue;") def _callfunc(self, v, current_klass):
@@ -562,7 +566,7 @@
arg = self.expr(ch4, current_klass)
- print >>self.output, "pyjslib.printFunc([", ', '.join(call_args), "],", int(isinstance(node, ast.Printnl)), ");"
+ self.printo("pyjslib.printFunc([", ', '.join(call_args), "],", int(isinstance(node, ast.Printnl)), ");") def _tryExcept(self, node, current_klass):
if len(node.handlers) != 1:
@@ -580,10 +584,10 @@
# local scope, temporary to the function. oh dearie me.
self.add_local_arg(errName)
- print >>self.output, " try {"
for stmt in node.body.nodes:
self._stmt(stmt, current_klass)
- print >> self.output, " } catch(%s) {" % errName
+ self.printo(" } catch(%s) {" % errName) if isinstance(expr, ast.Tuple):
@@ -591,17 +595,17 @@
k.append("(%(err)s.__name__ == %(expr)s.__name__)" % dict(err=errName, expr=self.expr(x, current_klass)))
k = [" (%(err)s.__name__ == %(expr)s.__name__) " % dict(err=errName, expr=self.expr(expr, current_klass))]
- print >> self.output, " if(%s) {" % '||\n\t\t'.join(k)
+ self.printo(" if(%s) {" % '||\n\t\t'.join(k)) for stmt in node.handlers[0][2]:
self._stmt(stmt, current_klass)
- # print >> self.output, "} else { throw(%s); } " % errName
- print >> self.output, "}"
+ # self.printo("} else { throw(%s); } " % errName) if node.else_ is not None:
- print >>self.output, " } finally {"
+ self.printo(" } finally {") self._stmt(stmt, current_klass)
- print >>self.output, " }"
# XXX: change use_getattr to True to enable "strict" compilation
# but incurring a 100% performance penalty. oops.
@@ -636,11 +640,11 @@
return_none_for_module=False):
if v.name == 'ilikesillynamesfornicedebugcode':
- print top_level, current_klass, repr(v)
- print self.top_level_vars
- print self.top_level_functions
- print self.local_arg_stack
+ print(top_level, current_klass, repr(v)) + print(self.top_level_vars) + print(self.top_level_functions) + print(self.local_arg_stack) las = len(self.local_arg_stack)
@@ -786,11 +790,11 @@
raise TranslationError("more than one base (in _class)", node)
- print >>self.output, UU+class_name_ + " = function () {"
+ self.printo(UU+class_name_ + " = function () {") - # print >>self.output, " __" + base_class + ".call(this);"
- print >>self.output, "}"
+ # self.printo(" __" + base_class + ".call(this);") init_method = ast.Function([], "__init__", ["self"], [], 0, None, [])
@@ -813,23 +817,23 @@
self._function(clsfunc, False)
- print >>self.output, UU+class_name_ + ".__initialize__ = function () {"
- print >>self.output, " if("+UU+class_name_+".__was_initialized__) return;"
- print >>self.output, " "+UU+class_name_+".__was_initialized__ = true;"
+ self.printo(UU+class_name_ + ".__initialize__ = function () {") + self.printo(" if("+UU+class_name_+".__was_initialized__) return;") + self.printo(" "+UU+class_name_+".__was_initialized__ = true;") cls_obj = UU+class_name_ + '.prototype.__class__'
if class_name == "pyjslib.__Object":
- print >>self.output, " "+cls_obj+" = {};"
+ self.printo(" "+cls_obj+" = {};") if base_class and base_class not in ("object", "pyjslib.__Object"):
- print >>self.output, " if(!"+UU+base_class_+".__was_initialized__)"
- print >>self.output, " "+UU+base_class_+".__initialize__();"
- print >>self.output, " pyjs_extend(" + UU+class_name_ + ", "+UU+base_class_+");"
+ self.printo(" if(!"+UU+base_class_+".__was_initialized__)") + self.printo(" "+UU+base_class_+".__initialize__();") + self.printo(" pyjs_extend(" + UU+class_name_ + ", "+UU+base_class_+");") - print >>self.output, " pyjs_extend(" + UU+class_name_ + ", "+UU+"pyjslib.__Object);"
+ self.printo(" pyjs_extend(" + UU+class_name_ + ", "+UU+"pyjslib.__Object);") - print >>self.output, " "+cls_obj+".__new__ = "+UU+class_name+";"
- print >>self.output, " "+cls_obj+".__name__ = '"+UU+node.name+"';"
+ self.printo(" "+cls_obj+".__new__ = "+UU+class_name+";") + self.printo(" "+cls_obj+".__name__ = '"+UU+node.name+"';") if isinstance(child, ast.Pass):
@@ -843,9 +847,9 @@
raise TranslationError("unsupported type (in _class)", child)
- print >>self.output, "}"
- print >> self.output, class_name_+".__initialize__();"
+ self.printo(class_name_+".__initialize__();") def classattr(self, node, current_klass):
self._assign(node, current_klass, True)
@@ -854,8 +858,8 @@
raise TranslationError("More than one expression unsupported",
- print >> self.output, "throw (%s);" % self.expr(
- node.expr1, current_klass)
+ self.printo("throw (%s);" % self.expr( + node.expr1, current_klass)) def _method(self, node, current_klass, class_name, class_name_):
@@ -875,8 +879,8 @@
staticfunc = ast.Function([], class_name_+"."+node.name, node.argnames, node.defaults, node.flags, node.doc, node.code, node.lineno)
self._function(staticfunc, True)
- print >>self.output, " " + UU+class_name_ + ".prototype.__class__." + node.name + " = " + class_name_+"."+node.name+";"
- print >>self.output, " " + UU+class_name_ + ".prototype.__class__." + node.name + ".static_method = true;"
+ self.printo(" " + UU+class_name_ + ".prototype.__class__." + node.name + " = " + class_name_+"."+node.name+";") + self.printo(" " + UU+class_name_ + ".prototype.__class__." + node.name + ".static_method = true;") @@ -901,7 +905,7 @@
fexpr = UU + class_name_ + ".prototype.__class__." + node.name
fexpr = UU + class_name_ + ".prototype." + node.name
- print >>self.output, " "+fexpr + " = function" + function_args + " {"
+ self.printo(" "+fexpr + " = function" + function_args + " {") self._default_args_handler(node, normal_arg_names, current_klass)
@@ -921,7 +925,7 @@
# remove the top local arg names
self.local_arg_stack.pop()
- print >>self.output, " };"
self._kwargs_parser(node, fexpr, normal_arg_names, current_klass)
@@ -929,26 +933,26 @@
# Have to create a version on the instances which automatically passes the
altexpr = UU + class_name_ + ".prototype." + node.name
- print >>self.output, " "+altexpr + " = function() {"
- print >>self.output, " return " + fexpr + ".apply(this.__class__, arguments);"
- print >>self.output, " };"
- print >>self.output, " "+fexpr+".class_method = true;"
- print >>self.output, " "+altexpr+".instance_method = true;"
+ self.printo(" "+altexpr + " = function() {") + self.printo(" return " + fexpr + ".apply(this.__class__, arguments);") + self.printo(" "+fexpr+".class_method = true;") + self.printo(" "+altexpr+".instance_method = true;") # For instance methods, we need an unbound version in the class object
altexpr = UU + class_name_ + ".prototype.__class__." + node.name
- print >>self.output, " "+altexpr + " = function() {"
- print >>self.output, " return " + fexpr + ".call.apply("+fexpr+", arguments);"
- print >>self.output, " };"
- print >>self.output, " "+altexpr+".unbound_method = true;"
- print >>self.output, " "+fexpr+".instance_method = true;"
- print >>self.output, " "+altexpr+".__name__ = '%s';" % node.name
+ self.printo(" "+altexpr + " = function() {") + self.printo(" return " + fexpr + ".call.apply("+fexpr+", arguments);") + self.printo(" "+altexpr+".unbound_method = true;") + self.printo(" "+fexpr+".instance_method = true;") + self.printo(" "+altexpr+".__name__ = '%s';" % node.name) - print >>self.output, UU + class_name_ + ".prototype.%s.__name__ = '%s';" % \
+ self.printo(UU + class_name_ + ".prototype.%s.__name__ = '%s';" % + (node.name, node.name)) if node.kwargs or len(node.defaults):
- print >>self.output, " "+altexpr + ".parse_kwargs = " + fexpr + ".parse_kwargs;"
+ self.printo(" "+altexpr + ".parse_kwargs = " + fexpr + ".parse_kwargs;") self.method_imported_globals = set()
@@ -964,7 +968,7 @@
def _stmt(self, node, current_klass):
debugStmt = self.debug and not self._isNativeFunc(node)
- print >>self.output, ' try {'
if isinstance(node, ast.Return):
self._return(node, current_klass)
@@ -1025,7 +1029,7 @@
def get_line_trace(self, node):
@@ -1053,7 +1057,7 @@
lhs = self._name(node.node, current_klass)
rhs = self.expr(node.expr, current_klass)
- print >>self.output, " " + lhs + " " + op + " " + rhs + ";"
+ self.printo(" " + lhs + " " + op + " " + rhs + ";") def _assign(self, node, current_klass, top_level=False):
@@ -1128,7 +1132,7 @@
raise TranslationError("must have one sub (in _assign)", v)
idx = self.expr(v.subs[0], current_klass)
value = self.expr(node.expr, current_klass)
- print >>self.output, " " + obj + ".__setitem__(" + idx + ", " + value + ");"
+ self.printo(" " + obj + ".__setitem__(" + idx + ", " + value + ");") raise TranslationError("unsupported flag (in _assign)", v)
@@ -1136,8 +1140,7 @@
uniqueID = self.nextTupleAssignID
self.nextTupleAssignID += 1
tempName = "__tupleassign" + str(uniqueID) + "__"
- print >>self.output, " var " + tempName + " = " + \
- self.expr(node.expr, current_klass) + ";"
+ self.printo(" var " + tempName + " = " + self.expr(node.expr, current_klass) + ";") for index, child in enumerate(v.getChildNodes()):
rhs = tempName + ".__getitem__(" + str(index) + ")"
@@ -1153,18 +1156,17 @@
idx = self.expr(child.subs[0], current_klass)
value = self.expr(node.expr, current_klass)
- print >>self.output, " " + obj + ".__setitem__(" \
- + idx + ", " + rhs + ");"
+ self.printo(" " + obj + ".__setitem__(" + idx + ", " + rhs + ");") - print >>self.output, " " + lhs + " = " + rhs + ";"
+ self.printo(" " + lhs + " = " + rhs + ";") raise TranslationError("unsupported type (in _assign)", v)
rhs = self.expr(node.expr, current_klass)
- print "b", repr(node.expr), rhs
- print >>self.output, " " + lhs + " " + op + " " + rhs + ";"
+ print("b", repr(node.expr), rhs) + self.printo(" " + lhs + " " + op + " " + rhs + ";") def _discard(self, node, current_klass):
@@ -1175,24 +1177,24 @@
st = self.get_line_trace(node)
- print >>self.output, "sys.addstack('%s');\n" % st
+ self.printo("sys.addstack('%s');\n" % st) if isinstance(node.expr.node, ast.Name) and node.expr.node.name == NATIVE_JS_FUNC_NAME:
if len(node.expr.args) != 1:
raise TranslationError("native javascript function %s must have one arg" % NATIVE_JS_FUNC_NAME, node.expr)
if not isinstance(node.expr.args[0], ast.Const):
raise TranslationError("native javascript function %s must have constant arg" % NATIVE_JS_FUNC_NAME, node.expr)
raw_js = node.expr.args[0].value
- print >>self.output, raw_js
expr = self._callfunc(node.expr, current_klass)
- print >>self.output, " " + expr + ";"
+ self.printo(" " + expr + ";") - print >>self.output, "sys.popstack();\n"
+ self.printo("sys.popstack();\n") elif isinstance(node.expr, ast.Const):
if node.expr.value is not None: # Empty statements generate ignore None
- print >>self.output, self._const(node.expr)
+ self.printo(self._const(node.expr)) raise TranslationError("unsupported type (in _discard)", node.expr)
@@ -1217,9 +1219,9 @@
expr = self.expr(test, current_klass)
- print >>self.output, " " + keyword + " (pyjslib.bool(" + expr + ")) {"
+ self.printo(" " + keyword + " (pyjslib.bool(" + expr + ")) {") - print >>self.output, " " + keyword + " {"
+ self.printo(" " + keyword + " {") if isinstance(consequence, ast.Stmt):
for child in consequence.nodes:
@@ -1227,7 +1229,7 @@
raise TranslationError("unsupported type (in _if_test)", consequence)
- print >>self.output, " }"
@@ -1315,33 +1317,33 @@
lhs = "var " + assign_name
iterator_name = "__" + assign_name
- print >>self.output, """
var %(iterator_name)s = %(list_expr)s.__iter__();
%(lhs)s %(op)s %(iterator_name)s.next();
for node in node.body.nodes:
self._stmt(node, current_klass)
- print >>self.output, """
if (e.__name__ != pyjslib.StopIteration.__name__) {
def _while(self, node, current_klass):
test = self.expr(node.test, current_klass)
- print >>self.output, " while (pyjslib.bool(" + test + ")) {"
+ self.printo(" while (pyjslib.bool(" + test + ")) {") if isinstance(node.body, ast.Stmt):
for child in node.body.nodes:
self._stmt(child, current_klass)
raise TranslationError("unsupported type (in _while)", node.body)
- print >>self.output, " }"
if isinstance(node.value, int):
@@ -1411,7 +1413,7 @@
def _subscript_stmt(self, node, current_klass):
if node.flags == "OP_DELETE":
- print >>self.output, " " + self.expr(node.expr, current_klass) + ".__delitem__(" + self.expr(node.subs[0], current_klass) + ");"
+ self.printo(" " + self.expr(node.expr, current_klass) + ".__delitem__(" + self.expr(node.subs[0], current_klass) + ");") raise TranslationError("unsupported flag (in _subscript)", node)
@@ -1439,10 +1441,10 @@
function_args = ", ".join(arg_names)
for child in node.getChildNodes():
expr = self.expr(child, None)
- print >> res, "function (%s){" % function_args
+ print("function (%s){" % function_args, file=res) self._default_args_handler(node, arg_names, None,
- print >> res, 'return %s;}' % expr
+ print('return %s;}' % expr, file=res) def _slice(self, node, current_klass):
@@ -1561,9 +1563,9 @@
- print "Importing %s (Platform %s)" % (module_name, self.platform)
+ print("Importing %s (Platform %s)" % (module_name, self.platform)) - print "Importing %s" % (module_name)
+ print("Importing %s" % (module_name)) @@ -1717,28 +1719,28 @@
self.library_modules.append(library)
- print 'Including LIB', library
- print >> lib_code, '\n//\n// BEGIN LIB '+library+'\n//\n'
- print >> lib_code, self._translate(
- library, False, debug=debug, imported_js=imported_js)
+ print('Including LIB', library) + print('\n//\n// BEGIN LIB '+library+'\n//\n', file=lib_code) + print(self._translate(library, False, debug=debug, imported_js=imported_js), - print >> lib_code, "/* initialize static library */"
- print >> lib_code, "%s%s();\n" % (UU, library)
+ print("/* initialize static library */", file=lib_code) + print("%s%s();\n" % (UU, library), file=lib_code) - print >> lib_code, '\n//\n// END LIB '+library+'\n//\n'
+ print('\n//\n// END LIB '+library+'\n//\n', file=lib_code) - print >> app_code, self._translate(
- module_name, is_app, debug=debug, imported_js=imported_js)
+ print(self._translate(module_name, is_app, debug=debug, imported_js=imported_js), - print 'Including JS', js
- print >> lib_code, '\n//\n// BEGIN JS '+js+'\n//\n'
- print >> lib_code, file(path).read()
- print >> lib_code, '\n//\n// END JS '+js+'\n//\n'
+ print('Including JS', js) + print('\n//\n// BEGIN JS '+js+'\n//\n', file=lib_code) + print(file(path).read(), file=lib_code) + print('\n//\n// END JS '+js+'\n//\n', file=lib_code) - print >>sys.stderr, 'Warning: Unable to find imported javascript:', js
+ print('Warning: Unable to find imported javascript:', js, file=sys.stderr) return lib_code.getvalue(), app_code.getvalue()
@@ -1750,17 +1752,17 @@
- print >> sys.stderr, usage % sys.argv[0]
+ print(usage % sys.argv[0], file=sys.stderr) file_name = os.path.abspath(sys.argv[1])
if not os.path.isfile(file_name):
- print >> sys.stderr, "File not found %s" % file_name
+ print("File not found %s" % file_name, file=sys.stderr) module_name = sys.argv[2]
- print translate(file_name, module_name),
+ print(translate(file_name, module_name), end="") if __name__ == "__main__":