summaryrefslogtreecommitdiffstats
path: root/ipalib/ipa_types.py
diff options
context:
space:
mode:
authorJason Gerard DeRose <jderose@redhat.com>2008-08-28 02:02:03 +0000
committerJason Gerard DeRose <jderose@redhat.com>2008-08-28 02:02:03 +0000
commit039b9a2a9b8e4a5a81d338b642869cefa6a6d8e4 (patch)
tree466e7349087892020d00522c6b6119f6bd9b6fdc /ipalib/ipa_types.py
parent2b01bdc1121bf7dee1296bc3b8bdf8443d54d202 (diff)
downloadfreeipa-039b9a2a9b8e4a5a81d338b642869cefa6a6d8e4.tar.gz
freeipa-039b9a2a9b8e4a5a81d338b642869cefa6a6d8e4.tar.xz
freeipa-039b9a2a9b8e4a5a81d338b642869cefa6a6d8e4.zip
210: Type.__init__() now takes the type as the first argument, does not use subclass attribute; updated Int, Unicode, and their unit tests accordingly
Diffstat (limited to 'ipalib/ipa_types.py')
-rw-r--r--ipalib/ipa_types.py17
1 files changed, 10 insertions, 7 deletions
diff --git a/ipalib/ipa_types.py b/ipalib/ipa_types.py
index 5bcea5344..8d30aaa48 100644
--- a/ipalib/ipa_types.py
+++ b/ipalib/ipa_types.py
@@ -51,7 +51,14 @@ class Type(ReadOnly):
Base class for all IPA types.
"""
- type = None # Override in base class
+ def __init__(self, type_):
+ allowed = (bool, int, float, unicode)
+ if type_ not in allowed:
+ raise ValueError(
+ 'type_ must be in %r, got %r' % (type_, allowed)
+ )
+ self.type = type_
+ lock(self)
def __get_name(self):
"""
@@ -75,13 +82,11 @@ class Type(ReadOnly):
class Int(Type):
- type = int
-
def __init__(self, min_value=None, max_value=None):
check_min_max(min_value, max_value, 'min_value', 'max_value')
self.min_value = min_value
self.max_value = max_value
- lock(self)
+ super(Int, self).__init__(int)
def validate(self, value):
if type(value) is not self.type:
@@ -93,8 +98,6 @@ class Int(Type):
class Unicode(Type):
- type = unicode
-
def __init__(self, min_length=None, max_length=None, pattern=None):
check_min_max(min_length, max_length, 'min_length', 'max_length')
if min_length is not None and min_length < 0:
@@ -112,7 +115,7 @@ class Unicode(Type):
self.regex = None
else:
self.regex = re.compile(pattern)
- lock(self)
+ super(Unicode, self).__init__(unicode)
def validate(self, value):
if type(value) is not self.type: