Minor adjustment to the __contains__ cache of cmdsets.
This commit is contained in:
parent
c0b03c2ee3
commit
de3d1f4a22
1 changed files with 3 additions and 6 deletions
|
|
@ -14,7 +14,6 @@ See CmdHandler for practical examples on how to apply cmdsets
|
||||||
together to create interesting in-game effects.
|
together to create interesting in-game effects.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import copy
|
|
||||||
from django.utils.translation import ugettext as _
|
from django.utils.translation import ugettext as _
|
||||||
from src.utils.utils import inherits_from, is_iter
|
from src.utils.utils import inherits_from, is_iter
|
||||||
__all__ = ("CmdSet",)
|
__all__ = ("CmdSet",)
|
||||||
|
|
@ -225,10 +224,8 @@ class CmdSet(object):
|
||||||
Returns True if this cmdset contains the given command (as defined
|
Returns True if this cmdset contains the given command (as defined
|
||||||
by command name and aliases). This allows for things like 'if cmd in cmdset'
|
by command name and aliases). This allows for things like 'if cmd in cmdset'
|
||||||
"""
|
"""
|
||||||
# optimization test
|
ret = self._contains_cache.get(othercmd)
|
||||||
try:
|
if ret == None:
|
||||||
return self._contains_cache[othercmd]
|
|
||||||
except KeyError:
|
|
||||||
ret = othercmd in self.commands
|
ret = othercmd in self.commands
|
||||||
self._contains_cache[othercmd] = ret
|
self._contains_cache[othercmd] = ret
|
||||||
return ret
|
return ret
|
||||||
|
|
@ -326,7 +323,7 @@ class CmdSet(object):
|
||||||
# an infinite loop (adding cmdset to itself somehow)
|
# an infinite loop (adding cmdset to itself somehow)
|
||||||
try:
|
try:
|
||||||
cmd = self._instantiate(cmd)
|
cmd = self._instantiate(cmd)
|
||||||
except RuntimeError, e:
|
except RuntimeError:
|
||||||
string = "Adding cmdset %(cmd)s to %(class)s lead to an infinite loop. When adding a cmdset to another, "
|
string = "Adding cmdset %(cmd)s to %(class)s lead to an infinite loop. When adding a cmdset to another, "
|
||||||
string += "make sure they are not themself cyclically added to the new cmdset somewhere in the chain."
|
string += "make sure they are not themself cyclically added to the new cmdset somewhere in the chain."
|
||||||
raise RuntimeError(_(string) % {"cmd":cmd, "class":self.__class__})
|
raise RuntimeError(_(string) % {"cmd":cmd, "class":self.__class__})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue