# HG changeset patch # User Andrey Skvortsov # Date 1538492929 -10800 # Node ID 5587c490a070ec2d8f3a6206c11c2c6d89b1593d # Parent 316ee9fff395526aa10acbd7f8fcf201fcaf7c54 Use python 3 compatible exception syntax everywhere diff -r 316ee9fff395 -r 5587c490a070 Beremiz_service.py --- a/Beremiz_service.py Tue Oct 02 17:18:09 2018 +0300 +++ b/Beremiz_service.py Tue Oct 02 18:08:49 2018 +0300 @@ -70,7 +70,7 @@ try: opts, argv = getopt.getopt(sys.argv[1:], "i:p:n:x:t:a:w:c:e:s:h", ["help", "version"]) -except getopt.GetoptError, err: +except getopt.GetoptError as err: # print help information and exit: print(str(err)) # will print something like "option -a not recognized" usage() diff -r 316ee9fff395 -r 5587c490a070 CodeFileTreeNode.py --- a/CodeFileTreeNode.py Tue Oct 02 17:18:09 2018 +0300 +++ b/CodeFileTreeNode.py Tue Oct 02 18:08:49 2018 +0300 @@ -123,7 +123,7 @@ (fname, lnum, src) = ((self.CODEFILE_NAME,) + error) self.GetCTRoot().logger.write_warning(XSDSchemaErrorMessage.format(a1=fname, a2=lnum, a3=src)) self.CreateCodeFileBuffer(True) - except Exception, exc: + except Exception as exc: msg = _("Couldn't load confnode parameters {a1} :\n {a2}").format(a1=self.CTNName(), a2=unicode(exc)) self.GetCTRoot().logger.write_error(msg) self.GetCTRoot().logger.write_error(traceback.format_exc()) diff -r 316ee9fff395 -r 5587c490a070 ConfigTreeNode.py --- a/ConfigTreeNode.py Tue Oct 02 17:18:09 2018 +0300 +++ b/ConfigTreeNode.py Tue Oct 02 18:08:49 2018 +0300 @@ -626,7 +626,7 @@ self.GetCTRoot().logger.write_warning(XSDSchemaErrorMessage.format(a1=fname, a2=lnum, a3=src)) self.MandatoryParams = ("BaseParams", self.BaseParams) basexmlfile.close() - except Exception, exc: + except Exception as exc: msg = _("Couldn't load confnode base parameters {a1} :\n {a2}").format(a1=ConfNodeName, a2=unicode(exc)) self.GetCTRoot().logger.write_error(msg) self.GetCTRoot().logger.write_error(traceback.format_exc()) @@ -643,7 +643,7 @@ setattr(self, name, obj) self.CTNParams = (name, obj) xmlfile.close() - except Exception, exc: + except Exception as exc: msg = _("Couldn't load confnode parameters {a1} :\n {a2}").format(a1=ConfNodeName, a2=unicode(exc)) self.GetCTRoot().logger.write_error(msg) self.GetCTRoot().logger.write_error(traceback.format_exc()) @@ -656,7 +656,7 @@ pname, ptype = CTNDir.split(NameTypeSeparator) try: self.CTNAddChild(pname, ptype) - except Exception, exc: + except Exception as exc: msg = _("Could not add child \"{a1}\", type {a2} :\n{a3}\n").format(a1=pname, a2=ptype, a3=unicode(exc)) self.GetCTRoot().logger.write_error(msg) self.GetCTRoot().logger.write_error(traceback.format_exc()) diff -r 316ee9fff395 -r 5587c490a070 PLCControler.py --- a/PLCControler.py Tue Oct 02 17:18:09 2018 +0300 +++ b/PLCControler.py Tue Oct 02 18:08:49 2018 +0300 @@ -460,7 +460,7 @@ programfile.close() self.ProgramFilePath = filepath return program_text, errors, warnings - except PLCGenException, ex: + except PLCGenException as ex: errors.append(ex.message) else: errors.append("No project opened") diff -r 316ee9fff395 -r 5587c490a070 PLCGenerator.py --- a/PLCGenerator.py Tue Oct 02 17:18:09 2018 +0300 +++ b/PLCGenerator.py Tue Oct 02 18:08:49 2018 +0300 @@ -1024,7 +1024,7 @@ format(a1=block_type, a2=self.Name)) try: self.GenerateBlock(instance, block_infos, body, None) - except ValueError, e: + except ValueError as e: raise PLCGenException(e.message) elif isinstance(instance, ConnectorClass): connector = instance.getname() @@ -1302,7 +1302,7 @@ format(a1=block_type, a2=self.Name)) try: paths.append(str(self.GenerateBlock(next, block_infos, body, connection, order, to_inout))) - except ValueError, e: + except ValueError as e: raise PLCGenException(e.message) elif isinstance(next, ContinuationClass): name = next.getname() diff -r 316ee9fff395 -r 5587c490a070 ProjectController.py --- a/ProjectController.py Tue Oct 02 17:18:09 2018 +0300 +++ b/ProjectController.py Tue Oct 02 18:08:49 2018 +0300 @@ -799,7 +799,7 @@ status, result, err_result = ProcessLogger(self.logger, buildcmd, no_stdout=True, no_stderr=True).spin() - except Exception, e: + except Exception as e: self.logger.write_error(buildcmd + "\n") self.logger.write_error(repr(e) + "\n") return False diff -r 316ee9fff395 -r 5587c490a070 canfestival/canfestival.py --- a/canfestival/canfestival.py Tue Oct 02 17:18:09 2018 +0300 +++ b/canfestival/canfestival.py Tue Oct 02 18:08:49 2018 +0300 @@ -451,7 +451,7 @@ # Create a new copy of the model with DCF loaded with PDO mappings for desired location try: master, pointers = config_utils.GenerateConciseDCF(locations, current_location, self, self.CanFestivalNode.getSync_TPDOs(), "OD_%s" % prefix) - except config_utils.PDOmappingException, e: + except config_utils.PDOmappingException as e: raise Exception(e.message) # Do generate C file. res = gen_cfile.GenerateFile(Gen_OD_path, master, pointers) diff -r 316ee9fff395 -r 5587c490a070 canfestival/config_utils.py --- a/canfestival/config_utils.py Tue Oct 02 17:18:09 2018 +0300 +++ b/canfestival/config_utils.py Tue Oct 02 18:08:49 2018 +0300 @@ -765,7 +765,7 @@ # Generate MasterNode configuration try: masternode, pointedvariables = GenerateConciseDCF(locations, (0, 1), nodelist, True, "TestNode") - except ValueError, message: + except ValueError as message: print("%s\nTest Failed!" % message) sys.exit() diff -r 316ee9fff395 -r 5587c490a070 connectors/PYRO/__init__.py --- a/connectors/PYRO/__init__.py Tue Oct 02 17:18:09 2018 +0300 +++ b/connectors/PYRO/__init__.py Tue Oct 02 18:08:49 2018 +0300 @@ -120,12 +120,12 @@ def catcher_func(*args, **kwargs): try: return func(*args, **kwargs) - except Pyro.errors.ConnectionClosedError, e: + except Pyro.errors.ConnectionClosedError as e: confnodesroot.logger.write_error(_("Connection lost!\n")) confnodesroot._SetConnector(None) - except Pyro.errors.ProtocolError, e: + except Pyro.errors.ProtocolError as e: confnodesroot.logger.write_error(_("Pyro exception: %s\n") % e) - except Exception, e: + except Exception as e: # confnodesroot.logger.write_error(traceback.format_exc()) errmess = ''.join(Pyro.util.getPyroTraceback(e)) confnodesroot.logger.write_error(errmess + "\n") diff -r 316ee9fff395 -r 5587c490a070 etherlab/EthercatMaster.py --- a/etherlab/EthercatMaster.py Tue Oct 02 17:18:09 2018 +0300 +++ b/etherlab/EthercatMaster.py Tue Oct 02 18:08:49 2018 +0300 @@ -249,7 +249,7 @@ EtherCATConfigParser.LoadXMLString(config_xmlfile.read()) if error is None: config_is_saved = True - except Exception, e: + except Exception as e: error = e.message config_xmlfile.close() @@ -270,7 +270,7 @@ ProcessVariablesParser.LoadXMLString(process_xmlfile.read()) if error is None: process_is_saved = True - except Exception, e: + except Exception as e: error = e.message process_xmlfile.close() diff -r 316ee9fff395 -r 5587c490a070 etherlab/etherlab.py --- a/etherlab/etherlab.py Tue Oct 02 17:18:09 2018 +0300 +++ b/etherlab/etherlab.py Tue Oct 02 18:08:49 2018 +0300 @@ -226,7 +226,7 @@ if error is not None: self.GetCTRoot().logger.write_warning( XSDSchemaErrorMessage % (filepath + error)) - except Exception, exc: + except Exception as exc: self.modules_infos, error = None, unicode(exc) xmlfile.close() diff -r 316ee9fff395 -r 5587c490a070 i18n/mki18n.py --- a/i18n/mki18n.py Tue Oct 02 17:18:09 2018 +0300 +++ b/i18n/mki18n.py Tue Oct 02 18:08:49 2018 +0300 @@ -486,7 +486,7 @@ exit_code = 1 try: optionList, pargs = getopt.getopt(sys.argv[1:], validOptions, validLongOptions) - except getopt.GetoptError, e: + except getopt.GetoptError as e: printUsage(e[0]) sys.exit(1) for (opt, val) in optionList: @@ -512,7 +512,7 @@ try: makePO(appDirPath, option['domain'], option['verbose']) exit_code = 0 - except IOError, e: + except IOError as e: printUsage(e[1] + '\n You must write a file app.fil that contains the list of all files to parse.') if option['mo']: makeMO(appDirPath, option['moTarget'], option['domain'], option['verbose'], option['forceEnglish']) diff -r 316ee9fff395 -r 5587c490a070 plcopen/plcopen.py --- a/plcopen/plcopen.py Tue Oct 02 17:18:09 2018 +0300 +++ b/plcopen/plcopen.py Tue Oct 02 18:08:49 2018 +0300 @@ -298,7 +298,7 @@ return tree, error - except Exception, e: + except Exception as e: return None, e.message diff -r 316ee9fff395 -r 5587c490a070 py_ext/PythonFileCTNMixin.py --- a/py_ext/PythonFileCTNMixin.py Tue Oct 02 17:18:09 2018 +0300 +++ b/py_ext/PythonFileCTNMixin.py Tue Oct 02 18:08:49 2018 +0300 @@ -73,7 +73,7 @@ os.remove(filepath) self.CreateCodeFileBuffer(False) self.OnCTNSave() - except Exception, exc: + except Exception as exc: error = unicode(exc) if error is not None: diff -r 316ee9fff395 -r 5587c490a070 runtime/PLCObject.py --- a/runtime/PLCObject.py Tue Oct 02 17:18:09 2018 +0300 +++ b/runtime/PLCObject.py Tue Oct 02 18:08:49 2018 +0300 @@ -497,7 +497,7 @@ else: res = str(result) self.python_runtime_vars["FBID"] = None - except Exception, e: + except Exception as e: res = "#EXCEPTION : "+str(e) self.LogMessage(1, ('PyEval@0x%x(Code="%s") Exception "%s"') % (FBID, cmd, str(e))) diff -r 316ee9fff395 -r 5587c490a070 runtime/WampClient.py --- a/runtime/WampClient.py Tue Oct 02 17:18:09 2018 +0300 +++ b/runtime/WampClient.py Tue Oct 02 18:08:49 2018 +0300 @@ -157,7 +157,7 @@ if protocolOptions: self.setProtocolOptions(**protocolOptions) _transportFactory = self - except Exception, e: + except Exception as e: print(_("Custom protocol options failed :"), e) _transportFactory = None diff -r 316ee9fff395 -r 5587c490a070 svgui/pyjs/build.py --- a/svgui/pyjs/build.py Tue Oct 02 17:18:09 2018 +0300 +++ b/svgui/pyjs/build.py Tue Oct 02 18:08:49 2018 +0300 @@ -99,7 +99,7 @@ copytree_exists(srcname, dstname, symlinks) else: shutil.copy2(srcname, dstname) - except (IOError, os.error), why: + except (IOError, os.error) as why: errors.append((srcname, dstname, why)) if errors: print(errors) @@ -184,7 +184,7 @@ try: print("Creating output directory") os.mkdir(output) - except StandardError, e: + except StandardError as e: print("Exception creating output directory %s: %s" % (output, e), file=sys.stderr) # public dir