mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-02 17:29:22 +01:00
Ah, a better way to do default normalization.
This commit is contained in:
parent
9eee85dc63
commit
3538dee7c9
@ -424,9 +424,6 @@ length of time a driver should block waiting for input."""))
|
|||||||
|
|
||||||
class ValidDriverModule(registry.OnlySomeStrings):
|
class ValidDriverModule(registry.OnlySomeStrings):
|
||||||
validStrings = ('socketDrivers', 'twistedDrivers', 'asyncoreDrivers')
|
validStrings = ('socketDrivers', 'twistedDrivers', 'asyncoreDrivers')
|
||||||
def normalize(self, s):
|
|
||||||
# We can't be case insensitive here. At least not without work.
|
|
||||||
return s
|
|
||||||
|
|
||||||
supybot.drivers.register('module', ValidDriverModule('socketDrivers', """
|
supybot.drivers.register('module', ValidDriverModule('socketDrivers', """
|
||||||
Determines what driver module the bot will use. socketDrivers, a simple
|
Determines what driver module the bot will use. socketDrivers, a simple
|
||||||
|
@ -297,13 +297,21 @@ class String(Value):
|
|||||||
raise InvalidRegistryValue, '%r is not a string.' % s
|
raise InvalidRegistryValue, '%r is not a string.' % s
|
||||||
|
|
||||||
class OnlySomeStrings(String):
|
class OnlySomeStrings(String):
|
||||||
normalize = staticmethod(str.lower)
|
|
||||||
validStrings = ()
|
validStrings = ()
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
assert self.validStrings, 'There must be some valid strings. ' \
|
assert self.validStrings, 'There must be some valid strings. ' \
|
||||||
'This is a bug.'
|
'This is a bug.'
|
||||||
String.__init__(self, *args, **kwargs)
|
String.__init__(self, *args, **kwargs)
|
||||||
|
|
||||||
|
def normalize(self, s):
|
||||||
|
lowered = s.lower()
|
||||||
|
L = list(map(str.lower, self.validStrings))
|
||||||
|
try:
|
||||||
|
i = L.index(lowered)
|
||||||
|
except ValueError:
|
||||||
|
return s # This is handled in setValue.
|
||||||
|
return self.validStrings[i]
|
||||||
|
|
||||||
def setValue(self, s):
|
def setValue(self, s):
|
||||||
s = self.normalize(s)
|
s = self.normalize(s)
|
||||||
if s in self.validStrings:
|
if s in self.validStrings:
|
||||||
|
Loading…
Reference in New Issue
Block a user