summaryrefslogtreecommitdiffstats
path: root/ipalib/parameters.py
diff options
context:
space:
mode:
authorRob Crittenden <rcritten@redhat.com>2010-12-06 15:09:03 -0500
committerRob Crittenden <rcritten@redhat.com>2010-12-07 16:37:42 -0500
commit6e2dd0fa5b79849c3dbd5f9b855e43b634e2a4b3 (patch)
tree3264b8ba10fdb44845ee4f257e851f2764f3a6cd /ipalib/parameters.py
parent78786a699586b12ec53c0a87703e0a44e9c7427e (diff)
downloadfreeipa-6e2dd0fa5b79849c3dbd5f9b855e43b634e2a4b3.tar.gz
freeipa-6e2dd0fa5b79849c3dbd5f9b855e43b634e2a4b3.tar.xz
freeipa-6e2dd0fa5b79849c3dbd5f9b855e43b634e2a4b3.zip
Add new parameter type IA5Str and use this to enforce the right charset.
ticket 496
Diffstat (limited to 'ipalib/parameters.py')
-rw-r--r--ipalib/parameters.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/ipalib/parameters.py b/ipalib/parameters.py
index cf4f3ba45..f3b13bdb1 100644
--- a/ipalib/parameters.py
+++ b/ipalib/parameters.py
@@ -1278,6 +1278,25 @@ class Str(Data):
)
+class IA5Str(Str):
+ """
+ An IA5String per RFC 4517
+ """
+
+ def __init__(self, name, *rules, **kw):
+ super(IA5Str, self).__init__(name, *rules, **kw)
+
+ def _convert_scalar(self, value, index=None):
+ if isinstance(value, basestring):
+ for i in xrange(len(value)):
+ if ord(value[i]) > 127:
+ raise ConversionError(name=self.name, index=index,
+ error=_('The character \'%(char)r\' is not allowed.') %
+ dict(char=value[i],)
+ )
+ return super(IA5Str, self)._convert_scalar(value, index)
+
+
class Password(Str):
"""
A parameter for passwords (stored in the ``unicode`` type).