From bcdbf40c29003f02377685c3ee1ac7f5ad607882 Mon Sep 17 00:00:00 2001 From: lbessard Date: Thu, 28 Aug 2008 12:24:10 +0000 Subject: [PATCH 1/1] Some instance type test improved --- objdictgen/gen_cfile.py | 2 +- objdictgen/networkedit.py | 8 ++++---- objdictgen/nodemanager.py | 4 ++-- objdictgen/objdictedit.py | 20 ++++++++++---------- objdictgen/objdictgen.py | 4 ++-- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/objdictgen/gen_cfile.py b/objdictgen/gen_cfile.py index c821783..48ef711 100644 --- a/objdictgen/gen_cfile.py +++ b/objdictgen/gen_cfile.py @@ -183,7 +183,7 @@ def GenerateFileContent(Node, headerfilepath, pointers_dict = {}): strIndex += "\n/* index 0x%(index)04X : %(EntryName)s. */\n"%texts # Entry type is VAR - if type(values) != ListType: + if isinstance(values, ListType): subentry_infos = Node.GetSubentryInfos(index, 0) typename = Node.GetTypeName(subentry_infos["type"]) typeinfos = GetValidTypeInfos(typename, [values]) diff --git a/objdictgen/networkedit.py b/objdictgen/networkedit.py index 51ae601..fccfc27 100644 --- a/objdictgen/networkedit.py +++ b/objdictgen/networkedit.py @@ -27,7 +27,7 @@ import wx.grid from types import * import os, re, platform, sys, time, traceback, getopt -__version__ = "$Revision: 1.24 $" +__version__ = "$Revision: 1.25 $" from nodelist import * from nodemanager import * @@ -705,13 +705,13 @@ class networkedit(wx.Frame): find_index = True index, subIndex = result result = OpenPDFDocIndex(index, ScriptDirectory) - if type(result) == StringType: + if isinstance(result, (StringType, UnicodeType)): message = wx.MessageDialog(self, result, "ERROR", wx.OK|wx.ICON_ERROR) message.ShowModal() message.Destroy() if not find_index: result = OpenPDFDocIndex(None, ScriptDirectory) - if type(result) == StringType: + if isinstance(result, (StringType, UnicodeType)): message = wx.MessageDialog(self, result, "ERROR", wx.OK|wx.ICON_ERROR) message.ShowModal() message.Destroy() @@ -817,7 +817,7 @@ class networkedit(wx.Frame): if dialog.ShowModal() == wx.ID_OK: index, name, struct, number = dialog.GetValues() result = self.Manager.AddMapVariableToCurrent(index, name, struct, number) - if type(result) != StringType: + if not isinstance(result, (StringType, UnicodeType)): self.RefreshBufferState() self.RefreshCurrentIndexList() else: diff --git a/objdictgen/nodemanager.py b/objdictgen/nodemanager.py index 2b29882..e48c145 100755 --- a/objdictgen/nodemanager.py +++ b/objdictgen/nodemanager.py @@ -1027,7 +1027,7 @@ class NodeManager: editors = [] values = node.GetEntry(index, compute = False) params = node.GetParamsEntry(index) - if type(values) == ListType: + if isinstance(values, ListType): for i, value in enumerate(values): data.append({"value" : value}) data[-1].update(params[i]) @@ -1042,7 +1042,7 @@ class NodeManager: dic["access"] = AccessType[infos["access"]] dic["save"] = OptionType[dic["save"]] editor = {"subindex" : None, "save" : "option", "callback" : "option", "comment" : "string"} - if type(values) == ListType and i == 0: + if isinstance(values, ListType) and i == 0: editor["name"] = None editor["type"] = None if 0x1600 <= index <= 0x17FF or 0x1A00 <= index <= 0x1C00: diff --git a/objdictgen/objdictedit.py b/objdictgen/objdictedit.py index f0e3b9e..60cded3 100755 --- a/objdictgen/objdictedit.py +++ b/objdictgen/objdictedit.py @@ -26,7 +26,7 @@ import wx from types import * import os, re, platform, sys, time, traceback, getopt -__version__ = "$Revision: 1.44 $" +__version__ = "$Revision: 1.45 $" from node import OD_Subindex, OD_MultipleSubindexes, OD_IdenticalSubindexes, OD_IdenticalIndexes @@ -298,7 +298,7 @@ class objdictedit(wx.Frame): self.Manager = NodeManager() for filepath in filesOpen: result = self.Manager.OpenFileInCurrent(filepath) - if type(result) == IntType: + if isinstance(result, (IntType, LongType)): new_editingpanel = EditingPanel(self.FileOpened, self, self.Manager) new_editingpanel.SetIndex(result) self.FileOpened.AddPage(new_editingpanel, "") @@ -389,13 +389,13 @@ class objdictedit(wx.Frame): find_index = True index, subIndex = result result = OpenPDFDocIndex(index, ScriptDirectory) - if type(result) == StringType: + if isinstance(result, (StringType, UnicodeType)): message = wx.MessageDialog(self, result, "ERROR", wx.OK|wx.ICON_ERROR) message.ShowModal() message.Destroy() if not find_index: result = OpenPDFDocIndex(None, ScriptDirectory) - if type(result) == StringType: + if isinstance(result, (StringType, UnicodeType)): message = wx.MessageDialog(self, result, "ERROR", wx.OK|wx.ICON_ERROR) message.ShowModal() message.Destroy() @@ -598,7 +598,7 @@ class objdictedit(wx.Frame): NMT = dialog.GetNMTManagement() options = dialog.GetOptions() result = self.Manager.CreateNewNode(name, id, nodetype, description, profile, filepath, NMT, options) - if type(result) == IntType: + if isinstance(result, (IntType, LongType)): new_editingpanel = EditingPanel(self.FileOpened, self, self.Manager) new_editingpanel.SetIndex(result) self.FileOpened.AddPage(new_editingpanel, "") @@ -627,7 +627,7 @@ class objdictedit(wx.Frame): filepath = dialog.GetPath() if os.path.isfile(filepath): result = self.Manager.OpenFileInCurrent(filepath) - if type(result) == IntType: + if isinstance(result, (IntType, LongType)): new_editingpanel = EditingPanel(self.FileOpened, self, self.Manager) new_editingpanel.SetIndex(result) self.FileOpened.AddPage(new_editingpanel, "") @@ -663,7 +663,7 @@ class objdictedit(wx.Frame): result = self.Manager.SaveCurrentInFile() if not result: self.SaveAs() - elif type(result) != StringType: + elif not isinstance(result, (StringType, UnicodeType)): self.RefreshBufferState() else: message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR) @@ -681,7 +681,7 @@ class objdictedit(wx.Frame): filepath = dialog.GetPath() if os.path.isdir(os.path.dirname(filepath)): result = self.Manager.SaveCurrentInFile(filepath) - if type(result) != StringType: + if not isinstance(result, (StringType, UnicodeType)): self.RefreshBufferState() else: message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR) @@ -726,7 +726,7 @@ class objdictedit(wx.Frame): filepath = dialog.GetPath() if os.path.isfile(filepath): result = self.Manager.ImportCurrentFromEDSFile(filepath) - if type(result) == IntType: + if isinstance(result, (IntType, LongType)): new_editingpanel = EditingPanel(self.FileOpened, self, self.Manager) new_editingpanel.SetIndex(result) self.FileOpened.AddPage(new_editingpanel, "") @@ -881,7 +881,7 @@ class objdictedit(wx.Frame): if dialog.ShowModal() == wx.ID_OK: index, name, struct, number = dialog.GetValues() result = self.Manager.AddMapVariableToCurrent(index, name, struct, number) - if type(result) != StringType: + if not isinstance(result, (StringType, UnicodeType)): self.RefreshBufferState() self.RefreshCurrentIndexList() else: diff --git a/objdictgen/objdictgen.py b/objdictgen/objdictgen.py index 7b7afbe..84ac9ab 100644 --- a/objdictgen/objdictgen.py +++ b/objdictgen/objdictgen.py @@ -57,7 +57,7 @@ if __name__ == '__main__': if os.path.isfile(fileIn): print "Parsing input file" result = manager.OpenFileInCurrent(fileIn) - if type(result) != UnicodeType: + if not isinstance(result, (StringType, UnicodeType)): Node = result else: print result @@ -67,7 +67,7 @@ if __name__ == '__main__': sys.exit(-1) print "Writing output file" result = manager.ExportCurrentToCFile(fileOut) - if type(result) == UnicodeType: + if isinstance(result, (UnicodeType, StringType)): print result sys.exit(-1) print "All done" -- 2.39.2