mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-26 04:39:26 +01:00
registry: forbid direct access to Regexp.setValue.
This is not a regression; this was already forbidden before
23417b0675
, and this commit was not
tagged/released yet at the moment I'm writing this one.
This commit is contained in:
parent
ac94c5291e
commit
f4d6bd11be
@ -785,6 +785,17 @@ class Regexp(Value):
|
|||||||
else:
|
else:
|
||||||
super().set(v)
|
super().set(v)
|
||||||
|
|
||||||
|
def setValue(self, v):
|
||||||
|
"""Don't call this function directly from plugins, it is subject
|
||||||
|
to change without notice."""
|
||||||
|
if v is not None and (not isinstance(v, tuple) or len(v) != 2):
|
||||||
|
raise InvalidRegistryValue(
|
||||||
|
'Can\'t setValue a regexp, there would be an inconsistency '
|
||||||
|
'between the regexp and the recorded string value. '
|
||||||
|
'Use .set() instead.')
|
||||||
|
|
||||||
|
super().setValue(v)
|
||||||
|
|
||||||
def __call__(self):
|
def __call__(self):
|
||||||
if self.value is None:
|
if self.value is None:
|
||||||
return None
|
return None
|
||||||
|
@ -183,6 +183,13 @@ class ValuesTestCase(SupyTestCase):
|
|||||||
v.set('')
|
v.set('')
|
||||||
self.assertEqual(v(), None)
|
self.assertEqual(v(), None)
|
||||||
|
|
||||||
|
def testRegexpSetValue(self):
|
||||||
|
v = registry.Regexp(None, 'help')
|
||||||
|
self.assertRaises(registry.InvalidRegistryValue,
|
||||||
|
v.setValue, r'foo')
|
||||||
|
self.assertRaises(registry.InvalidRegistryValue,
|
||||||
|
v.setValue, re.compile(r'foo'))
|
||||||
|
|
||||||
def testRegexpDefaultString(self):
|
def testRegexpDefaultString(self):
|
||||||
v = registry.Regexp('m/foo/', 'help')
|
v = registry.Regexp('m/foo/', 'help')
|
||||||
self.assertEqual(v(), re.compile('foo'))
|
self.assertEqual(v(), re.compile('foo'))
|
||||||
|
Loading…
Reference in New Issue
Block a user