mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 13:19:24 +01:00
Add registry.TemplatedString for config variables which use string.Template
This commit is contained in:
parent
25fc2de643
commit
035a9f2459
@ -1,5 +1,6 @@
|
|||||||
###
|
###
|
||||||
# Copyright (c) 2004-2005, Jeremiah Fincher
|
# Copyright (c) 2004-2005, Jeremiah Fincher
|
||||||
|
# Copyright (c) 2009, James Vega
|
||||||
# All rights reserved.
|
# All rights reserved.
|
||||||
#
|
#
|
||||||
# Redistribution and use in source and binary forms, with or without
|
# Redistribution and use in source and binary forms, with or without
|
||||||
@ -550,13 +551,12 @@ class Regexp(Value):
|
|||||||
self.error(e)
|
self.error(e)
|
||||||
|
|
||||||
def setValue(self, v, sr=None):
|
def setValue(self, v, sr=None):
|
||||||
parent = super(Regexp, self)
|
|
||||||
if v is None:
|
if v is None:
|
||||||
self.sr = ''
|
self.sr = ''
|
||||||
parent.setValue(None)
|
self.__parent.setValue(None)
|
||||||
elif sr is not None:
|
elif sr is not None:
|
||||||
self.sr = sr
|
self.sr = sr
|
||||||
parent.setValue(v)
|
self.__parent.setValue(v)
|
||||||
else:
|
else:
|
||||||
raise InvalidRegistryValue, \
|
raise InvalidRegistryValue, \
|
||||||
'Can\'t setValue a regexp, there would be an inconsistency '\
|
'Can\'t setValue a regexp, there would be an inconsistency '\
|
||||||
@ -619,6 +619,20 @@ class CommaSeparatedListOfStrings(SeparatedListOf):
|
|||||||
return re.split(r'\s*,\s*', s)
|
return re.split(r'\s*,\s*', s)
|
||||||
joiner = ', '.join
|
joiner = ', '.join
|
||||||
|
|
||||||
|
class TemplatedString(String):
|
||||||
|
requiredTemplates = []
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
assert self.requiredTemplates, \
|
||||||
|
'There must be some templates. This is a bug.'
|
||||||
|
self.__parent = super(String, self)
|
||||||
|
self.__parent.__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
def setValue(self, v):
|
||||||
|
def hasTemplate(s):
|
||||||
|
return re.search(r'\$%s\b|\${%s}' % (s, s), v) is not None
|
||||||
|
if utils.iter.all(hasTemplate, self.requiredTemplates):
|
||||||
|
self.__parent.setValue(v)
|
||||||
|
else:
|
||||||
|
self.error()
|
||||||
|
|
||||||
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user