205: Continued work on Unicode.__init__() and corresponding unit tests

This commit is contained in:
Jason Gerard DeRose
2008-08-27 22:26:35 +00:00
parent e6cecfdcf2
commit 2984041d00
2 changed files with 53 additions and 8 deletions

View File

@@ -83,11 +83,15 @@ class Int(Type):
class Unicode(Type):
def __init__(self, length=None,min_length=None, max_length=None, pattern=None):
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:
raise ValueError(
'min_length must zero or greater, got: %r' % min_length
raise ValueError('min_length must be >= 0, got: %r' % min_length)
if max_length is not None and max_length < 1:
raise ValueError('max_length must be >= 1, got: %r' % max_length)
if not (pattern is None or isinstance(pattern, basestring)):
raise TypeError(
'pattern must be a basestring or None, got: %r' % pattern
)
self.min_length = min_length
self.max_length = max_length