diff options
Diffstat (limited to 'ipalib')
-rw-r--r-- | ipalib/parameters.py | 12 | ||||
-rw-r--r-- | ipalib/plugins/group.py | 3 | ||||
-rw-r--r-- | ipalib/plugins/user.py | 3 |
3 files changed, 15 insertions, 3 deletions
diff --git a/ipalib/parameters.py b/ipalib/parameters.py index f97c4221..c86db758 100644 --- a/ipalib/parameters.py +++ b/ipalib/parameters.py @@ -1082,6 +1082,7 @@ class Data(Param): ('maxlength', int, None), ('length', int, None), ('pattern', (basestring,), None), + ('pattern_errmsg', (basestring,), None), ) def __init__(self, name, *rules, **kw): @@ -1123,9 +1124,12 @@ class Data(Param): """ assert type(value) is self.type if self.re.match(value) is None: - return _('must match pattern "%(pattern)s"') % dict( - pattern=self.pattern, - ) + if self.re_errmsg: + return self.re_errmsg % dict(pattern=self.pattern,) + else: + return _('must match pattern "%(pattern)s"') % dict( + pattern=self.pattern, + ) class Bytes(Data): @@ -1148,6 +1152,7 @@ class Bytes(Data): self.re = None else: self.re = re.compile(kw['pattern']) + self.re_errmsg = kw.get('pattern_errmsg', None) super(Bytes, self).__init__(name, *rules, **kw) def _rule_minlength(self, _, value): @@ -1201,6 +1206,7 @@ class Str(Data): self.re = None else: self.re = re.compile(kw['pattern'], re.UNICODE) + self.re_errmsg = kw.get('pattern_errmsg', None) super(Str, self).__init__(name, *rules, **kw) def _convert_scalar(self, value, index=None): diff --git a/ipalib/plugins/group.py b/ipalib/plugins/group.py index 2558c38a..4fd630d4 100644 --- a/ipalib/plugins/group.py +++ b/ipalib/plugins/group.py @@ -89,6 +89,9 @@ class group(LDAPObject): takes_params = ( Str('cn', + pattern='^[a-zA-Z0-9_.][a-zA-Z0-9_.-]{0,30}[a-zA-Z0-9_.$-]?$', + pattern_errmsg='may only include letters, numbers, _, -, . and $', + maxlength=33, cli_name='name', label=_('Group name'), primary_key=True, diff --git a/ipalib/plugins/user.py b/ipalib/plugins/user.py index de5ff2d2..f698aa70 100644 --- a/ipalib/plugins/user.py +++ b/ipalib/plugins/user.py @@ -72,6 +72,9 @@ class user(LDAPObject): takes_params = ( Str('uid', + pattern='^[a-zA-Z0-9_.][a-zA-Z0-9_.-]{0,30}[a-zA-Z0-9_.$-]?$', + pattern_errmsg='may only include letters, numbers, _, -, . and $', + maxlength=33, cli_name='login', label=_('User login'), primary_key=True, |