# HG changeset patch # User Andrey Skvortsov # Date 1506066882 -10800 # Node ID 91796f408540d648b97d361f387e5aa9cfc8a4c8 # Parent bcb50e736a46d9c1d649c8fe43b1cc23b6956ec6 fix usage of python2-only print statement diff -r bcb50e736a46 -r 91796f408540 Beremiz.py --- a/Beremiz.py Fri Sep 22 10:52:44 2017 +0300 +++ b/Beremiz.py Fri Sep 22 10:54:42 2017 +0300 @@ -23,6 +23,7 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +from __future__ import print_function import os import sys import getopt @@ -61,15 +62,15 @@ time.sleep(0.01) def Usage(self): - print "Usage:" - print "%s [Options] [Projectpath] [Buildpath]" % sys.argv[0] - print "" - print "Supported options:" - print "-h --help Print this help" - print "-u --updatecheck URL Retrieve update information by checking URL" - print "-e --extend PathToExtension Extend IDE functionality by loading at start additional extensions" - print "" - print "" + print("Usage:") + print("%s [Options] [Projectpath] [Buildpath]" % sys.argv[0]) + print("") + print("Supported options:") + print("-h --help Print this help") + print("-u --updatecheck URL Retrieve update information by checking URL") + print("-e --extend PathToExtension Extend IDE functionality by loading at start additional extensions") + print("") + print("") def SetCmdOptions(self): self.shortCmdOpts = "hu:e:" diff -r bcb50e736a46 -r 91796f408540 Beremiz_service.py --- 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 import os import sys import getopt @@ -37,7 +39,7 @@ def usage(): - print """ + print(""" 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 -""" % sys.argv[0] +""" % sys.argv[0]) try: 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" usage() sys.exit(2) @@ -172,7 +174,7 @@ import wx havewx = True except ImportError: - print "Wx unavailable !" + print("Wx unavailable !") havewx = False if havewx: @@ -302,14 +304,14 @@ if plcstatus is "Stopped": self.pyroserver.plcobj.StartPLC() else: - 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() else: - print _("PLC is not started.") + print(_("PLC is not started.")) def OnTaskBarChangeInterface(self, evt): ip_addr = self.pyroserver.ip_addr @@ -433,13 +435,13 @@ self.pyruntimevars) 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 @@ havetwisted = True except ImportError: - print _("Twisted unavailable.") + print(_("Twisted unavailable.")) havetwisted = False pyruntimevars = {} @@ -570,7 +572,7 @@ try: import runtime.NevowServer as NS except Exception, e: - print _("Nevow/Athena import failed :"), e + print(_("Nevow/Athena import failed :"), e) webport = None NS.WorkingDir = WorkingDir @@ -578,7 +580,7 @@ try: import runtime.WampClient as WC except Exception, e: - print _("WAMP import failed :"), e + print(_("WAMP import failed :"), e) wampconf = None # Load extensions @@ -594,7 +596,7 @@ pyruntimevars["website"] = website statuschange.append(NS.website_statuslistener_factory(website)) except Exception, e: - print _("Nevow Web service failed. "), e + print(_("Nevow Web service failed. "), e) if wampconf is not None: try: @@ -602,7 +604,7 @@ pyruntimevars["wampsession"] = WC.GetSession WC.SetServer(pyroserver) except Exception, e: - print _("WAMP client startup failed. "), e + print(_("WAMP client startup failed. "), e) if havetwisted or havewx: diff -r bcb50e736a46 -r 91796f408540 PLCOpenEditor.py --- a/PLCOpenEditor.py Fri Sep 22 10:52:44 2017 +0300 +++ b/PLCOpenEditor.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 import wx import os import sys @@ -375,8 +377,8 @@ # def SetOpenFile( def PrintUsage(self): - print "\nUsage of PLCOpenEditor.py :" - print "\n %s [Filepath]\n" % sys.argv[0] + print("\nUsage of PLCOpenEditor.py :") + print("\n %s [Filepath]\n" % sys.argv[0]) def ParseCommandLine(self): # Parse options given to PLCOpenEditor in command line diff -r bcb50e736a46 -r 91796f408540 canfestival/config_utils.py --- a/canfestival/config_utils.py Fri Sep 22 10:52:44 2017 +0300 +++ b/canfestival/config_utils.py Fri Sep 22 10:54:42 2017 +0300 @@ -22,6 +22,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 from types import * # Translation between IEC types and Can Open types @@ -697,7 +699,7 @@ import getopt def usage(): - print """ + print(""" Usage of config_utils.py test : %s [options] @@ -710,7 +712,7 @@ Reset the reference result of config_utils test. Use with caution. Be sure that config_utils is currently working properly. -""" % sys.argv[0] +""" % sys.argv[0]) # Boolean that indicate if reference result must be redefined reset = False @@ -764,7 +766,7 @@ try: masternode, pointedvariables = GenerateConciseDCF(locations, (0, 1), nodelist, True, "TestNode") except ValueError, message: - print "%s\nTest Failed!" % message + print("%s\nTest Failed!" % message) sys.exit() import pprint @@ -780,7 +782,7 @@ testfile.write(result) testfile.close() - print "Reset Successful!" + print("Reset Successful!") else: import os diff -r bcb50e736a46 -r 91796f408540 connectors/PYRO/__init__.py --- a/connectors/PYRO/__init__.py Fri Sep 22 10:52:44 2017 +0300 +++ b/connectors/PYRO/__init__.py Fri Sep 22 10:54:42 2017 +0300 @@ -22,6 +22,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 import Pyro import Pyro.core import Pyro.util @@ -123,7 +125,7 @@ # confnodesroot.logger.write_error(traceback.format_exc()) errmess = ''.join(Pyro.util.getPyroTraceback(e)) confnodesroot.logger.write_error(errmess + "\n") - print errmess + print(errmess) confnodesroot._SetConnector(None) return default return catcher_func diff -r bcb50e736a46 -r 91796f408540 connectors/WAMP/__init__.py --- a/connectors/WAMP/__init__.py Fri Sep 22 10:52:44 2017 +0300 +++ b/connectors/WAMP/__init__.py Fri Sep 22 10:54:42 2017 +0300 @@ -22,6 +22,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 import sys import traceback import atexit @@ -43,13 +45,13 @@ global _WampSession, _WampSessionEvent _WampSession = self _WampSessionEvent.set() - print 'WAMP session joined for :', self.config.extra["ID"] + print('WAMP session joined for :', self.config.extra["ID"]) def onLeave(self, details): global _WampSession, _WampSessionEvent _WampSessionEvent.clear() _WampSession = None - print 'WAMP session left' + print('WAMP session left') PLCObjDefaults = { @@ -121,7 +123,7 @@ except Exception, e: errmess = traceback.format_exc() confnodesroot.logger.write_error(errmess+"\n") - print errmess + print(errmess) # confnodesroot._SetConnector(None) return PLCObjDefaults.get(funcname) return catcher_func diff -r bcb50e736a46 -r 91796f408540 docutil/docpdf.py --- a/docutil/docpdf.py Fri Sep 22 10:52:44 2017 +0300 +++ b/docutil/docpdf.py Fri Sep 22 10:54:42 2017 +0300 @@ -22,6 +22,7 @@ # 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 import os import wx @@ -58,7 +59,7 @@ if pagenum is None: os.system("%s -remote DS301 %s &" % (readerexepath, pdffile)) else: - print "Open pdf %s at page %d" % (pdffile, pagenum) + print("Open pdf %s at page %d" % (pdffile, pagenum)) os.system("%s -remote DS301 %s %d &" % (readerexepath, pdffile, pagenum)) diff -r bcb50e736a46 -r 91796f408540 i18n/mki18n.py --- a/i18n/mki18n.py Fri Sep 22 10:52:44 2017 +0300 +++ b/i18n/mki18n.py Fri Sep 22 10:54:42 2017 +0300 @@ -78,6 +78,7 @@ # Module Import # ------------- # +from __future__ import print_function import os import sys import wx @@ -112,7 +113,7 @@ def verbosePrint(verbose, str): if verbose: - print str + print(str) def processCustomFiles(filein, fileout, regexp, prefix=''): @@ -300,7 +301,7 @@ def printUsage(errorMsg=None): """Displays how to use this script from the command line.""" - print """ + print(""" ################################################################################## # mki18n : Make internationalization files. # # Uses the GNU gettext system to create PO (Portable Object) files # @@ -330,9 +331,9 @@ # specify the path of the target application. If you leave it out mki18n # # will use the current directory as the application main directory. # # # - ##################################################################################""" + ##################################################################################""") if errorMsg: - print "\n ERROR: %s" % errorMsg + print("\n ERROR: %s" % errorMsg) def fileBaseOf(filename, withPath=0): @@ -473,7 +474,7 @@ if len(pargs) == 0: appDirPath = os.getcwd() if option['verbose']: - print "No project directory given. Using current one: %s" % appDirPath + print("No project directory given. Using current one: %s" % appDirPath) elif len(pargs) == 1: appDirPath = pargs[0] else: @@ -483,7 +484,7 @@ # If no domain specified, use the name of the target directory option['domain'] = fileBaseOf(appDirPath) if option['verbose']: - print "Application domain used is: '%s'" % option['domain'] + print("Application domain used is: '%s'" % option['domain']) if option['po']: try: makePO(appDirPath, option['domain'], option['verbose']) diff -r bcb50e736a46 -r 91796f408540 runtime/NevowServer.py --- a/runtime/NevowServer.py Fri Sep 22 10:52:44 2017 +0300 +++ b/runtime/NevowServer.py Fri Sep 22 10:54:42 2017 +0300 @@ -22,6 +22,8 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +from __future__ import print_function import os import util.paths as paths from nevow import rend, appserver, inevow, tags, loaders, athena @@ -185,7 +187,7 @@ listening = False reactor.listenTCP(port, site) - print _("HTTP interface port :"), port + print(_('HTTP interface port :'), port) return website diff -r bcb50e736a46 -r 91796f408540 runtime/ServicePublisher.py --- a/runtime/ServicePublisher.py Fri Sep 22 10:52:44 2017 +0300 +++ b/runtime/ServicePublisher.py Fri Sep 22 10:54:42 2017 +0300 @@ -21,6 +21,8 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +from __future__ import print_function import socket import threading from util import Zeroconf @@ -54,11 +56,11 @@ self.port = port self.server = Zeroconf.Zeroconf(ip) - print "MDNS brodcasting on :"+ip + print("MDNS brodcasting on :" + ip) if ip == "0.0.0.0": ip = self.gethostaddr() - print "MDNS brodcasted service address :"+ip + print("MDNS brodcasted service address :" + ip) self.ip_32b = socket.inet_aton(ip) self.server.registerService( diff -r bcb50e736a46 -r 91796f408540 runtime/WampClient.py --- a/runtime/WampClient.py Fri Sep 22 10:52:44 2017 +0300 +++ b/runtime/WampClient.py Fri Sep 22 10:54:42 2017 +0300 @@ -21,6 +21,8 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +from __future__ import print_function import sys from autobahn.twisted import wamp from autobahn.twisted.websocket import WampWebSocketClientFactory, connectWS @@ -68,7 +70,7 @@ global _WampSession _WampSession = self ID = self.config.extra["ID"] - print 'WAMP session joined by :', ID + print('WAMP session joined by :', ID) for name in ExposedCalls: reg = yield self.register(GetCallee(name), '.'.join((ID, name))) @@ -81,7 +83,7 @@ def onLeave(self, details): global _WampSession _WampSession = None - print 'WAMP session left' + print('WAMP session left') class ReconnectingWampWebSocketClientFactory(WampWebSocketClientFactory, ReconnectingClientFactory): @@ -125,7 +127,7 @@ # start the client from a Twisted endpoint conn = connectWS(transport_factory) - print "WAMP client connecting to :", WSClientConf["url"] + print("WAMP client connecting to :", WSClientConf["url"]) return conn diff -r bcb50e736a46 -r 91796f408540 svgui/pyjs/build.py --- 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 @@ #!/usr/bin/env python +from __future__ import print_function import sys import os import shutil @@ -103,7 +104,7 @@ except (IOError, os.error), why: errors.append((srcname, dstname, why)) if errors: - print errors + print(errors) def check_html_file(source_file, dest_path): @@ -175,24 +176,24 @@ msg = "Building '%(app_name)s' to output directory '%(output)s'" % locals() if debug: msg += " with debugging statements" - print msg + print(msg) # 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) return if not os.path.isdir(output): try: - print "Creating output directory" + print("Creating output directory") os.mkdir(output) except StandardError, e: - print >>sys.stderr, "Exception creating output directory %s: %s" % (output, e) + print("Exception creating output directory %s: %s" % (output, e), file=sys.stderr) # public dir for p in pyjs.path: pub_dir = join(p, 'public') if isdir(pub_dir): - 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 @@ try: shutil.copy(html_input_filename, html_output_filename) except Exception: - print >>sys.stderr, "Warning: Missing module HTML file %s" % html_input_filename - - print "Copying: %(html_input_filename)s" % locals() + print("Warning: Missing module HTML file %s" % html_input_filename, file=sys.stderr) + + 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) # pygwt.js - 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) pygwt_js_output.close() # Images - 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 @@ # AppName.nocache.html - 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 >>home_nocache_html_output, home_nocache_html_template % dict( - app_name=app_name, - script_selectors=script_selectors.getvalue(), - ) + print(select_tmpl % (platform, file_prefix), file=script_selectors) + + print( + home_nocache_html_template % dict( + app_name=app_name, + 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): p = join(output, name) - print "Deleting existing app file %s" % p + print("Deleting existing app file %s" % p) os.unlink(p) app_files = [] @@ -334,7 +336,7 @@ pd = overrides.setdefault(mname, {}) pd[platform] = name - print appcode + print(appcode) # mod_code[platform][app_name] = appcode # platform.Module.cache.js @@ -432,7 +434,7 @@ else: 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 @@ else: mod_cache_html_output = StringIO() - print >>mod_cache_html_output, mod_cache_html_template % dict( + print(mod_cache_html_template % dict( mod_name=mod_name, app_name=app_name, modnames=modnames, @@ -464,7 +466,7 @@ mod_libs=mod_libs[platform][mod_name], dynamic=dynamic, mod_code=mod_code_, - ) + ), file=mod_cache_html_output) if dynamic: mod_cache_html_output.close() @@ -518,8 +520,8 @@ out_file.write(file_contents) out_file.close() 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)) return app_files @@ -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) diff -r bcb50e736a46 -r 91796f408540 svgui/pyjs/pyjs.py --- 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 import sys from types import StringType import compiler @@ -226,36 +227,36 @@ vdec = '' else: vdec = 'var ' - print >>self.output, 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(UU+"%s%s = function (__mod_name__) {" % (vdec, 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) if decl: - print >>self.output, decl + self.printo(decl) if self.debug: 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, '}' - - print >>self.output, haltException + ".prototype.toString = function()" - print >>self.output, '{' - print >>self.output, 'return this.name + ": \\"" + this.message + "\\"";' - print >>self.output, '}' + self.printo(haltException + ' = function () {') + self.printo(' this.message = "Program Halted";') + self.printo(' this.name = "' + haltException + '";') + self.printo('}') + self.printo('') + self.printo(haltException + ".prototype.__str__ = function()") + self.printo('{') + self.printo('return this.message ;') + self.printo('}') + + self.printo(haltException + ".prototype.toString = function()") + self.printo('{') + self.printo('return this.name + ": \\"" + this.message + "\\"";') + self.printo('}') isHaltFunction = self.module_prefix + "IsHaltException" - print >>self.output, """ + self.printo(""") %s = function (s) { var suffix="HaltException"; if (s.length < suffix.length) { @@ -267,7 +268,7 @@ return ss == suffix; } } - """ % isHaltFunction + """ % isHaltFunction) for child in mod.node: 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" - - print >> self.output, "return this;\n" - print >> self.output, "}; /* end %s */ \n" % module_name + # self.printo("\t"+UU+self.modpfx()+"__"+className+"_initialize();") + # self.printo("};\n") + + 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! child_name = name[-1] self.imported_modules_as.append(child_name) - print >> self.output, gen_mod_import(self.raw_module_name, - strip_py(importName), - self.dynamic) + self.printo(gen_mod_import(self.raw_module_name, + strip_py(importName), + self.dynamic)) def _default_args_handler(self, node, arg_names, current_klass, output=None): @@ -377,21 +381,21 @@ default_name = arg_names[default_pos] default_pos += 1 - 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);") + self.printo(" }") 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: default_pos -= 1 - 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)) default_pos += 1 # self._default_args_handler(node, arg_names, current_klass) if node.kwargs: arg_names += ["pyjslib.Dict(__kwargs)"] - print >>self.output, " var __r = "+"".join(["[", ", ".join(arg_names), "]"])+";" + self.printo(" var __r = "+"".join(["[", ", ".join(arg_names), "]"])+";") if node.varargs: 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;") + self.printo("};") def _function(self, node, local=False): if local: @@ -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;" - - print >>self.output, "};" - print >>self.output, "%s.__name__ = '%s';\n" % (function_name, node.name) + self.printo(" return null;") + + self.printo("};") + 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 # here too - print >>self.output, " return " + expr + ";" + self.printo(" return " + expr + ";") def _break(self, node, current_klass): - print >>self.output, " break;" + self.printo(" 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) call_args.append(arg) - 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 {" + self.printo(" try {") for stmt in node.body.nodes: self._stmt(stmt, current_klass) - print >> self.output, " } catch(%s) {" % errName + self.printo(" } catch(%s) {" % errName) if expr: k = [] 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))) else: 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) if expr: - # print >> self.output, "} else { throw(%s); } " % errName - print >> self.output, "}" + # self.printo("} else { throw(%s); } " % errName) + self.printo("}") if node.else_ is not None: - print >>self.output, " } finally {" + self.printo(" } finally {") for stmt in node.else_: self._stmt(stmt, current_klass) - print >>self.output, " }" + self.printo(" }") # 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 "error..." + print(top_level, current_klass, repr(v)) + print(self.top_level_vars) + print(self.top_level_functions) + print(self.local_arg_stack) + print("error...") local_var_names = None las = len(self.local_arg_stack) @@ -786,11 +790,11 @@ else: raise TranslationError("more than one base (in _class)", node) - print >>self.output, UU+class_name_ + " = function () {" + self.printo(UU+class_name_ + " = function () {") # call superconstructor # if base_class: - # print >>self.output, " __" + base_class + ".call(this);" - print >>self.output, "}" + # self.printo(" __" + base_class + ".call(this);") + self.printo("}") if not init_method: 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+" = {};") else: 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_+");" - else: - print >>self.output, " 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(" if(!"+UU+base_class_+".__was_initialized__)") + self.printo(" "+UU+base_class_+".__initialize__();") + self.printo(" pyjs_extend(" + UU+class_name_ + ", "+UU+base_class_+");") + else: + self.printo(" pyjs_extend(" + UU+class_name_ + ", "+UU+"pyjslib.__Object);") + + self.printo(" "+cls_obj+".__new__ = "+UU+class_name+";") + self.printo(" "+cls_obj+".__name__ = '"+UU+node.name+"';") for child in node.code: if isinstance(child, ast.Pass): @@ -843,9 +847,9 @@ pass else: raise TranslationError("unsupported type (in _class)", child) - print >>self.output, "}" - - print >> self.output, class_name_+".__initialize__();" + self.printo("}") + + self.printo(class_name_+".__initialize__();") def classattr(self, node, current_klass): self._assign(node, current_klass, True) @@ -854,8 +858,8 @@ if node.expr2: raise TranslationError("More than one expression unsupported", node) - 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_): # reset global var scope @@ -875,8 +879,8 @@ if staticmethod: 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;") return else: if len(arg_names) == 0: @@ -901,7 +905,7 @@ fexpr = UU + class_name_ + ".prototype.__class__." + node.name else: fexpr = UU + class_name_ + ".prototype." + node.name - print >>self.output, " "+fexpr + " = function" + function_args + " {" + self.printo(" "+fexpr + " = function" + function_args + " {") # default arguments 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.printo(" };") 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 # class as "self" 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(" };") + self.printo(" "+fexpr+".class_method = true;") + self.printo(" "+altexpr+".instance_method = true;") else: # 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 - - print >>self.output, UU + class_name_ + ".prototype.%s.__name__ = '%s';" % \ - (node.name, node.name) + self.printo(" "+altexpr + " = function() {") + self.printo(" return " + fexpr + ".call.apply("+fexpr+", arguments);") + self.printo(" };") + self.printo(" "+altexpr+".unbound_method = true;") + self.printo(" "+fexpr+".instance_method = true;") + self.printo(" "+altexpr+".__name__ = '%s';" % node.name) + + 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_self = None self.method_imported_globals = set() @@ -964,7 +968,7 @@ def _stmt(self, node, current_klass): debugStmt = self.debug and not self._isNativeFunc(node) if debugStmt: - print >>self.output, ' try {' + self.printo(' try {') if isinstance(node, ast.Return): self._return(node, current_klass) @@ -1025,7 +1029,7 @@ ' }' ) for s in out: - print >>self.output, s + self.printo(s) def get_line_trace(self, node): lineNum = "Unknown" @@ -1053,7 +1057,7 @@ lhs = self._name(node.node, current_klass) op = node.op 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): if len(node.nodes) != 1: @@ -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 + ");") return else: 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 @@ "(in _assign)", child) 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 + ");") continue - print >>self.output, " " + lhs + " = " + rhs + ";" + self.printo(" " + lhs + " = " + rhs + ";") return else: raise TranslationError("unsupported type (in _assign)", v) rhs = self.expr(node.expr, current_klass) if dbg: - 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 @@ debugStmt = False if debugStmt: 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 + self.printo(raw_js) else: expr = self._callfunc(node.expr, current_klass) - print >>self.output, " " + expr + ";" + self.printo(" " + expr + ";") if debugStmt: - 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)) else: raise TranslationError("unsupported type (in _discard)", node.expr) @@ -1217,9 +1219,9 @@ if test: expr = self.expr(test, current_klass) - print >>self.output, " " + keyword + " (pyjslib.bool(" + expr + ")) {" - else: - print >>self.output, " " + keyword + " {" + self.printo(" " + keyword + " (pyjslib.bool(" + expr + ")) {") + else: + self.printo(" " + keyword + " {") if isinstance(consequence, ast.Stmt): for child in consequence.nodes: @@ -1227,7 +1229,7 @@ else: raise TranslationError("unsupported type (in _if_test)", consequence) - print >>self.output, " }" + self.printo(" }") def _from(self, node): for name in node.names: @@ -1315,33 +1317,33 @@ lhs = "var " + assign_name iterator_name = "__" + assign_name - print >>self.output, """ + self.printo(""" var %(iterator_name)s = %(list_expr)s.__iter__(); try { while (true) { %(lhs)s %(op)s %(iterator_name)s.next(); %(assign_tuple)s - """ % locals() + """ % locals()) for node in node.body.nodes: self._stmt(node, current_klass) - print >>self.output, """ + self.printo(""" } } catch (e) { if (e.__name__ != pyjslib.StopIteration.__name__) { throw e; } } - """ % locals() + """ % locals()) 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) else: raise TranslationError("unsupported type (in _while)", node.body) - print >>self.output, " }" + self.printo(" }") def _const(self, node): 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) + ");") else: 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, output=res) - print >> res, 'return %s;}' % expr + print('return %s;}' % expr, file=res) return res.getvalue() def _slice(self, node, current_klass): @@ -1561,9 +1563,9 @@ if self.verbose: if override: - print "Importing %s (Platform %s)" % (module_name, self.platform) + print("Importing %s (Platform %s)" % (module_name, self.platform)) elif importing: - print "Importing %s" % (module_name) + print("Importing %s" % (module_name)) return mod, override @@ -1717,28 +1719,28 @@ continue self.library_modules.append(library) if self.verbose: - 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 >> lib_code, "/* initialize static library */" - print >> lib_code, "%s%s();\n" % (UU, library) - - print >> lib_code, '\n//\n// END LIB '+library+'\n//\n' + 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), + file=lib_code) + + print("/* initialize static library */", file=lib_code) + print("%s%s();\n" % (UU, library), file=lib_code) + + print('\n//\n// END LIB '+library+'\n//\n', file=lib_code) if module_name: - 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), + file=app_code) for js in imported_js: path = self.findFile(js) if os.path.isfile(path): if self.verbose: - 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' - else: - print >>sys.stderr, 'Warning: Unable to find imported javascript:', js + 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) + else: + print('Warning: Unable to find imported javascript:', js, file=sys.stderr) return lib_code.getvalue(), app_code.getvalue() @@ -1750,17 +1752,17 @@ def main(): import sys if len(sys.argv) < 2: - print >> sys.stderr, usage % sys.argv[0] + print(usage % sys.argv[0], file=sys.stderr) sys.exit(1) 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) sys.exit(1) if len(sys.argv) > 2: module_name = sys.argv[2] else: module_name = None - print translate(file_name, module_name), + print(translate(file_name, module_name), end="") if __name__ == "__main__": diff -r bcb50e736a46 -r 91796f408540 tests/tools/test_application.py --- a/tests/tools/test_application.py Fri Sep 22 10:52:44 2017 +0300 +++ b/tests/tools/test_application.py Fri Sep 22 10:54:42 2017 +0300 @@ -22,6 +22,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 import os import sys import unittest @@ -177,7 +179,7 @@ compiled and run on SoftPLC. """ project = self.GetProjectPath(name) - print "Testing example " + name + print("Testing example " + name) self.CheckTestProject(project) diff -r bcb50e736a46 -r 91796f408540 util/Zeroconf.py --- a/util/Zeroconf.py Fri Sep 22 10:52:44 2017 +0300 +++ b/util/Zeroconf.py Fri Sep 22 10:54:42 2017 +0300 @@ -74,6 +74,8 @@ # ensure names end in '.local.' # timeout on receiving socket for clean shutdown + +from __future__ import print_function import string import time import struct @@ -1564,21 +1566,21 @@ if __name__ == '__main__': - print "Multicast DNS Service Discovery for Python, version", __version__ + print("Multicast DNS Service Discovery for Python, version", __version__) r = Zeroconf() - print "1. Testing registration of a service..." + print("1. Testing registration of a service...") desc = {'version': '0.10', 'a': 'test value', 'b': 'another value'} info = ServiceInfo("_http._tcp.local.", "My Service Name._http._tcp.local.", socket.inet_aton("127.0.0.1"), 1234, 0, 0, desc) - print " Registering service..." + print(" Registering service...") r.registerService(info) - print " Registration done." - print "2. Testing query of service information..." - print " Getting ZOE service:", str(r.getServiceInfo("_http._tcp.local.", "ZOE._http._tcp.local.")) - print " Query done." - print "3. Testing query of own service..." - print " Getting self:", str(r.getServiceInfo("_http._tcp.local.", "My Service Name._http._tcp.local.")) - print " Query done." - print "4. Testing unregister of service information..." + print(" Registration done.") + print("2. Testing query of service information...") + print(" Getting ZOE service:", str(r.getServiceInfo("_http._tcp.local.", "ZOE._http._tcp.local."))) + print(" Query done.") + print("3. Testing query of own service...") + print(" Getting self:", str(r.getServiceInfo("_http._tcp.local.", "My Service Name._http._tcp.local."))) + print(" Query done.") + print("4. Testing unregister of service information...") r.unregisterService(info) - print " Unregister done." + print(" Unregister done.") r.close() diff -r bcb50e736a46 -r 91796f408540 xmlclass/xmlclass.py --- a/xmlclass/xmlclass.py Fri Sep 22 10:52:44 2017 +0300 +++ b/xmlclass/xmlclass.py Fri Sep 22 10:54:42 2017 +0300 @@ -22,6 +22,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 import os import sys import re @@ -1192,20 +1194,20 @@ items.sort() if self.FileName is not None: for filename, classes in items: - print "File '%s':" % filename + print("File '%s':" % filename) class_items = classes.items() class_items.sort() for classname, xmlclass in class_items: - print "%s: %s" % (classname, str(xmlclass)) + print("%s: %s" % (classname, str(xmlclass))) else: for classname, xmlclass in items: - print "%s: %s" % (classname, str(xmlclass)) + print("%s: %s" % (classname, str(xmlclass))) def PrintClassNames(self): classnames = self.XMLClassDefinitions.keys() classnames.sort() for classname in classnames: - print classname + print(classname) def ComputeMultiplicity(name, infos): diff -r bcb50e736a46 -r 91796f408540 xmlclass/xsdschema.py --- a/xmlclass/xsdschema.py Fri Sep 22 10:52:44 2017 +0300 +++ b/xmlclass/xsdschema.py Fri Sep 22 10:54:42 2017 +0300 @@ -22,6 +22,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 import os import re import datetime @@ -1082,7 +1084,7 @@ if element is None: if name in self.CurrentCompilations: if self.Debug: - print "Warning : \"%s\" is circular referenced!" % element_name + print("Warning : \"%s\" is circular referenced!" % element_name) else: raise ValueError("\"%s\" isn't defined!" % element_name) if element_type is not None and element["type"] != element_type: