From 862e22e548cdb23ffa11a7e774fde6e9193a960f Mon Sep 17 00:00:00 2001 From: rdb Date: Mon, 19 May 2014 17:33:36 +0000 Subject: [PATCH] remove Python-2-isms from DirectGui and FSM to make them work with Python 3 --- direct/src/fsm/FSM.py | 7 ++-- direct/src/gui/DirectGuiBase.py | 66 +++++++++++---------------------- 2 files changed, 25 insertions(+), 48 deletions(-) diff --git a/direct/src/fsm/FSM.py b/direct/src/fsm/FSM.py index 593581f758..db85ad4b00 100644 --- a/direct/src/fsm/FSM.py +++ b/direct/src/fsm/FSM.py @@ -10,7 +10,6 @@ from direct.directnotify import DirectNotifyGlobal from direct.showbase import PythonUtil from direct.stdpy.threading import RLock import types -import string class FSMException(Exception): pass @@ -364,7 +363,7 @@ class FSM(DirectObject): # If self.defaultTransitions is None, it means to accept # all requests whose name begins with a capital letter. # These are direct requests to a particular state. - if request[0] in string.uppercase: + if request[0].isupper(): return (request,) + args else: # If self.defaultTransitions is not None, it is a map of @@ -381,7 +380,7 @@ class FSM(DirectObject): # to request a direct state transition (capital letter # request) not listed in defaultTransitions and not # handled by an earlier filter. - if request[0] in string.uppercase: + if request[0].isupper(): raise RequestDenied, "%s (from state: %s)" % (request, self.state) # In either case, we quietly ignore unhandled command @@ -392,7 +391,7 @@ class FSM(DirectObject): def filterOff(self, request, args): """From the off state, we can always go directly to any other state.""" - if request[0] in string.uppercase: + if request[0].isupper(): return (request,) + args return self.defaultFilter(request, args) diff --git a/direct/src/gui/DirectGuiBase.py b/direct/src/gui/DirectGuiBase.py index 3d9d66292d..2d8c8241e7 100644 --- a/direct/src/gui/DirectGuiBase.py +++ b/direct/src/gui/DirectGuiBase.py @@ -14,7 +14,7 @@ from direct.task import Task from direct.showbase import ShowBase from direct.showbase.PythonUtil import recordCreationStackStr from pandac.PandaModules import PStatCollector -import string, types +import types guiObjectCollector = PStatCollector("Client::GuiObjects") @@ -192,9 +192,9 @@ class DirectGuiBase(DirectObject.DirectObject): # optimisations: optionInfo = self._optionInfo - optionInfo_has_key = optionInfo.has_key + optionInfo_has_key = optionInfo.__contains__ keywords = self._constructorKeywords - keywords_has_key = keywords.has_key + keywords_has_key = keywords.__contains__ FUNCTION = DGG._OPT_FUNCTION for name, default, function in optionDefs: @@ -251,7 +251,7 @@ class DirectGuiBase(DirectObject.DirectObject): # This keyword argument has not been used. If it # does not refer to a dynamic group, mark it as # unused. - index = string.find(name, '_') + index = name.find('_') if index < 0 or name[:index] not in self._dynamicGroups: unusedOptions.append(name) self._constructorKeywords = {} @@ -260,7 +260,7 @@ class DirectGuiBase(DirectObject.DirectObject): text = 'Unknown option "' else: text = 'Unknown options "' - raise KeyError, text + string.join(unusedOptions, ', ') + \ + raise KeyError, text + ', '.join(unusedOptions) + \ '" for ' + myClass.__name__ # Can now call post init func self.postInitialiseFunc() @@ -326,11 +326,11 @@ class DirectGuiBase(DirectObject.DirectObject): # optimizations: optionInfo = self._optionInfo - optionInfo_has_key = optionInfo.has_key + optionInfo_has_key = optionInfo.__contains__ componentInfo = self.__componentInfo - componentInfo_has_key = componentInfo.has_key + componentInfo_has_key = componentInfo.__contains__ componentAliases = self.__componentAliases - componentAliases_has_key = componentAliases.has_key + componentAliases_has_key = componentAliases.__contains__ VALUE = DGG._OPT_VALUE FUNCTION = DGG._OPT_FUNCTION @@ -345,7 +345,7 @@ class DirectGuiBase(DirectObject.DirectObject): # component and whose values are a dictionary of options and # values for the component. indirectOptions = {} - indirectOptions_has_key = indirectOptions.has_key + indirectOptions_has_key = indirectOptions.__contains__ for option, value in kw.items(): if optionInfo_has_key(option): @@ -361,7 +361,7 @@ class DirectGuiBase(DirectObject.DirectObject): optionInfo[option][VALUE] = value directOptions.append(option) else: - index = string.find(option, '_') + index = option.find('_') if index >= 0: # This option may be of the form _