New Param: decided on calling signature for rules; added unit tests for Bytes._rule_minlength, _rule_maxlength, and _rule_length

This commit is contained in:
Jason Gerard DeRose
2009-01-05 02:20:09 -07:00
parent c121d0064b
commit 6d6c0d81dd
3 changed files with 119 additions and 8 deletions

View File

@@ -500,30 +500,36 @@ class Bytes(Param):
self.nice, self.minlength)
)
def _rule_minlength(self, value):
def _rule_minlength(self, _, name, value):
"""
Check minlength constraint.
"""
assert type(value) is str
if len(value) < self.minlength:
return 'Must be at least %(minlength)d bytes long.' % dict(
return _('%(name)s must be at least %(minlength)d bytes') % dict(
name=name,
minlength=self.minlength,
)
def _rule_maxlength(self, value):
def _rule_maxlength(self, _, name, value):
"""
Check maxlength constraint.
"""
assert type(value) is str
if len(value) > self.maxlength:
return 'Can be at most %(maxlength)d bytes long.' % dict(
return _('%(name)s can be at most %(maxlength)d bytes') % dict(
name=name,
maxlength=self.maxlength,
)
def _rule_length(self, value):
def _rule_length(self, _, name, value):
"""
Check length constraint.
"""
assert type(value) is str
if len(value) != self.length:
return 'Must be exactly %(length)d bytes long.' % dict(
return _('%(name)s must be exactly %(length)d bytes') % dict(
name=name,
length=self.length,
)