mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-23 19:19:32 +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):
|
||||
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', """
|
||||
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
|
||||
|
||||
class OnlySomeStrings(String):
|
||||
normalize = staticmethod(str.lower)
|
||||
validStrings = ()
|
||||
def __init__(self, *args, **kwargs):
|
||||
assert self.validStrings, 'There must be some valid strings. ' \
|
||||
'This is a bug.'
|
||||
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):
|
||||
s = self.normalize(s)
|
||||
if s in self.validStrings:
|
||||
|
Loading…
Reference in New Issue
Block a user