# HG changeset patch # User Andrey Skvortsov # Date 1503155540 -10800 # Node ID c52d1460cea8a62e503193c3b9b3b6003d1080c7 # Parent 6cf16e5bfbf9052d92f35da1e94358b85382281a clean-up: fix PEP8 E722 do not use bare except' better it'd be to use particular exception instead of 'except Exception'. diff -r 6cf16e5bfbf9 -r c52d1460cea8 Beremiz.py --- a/Beremiz.py Sat Aug 19 17:17:54 2017 +0300 +++ b/Beremiz.py Sat Aug 19 18:12:20 2017 +0300 @@ -161,7 +161,7 @@ try: import urllib2 updateinfo = urllib2.urlopen(self.updateinfo_url, None).read() - except: + except Exception: updateinfo = _("update info unavailable.") from threading import Thread diff -r 6cf16e5bfbf9 -r c52d1460cea8 BeremizIDE.py --- a/BeremizIDE.py Sat Aug 19 17:17:54 2017 +0300 +++ b/BeremizIDE.py Sat Aug 19 18:12:20 2017 +0300 @@ -172,7 +172,7 @@ self.LastRefreshTime = gettime() try: self.RefreshLock.release() - except: + except Exception: pass newtime = time.time() if newtime - self.rising_timer > 1: @@ -676,7 +676,7 @@ try: recent_projects = map(DecodeFileSystemPath, self.GetConfigEntry("RecentProjects", [])) - except: + except Exception: recent_projects = [] while self.RecentProjectsMenu.GetMenuItemCount() > len(recent_projects): @@ -826,7 +826,7 @@ try: recent_projects = map(DecodeFileSystemPath, self.GetConfigEntry("RecentProjects", [])) - except: + except Exception: recent_projects = [] if projectpath in recent_projects: recent_projects.remove(projectpath) @@ -846,7 +846,7 @@ try: defaultpath = DecodeFileSystemPath(self.Config.Read("lastopenedfolder")) - except: + except Exception: defaultpath = os.path.expanduser("~") dialog = wx.DirDialog(self, _("Choose an empty directory for new project"), defaultpath) @@ -882,7 +882,7 @@ try: defaultpath = DecodeFileSystemPath(self.Config.Read("lastopenedfolder")) - except: + except Exception: defaultpath = os.path.expanduser("~") dialog = wx.DirDialog(self, _("Choose a project"), defaultpath, @@ -1175,7 +1175,7 @@ if 'self' in exception_locals: try: info['self'] = format_namespace(exception_locals['self'].__dict__) - except: + except Exception: pass if not os.path.exists(path): os.mkdir(path) @@ -1210,7 +1210,7 @@ run_old(*args, **kw) except (KeyboardInterrupt, SystemExit): raise - except: + except Exception: sys.excepthook(*sys.exc_info()) self.run = run_with_except_hook threading.Thread.__init__ = init diff -r 6cf16e5bfbf9 -r c52d1460cea8 Beremiz_service.py --- a/Beremiz_service.py Sat Aug 19 17:17:54 2017 +0300 +++ b/Beremiz_service.py Sat Aug 19 18:12:20 2017 +0300 @@ -167,7 +167,7 @@ wxversion.select(['2.8', '3.0']) import wx havewx = True - except: + except ImportError: print "Wx unavailable !" havewx = False @@ -481,7 +481,7 @@ from twisted.internet import reactor havetwisted = True - except: + except ImportError: print _("Twisted unavailable.") havetwisted = False @@ -557,7 +557,7 @@ run_old(*args, **kw) except (KeyboardInterrupt, SystemExit): raise - except: + except Exception: sys.excepthook(*sys.exc_info()) self.run = run_with_except_hook threading.Thread.__init__ = init diff -r 6cf16e5bfbf9 -r c52d1460cea8 PLCControler.py --- a/PLCControler.py Sat Aug 19 17:17:54 2017 +0300 +++ b/PLCControler.py Sat Aug 19 18:12:20 2017 +0300 @@ -1013,7 +1013,7 @@ ''' try: new_pou, error = LoadPou(pou_xml) - except: + except Exception: error = "" if error is not None: return _("Couldn't paste non-POU object.") @@ -2407,7 +2407,7 @@ try: instances, error = LoadPouInstances(text, bodytype) - except: + except Exception: instances, error = [], "" if error is not None or len(instances) == 0: return _("Invalid plcopen element(s)!!!") diff -r 6cf16e5bfbf9 -r c52d1460cea8 ProjectController.py --- a/ProjectController.py Sat Aug 19 17:17:54 2017 +0300 +++ b/ProjectController.py Sat Aug 19 18:12:20 2017 +0300 @@ -1216,7 +1216,7 @@ self._IECCodeView.SetKeywords(IEC_KEYWORDS) try: text = file(plc_file).read() - except: + except Exception: text = '(* No IEC code have been generated at that time ! *)' self._IECCodeView.SetText(text=text) self._IECCodeView.Editor.SetReadOnly(True) @@ -1718,7 +1718,7 @@ answer = dialog.ShowModal() uri = dialog.GetURI() dialog.Destroy() - except: + except Exception: self.logger.write_error(_("Local service discovery failed!\n")) self.logger.write_error(traceback.format_exc()) uri = None diff -r 6cf16e5bfbf9 -r c52d1460cea8 controls/DebugVariablePanel/DebugVariableGraphicViewer.py --- a/controls/DebugVariablePanel/DebugVariableGraphicViewer.py Sat Aug 19 17:17:54 2017 +0300 +++ b/controls/DebugVariablePanel/DebugVariableGraphicViewer.py Sat Aug 19 18:12:20 2017 +0300 @@ -163,7 +163,7 @@ values = eval(data) if not isinstance(values, TupleType): raise ValueError - except: + except Exception: message = _("Invalid value \"%s\" for debug variable") % data values = None diff -r 6cf16e5bfbf9 -r c52d1460cea8 controls/DebugVariablePanel/DebugVariablePanel.py --- a/controls/DebugVariablePanel/DebugVariablePanel.py Sat Aug 19 17:17:54 2017 +0300 +++ b/controls/DebugVariablePanel/DebugVariablePanel.py Sat Aug 19 18:12:20 2017 +0300 @@ -130,7 +130,7 @@ values = eval(data) if not isinstance(values, TupleType): raise ValueError - except: + except Exception: message = _("Invalid value \"%s\" for debug variable") % data values = None diff -r 6cf16e5bfbf9 -r c52d1460cea8 controls/DebugVariablePanel/DebugVariableTextViewer.py --- a/controls/DebugVariablePanel/DebugVariableTextViewer.py Sat Aug 19 17:17:54 2017 +0300 +++ b/controls/DebugVariablePanel/DebugVariableTextViewer.py Sat Aug 19 18:12:20 2017 +0300 @@ -88,7 +88,7 @@ values = eval(data) if not isinstance(values, TupleType): raise ValueError - except: + except Exception: message = _("Invalid value \"%s\" for debug variable") % data values = None diff -r 6cf16e5bfbf9 -r c52d1460cea8 controls/FolderTree.py --- a/controls/FolderTree.py Sat Aug 19 17:17:54 2017 +0300 +++ b/controls/FolderTree.py Sat Aug 19 18:12:20 2017 +0300 @@ -119,7 +119,7 @@ else: try: files = os.listdir(folderpath) - except: + except Exception: return [] for filename in files: if not filename.startswith("."): diff -r 6cf16e5bfbf9 -r c52d1460cea8 controls/VariablePanel.py --- a/controls/VariablePanel.py Sat Aug 19 17:17:54 2017 +0300 +++ b/controls/VariablePanel.py Sat Aug 19 18:12:20 2017 +0300 @@ -270,7 +270,7 @@ element_type = self.ParentWindow.ElementType try: values = eval(data) - except: + except Exception: message = _("Invalid value \"%s\" for variable grid element") % data values = None if not isinstance(values, TupleType): diff -r 6cf16e5bfbf9 -r c52d1460cea8 dialogs/FindInPouDialog.py --- a/dialogs/FindInPouDialog.py Sat Aug 19 17:17:54 2017 +0300 +++ b/dialogs/FindInPouDialog.py Sat Aug 19 18:12:20 2017 +0300 @@ -172,7 +172,7 @@ try: self.criteria = infos CompilePattern(self.criteria) - except: + except Exception: self.criteria.clear() message = self.RegExpSyntaxErrMsg self.SetStatusText(message) diff -r 6cf16e5bfbf9 -r c52d1460cea8 dialogs/ForceVariableDialog.py --- a/dialogs/ForceVariableDialog.py Sat Aug 19 17:17:54 2017 +0300 +++ b/dialogs/ForceVariableDialog.py Sat Aug 19 18:12:20 2017 +0300 @@ -41,7 +41,7 @@ def get_function(v): try: return f(v) - except: + except Exception: return None return get_function diff -r 6cf16e5bfbf9 -r c52d1460cea8 dialogs/SearchInProjectDialog.py --- a/dialogs/SearchInProjectDialog.py Sat Aug 19 17:17:54 2017 +0300 +++ b/dialogs/SearchInProjectDialog.py Sat Aug 19 18:12:20 2017 +0300 @@ -163,7 +163,7 @@ self.criteria = infos CompilePattern(self.criteria) self.infosPrev = infos - except: + except Exception: self.criteria.clear() message = _("Syntax error in regular expression of pattern to search!") diff -r 6cf16e5bfbf9 -r c52d1460cea8 docutil/docpdf.py --- a/docutil/docpdf.py Sat Aug 19 17:17:54 2017 +0300 +++ b/docutil/docpdf.py Sat Aug 19 18:12:20 2017 +0300 @@ -42,7 +42,7 @@ try: res = _winreg.QueryValue(_winreg.HKEY_LOCAL_MACHINE, 'Software\\Adobe\\%s\\%s\\InstallPath' % (key, numver)) return res - except: + except Exception: pass return None @@ -66,7 +66,7 @@ if wx.Platform == '__WXMSW__': try: readerpath = get_acroversion() - except: + except Exception: wx.MessageBox("Acrobat Reader is not found or installed !") return None diff -r 6cf16e5bfbf9 -r c52d1460cea8 docutil/docsvg.py --- a/docutil/docsvg.py Sat Aug 19 17:17:54 2017 +0300 +++ b/docutil/docsvg.py Sat Aug 19 18:12:20 2017 +0300 @@ -55,7 +55,7 @@ if wx.Platform == '__WXMSW__': try: open_win_svg(get_inkscape_path(), svgfile) - except: + except Exception: wx.MessageBox("Inkscape is not found or installed !") return None else: diff -r 6cf16e5bfbf9 -r c52d1460cea8 editors/CodeFileEditor.py --- a/editors/CodeFileEditor.py Sat Aug 19 17:17:54 2017 +0300 +++ b/editors/CodeFileEditor.py Sat Aug 19 18:12:20 2017 +0300 @@ -196,7 +196,7 @@ def OnDoDrop(self, event): try: values = eval(event.GetDragText()) - except: + except Exception: values = event.GetDragText() if isinstance(values, tuple): message = None diff -r 6cf16e5bfbf9 -r c52d1460cea8 editors/TextViewer.py --- a/editors/TextViewer.py Sat Aug 19 17:17:54 2017 +0300 +++ b/editors/TextViewer.py Sat Aug 19 18:12:20 2017 +0300 @@ -247,7 +247,7 @@ def OnDoDrop(self, event): try: values = eval(event.GetDragText()) - except: + except Exception: values = event.GetDragText() if isinstance(values, tuple): message = None diff -r 6cf16e5bfbf9 -r c52d1460cea8 editors/Viewer.py --- a/editors/Viewer.py Sat Aug 19 17:17:54 2017 +0300 +++ b/editors/Viewer.py Sat Aug 19 18:12:20 2017 +0300 @@ -268,7 +268,7 @@ message = None try: values = eval(data) - except: + except Exception: message = _("Invalid value \"%s\" for viewer block") % data values = None if not isinstance(values, TupleType): diff -r 6cf16e5bfbf9 -r c52d1460cea8 plcopen/plcopen.py --- a/plcopen/plcopen.py Sat Aug 19 17:17:54 2017 +0300 +++ b/plcopen/plcopen.py Sat Aug 19 18:12:20 2017 +0300 @@ -2557,7 +2557,7 @@ for element in self.value: try: repetition = int(element.getrepetitionValue()) - except: + except Exception: repetition = 1 if repetition > 1: value = element.getvalue() diff -r 6cf16e5bfbf9 -r c52d1460cea8 runtime/PLCObject.py --- a/runtime/PLCObject.py Sat Aug 19 17:17:54 2017 +0300 +++ b/runtime/PLCObject.py Sat Aug 19 18:12:20 2017 +0300 @@ -225,7 +225,7 @@ self.PythonRuntimeInit() return True - except: + except Exception: self._loading_error = traceback.format_exc() PLCprint(self._loading_error) return False @@ -317,7 +317,7 @@ method = self.python_runtime_vars.get("_%s_%s" % (name, methodname), None) if method is not None: self.python_runtime_vars["_runtime_%s" % methodname].append(method) - except: + except Exception: self.LogMessage(0, traceback.format_exc()) raise @@ -423,9 +423,9 @@ for filename in file(extra_files_log, "r").readlines() + [extra_files_log]: try: os.remove(os.path.join(self.workingdir, filename.strip())) - except: + except Exception: pass - except: + except Exception: pass try: @@ -445,7 +445,7 @@ # Store new PLC filename self.CurrentPLCFilename = NewFileName - except: + except Exception: self.PLCStatus = "Broken" self.StatusChange() PLCprint(traceback.format_exc()) @@ -465,7 +465,7 @@ try: last_md5 = open(self._GetMD5FileName(), "r").read() return last_md5 == MD5 - except: + except Exception: pass return False @@ -556,7 +556,7 @@ def RemoteExec(self, script, *kwargs): try: exec script in kwargs - except: + except Exception: e_type, e_value, e_traceback = sys.exc_info() line_no = traceback.tb_lineno(get_last_traceback(e_traceback)) return (-1, "RemoteExec script failed!\n\nLine %d: %s\n\t%s" % diff -r 6cf16e5bfbf9 -r c52d1460cea8 svgui/pyjs/build.py --- a/svgui/pyjs/build.py Sat Aug 19 17:17:54 2017 +0300 +++ b/svgui/pyjs/build.py Sat Aug 19 18:12:20 2017 +0300 @@ -11,7 +11,7 @@ try: # Python 2.5 and above from hashlib import md5 -except: +except Exception: import md5 import re @@ -77,7 +77,7 @@ names = os.listdir(src) try: os.mkdir(dst) - except: + except Exception: pass errors = [] @@ -203,7 +203,7 @@ os.path.getmtime(html_output_filename): try: shutil.copy(html_input_filename, html_output_filename) - except: + except Exception: print >>sys.stderr, "Warning: Missing module HTML file %s" % html_input_filename print "Copying: %(html_input_filename)s" % locals() diff -r 6cf16e5bfbf9 -r c52d1460cea8 svgui/pyjs/jsonrpc/jsonrpc.py --- a/svgui/pyjs/jsonrpc/jsonrpc.py Sat Aug 19 17:17:54 2017 +0300 +++ b/svgui/pyjs/jsonrpc/jsonrpc.py Sat Aug 19 18:12:20 2017 +0300 @@ -34,7 +34,7 @@ except BaseException: etype, eval, etb = sys.exc_info() return self.error(id, 100, '%s: %s' % (etype.__name__, eval)) - except: + except Exception: etype, eval, etb = sys.exc_info() return self.error(id, 100, 'Exception %s: %s' % (etype, eval)) else: diff -r 6cf16e5bfbf9 -r c52d1460cea8 util/ProcessLogger.py --- a/util/ProcessLogger.py Sat Aug 19 17:17:54 2017 +0300 +++ b/util/ProcessLogger.py Sat Aug 19 18:12:20 2017 +0300 @@ -66,7 +66,7 @@ if self.endcallback: try: err = self.Proc.wait() - except: + except Exception: err = self.retval self.finished = True self.endcallback(self.Proc.pid, err) @@ -205,7 +205,7 @@ sig = SIGKILL try: os.kill(self.Proc.pid, sig) - except: + except Exception: pass self.outt.join() self.errt.join() diff -r 6cf16e5bfbf9 -r c52d1460cea8 util/Zeroconf.py --- a/util/Zeroconf.py Sat Aug 19 17:17:54 2017 +0300 +++ b/util/Zeroconf.py Sat Aug 19 18:12:20 2017 +0300 @@ -241,14 +241,14 @@ """Class accessor""" try: return _CLASSES[clazz] - except: + except Exception: return "?(%s)" % (clazz) def getType(self, type): """Type accessor""" try: return _TYPES[type] - except: + except Exception: return "?(%s)" % (type) def toString(self, hdr, other): @@ -366,7 +366,7 @@ """String representation""" try: return socket.inet_ntoa(self.address) - except: + except Exception: return self.address @@ -799,7 +799,7 @@ """Adds an entry""" try: list = self.cache[entry.key] - except: + except Exception: list = self.cache[entry.key] = [] list.append(entry) @@ -808,7 +808,7 @@ try: list = self.cache[entry.key] list.remove(entry) - except: + except Exception: pass def get(self, entry): @@ -817,7 +817,7 @@ try: list = self.cache[entry.key] return list[list.index(entry)] - except: + except Exception: return None def getByDetails(self, name, type, clazz): @@ -830,7 +830,7 @@ """Returns a list of entries whose key matches the name.""" try: return self.cache[name] - except: + except Exception: return [] def entries(self): @@ -838,7 +838,7 @@ def add(x, y): return x+y try: return reduce(add, self.cache.values()) - except: + except Exception: return [] @@ -878,10 +878,10 @@ for socket in rr: try: self.readers[socket].handle_read() - except: + except Exception: # Ignore errors that occur on shutdown pass - except: + except Exception: pass def getReaders(self): @@ -1000,7 +1000,7 @@ del(self.services[record.alias.lower()]) self.list.append(callback) return - except: + except Exception: if not expired: def callback(x): return self.listener.addService(x, self.type, record.alias) @@ -1130,7 +1130,7 @@ result[key] = value self.properties = result - except: + except Exception: traceback.print_exc() self.properties = None @@ -1263,7 +1263,7 @@ try: self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1) - except: + except Exception: # SO_REUSEADDR should be equivalent to SO_REUSEPORT for # multicast UDP sockets (p 731, "TCP/IP Illustrated, # Volume 2"), but some BSD-derived systems require @@ -1278,7 +1278,7 @@ self.socket.setsockopt(socket.SOL_IP, socket.IP_MULTICAST_LOOP, 1) try: self.socket.bind(self.group) - except: + except Exception: # Some versions of linux raise an exception even though # the SO_REUSE* options have been set, so ignore it # @@ -1375,7 +1375,7 @@ """Unregister a service.""" try: del(self.services[info.name.lower()]) - except: + except Exception: pass now = currentTimeMillis() nextTime = now @@ -1460,7 +1460,7 @@ try: self.listeners.remove(listener) self.notifyAll() - except: + except Exception: pass def updateRecord(self, now, rec): @@ -1529,7 +1529,7 @@ out.addAnswer(msg, DNSText(question.name, _TYPE_TXT, _CLASS_IN | _CLASS_UNIQUE, _DNS_TTL, service.text)) if question.type == _TYPE_SRV: out.addAdditionalAnswer(DNSAddress(service.server, _TYPE_A, _CLASS_IN | _CLASS_UNIQUE, _DNS_TTL, service.address)) - except: + except Exception: traceback.print_exc() if out is not None and out.answers: @@ -1542,7 +1542,7 @@ #temp = DNSIncoming(out.packet()) try: bytes_sent = self.socket.sendto(out.packet(), 0, (addr, port)) - except: + except Exception: # Ignore this, it may be a temporary loss of network connection pass diff -r 6cf16e5bfbf9 -r c52d1460cea8 version.py --- a/version.py Sat Aug 19 17:17:54 2017 +0300 +++ b/version.py Sat Aug 19 18:12:20 2017 +0300 @@ -54,7 +54,7 @@ rev = pipe.communicate()[0] if pipe.returncode != 0: rev = None - except: + except Exception: pass # if this is not mercurial repository @@ -63,7 +63,7 @@ try: f = open(os.path.join(app_dir, "revision")) rev = f.readline() - except: + except Exception: pass return rev diff -r 6cf16e5bfbf9 -r c52d1460cea8 xmlclass/xmlclass.py --- a/xmlclass/xmlclass.py Sat Aug 19 17:17:54 2017 +0300 +++ b/xmlclass/xmlclass.py Sat Aug 19 18:12:20 2017 +0300 @@ -191,7 +191,7 @@ raise ValueError("\"%s\" isn't a valid hexadecimal integer!" % value) try: return int(value, 16) - except: + except Exception: raise ValueError("\"%s\" isn't a valid hexadecimal integer!" % value) @@ -221,7 +221,7 @@ try: # TODO: permit to write value like 1E2 value = int(value) - except: + except Exception: raise ValueError("\"%s\" isn't a valid integer!" % value) if minInclusive is not None and value < minInclusive: raise ValueError("\"%d\" isn't greater or equal to %d!" % @@ -260,7 +260,7 @@ return value try: return float(value) - except: + except Exception: raise ValueError("\"%s\" isn't a valid %s!" % (value, type)) return GetFloat @@ -410,7 +410,7 @@ raise ValueError("Member limit can't be defined to \"unbounded\"!") try: limit = int(value) - except: + except Exception: raise ValueError("\"%s\" isn't a valid value for this member limit!" % value) if limit < 0: raise ValueError("Member limit can't be negative!") diff -r 6cf16e5bfbf9 -r c52d1460cea8 xmlclass/xsdschema.py --- a/xmlclass/xsdschema.py Sat Aug 19 17:17:54 2017 +0300 +++ b/xmlclass/xsdschema.py Sat Aug 19 18:12:20 2017 +0300 @@ -215,7 +215,7 @@ raise ValueError("\"length\" and \"maxLength\" facets can't be defined at the same time!") try: value = int(value) - except: + except Exception: raise ValueError("\"length\" must be an integer!") if value < 0: raise ValueError("\"length\" can't be negative!") @@ -226,7 +226,7 @@ raise ValueError("\"length\" and \"minLength\" facets can't be defined at the same time!") try: value = int(value) - except: + except Exception: raise ValueError("\"minLength\" must be an integer!") if value < 0: raise ValueError("\"minLength\" can't be negative!") @@ -239,7 +239,7 @@ raise ValueError("\"length\" and \"maxLength\" facets can't be defined at the same time!") try: value = int(value) - except: + except Exception: raise ValueError("\"maxLength\" must be an integer!") if value < 0: raise ValueError("\"maxLength\" can't be negative!") @@ -464,7 +464,7 @@ for infos in membertypesinfos: try: return infos["extract"](attr, False) - except: + except Exception: pass raise ValueError("\"%s\" isn't valid for type defined for union!")