rename acceptable to choices

This commit is contained in:
Chris McDonough
2013-01-30 13:44:03 -05:00
parent 02f81f239f
commit ccbb3c4dff
2 changed files with 8 additions and 6 deletions

View File

@@ -360,19 +360,21 @@ class OneOf(object):
class ContainsOnly(object):
""" Validator which succeeds if the value passed to is a sequence and each
element in the sequence is also in the sequence passed as ``acceptable``
element in the sequence is also in the sequence passed as ``choices``.
This validator is useful when attached to a schemanode with, e.g. a
:class:`colander.Set` or another sequencetype.
"""
err_template = _(
'One or more of the choices you made was not acceptable'
)
def __init__(self, acceptable):
self.acceptable = set(acceptable)
def __init__(self, choices):
self.choices = choices
def __call__(self, node, value):
if not set(value).issubset(self.acceptable):
if not set(value).issubset(self.choices):
err = _(
self.err_template,
mapping = {'val':value, 'acceptable':self.acceptable}
mapping = {'val':value, 'choices':self.choices}
)
raise Invalid(node, err)

View File

@@ -428,7 +428,7 @@ class TestContainsOnly(unittest.TestCase):
def test_failure_with_custom_error_template(self):
validator = self._makeOne([1])
from colander import _
validator.err_template = _('${val}: ${acceptable}')
validator.err_template = _('${val}: ${choices}')
e = invalid_exc(validator, None, [2])
self.assertTrue('[2]' in e.msg.interpolate())