diff options
author | kopertop <kopertop@604d75c7-a419-0410-a38f-bde1a0bd1dbf> | 2009-11-25 14:51:43 +0000 |
---|---|---|
committer | kopertop <kopertop@604d75c7-a419-0410-a38f-bde1a0bd1dbf> | 2009-11-25 14:51:43 +0000 |
commit | de70a62bef4c6672c49fa8e12b8408d2b5605ac8 (patch) | |
tree | 8a9094a58d083b73511583fa2e273e750095f906 | |
parent | 18ff75a04db1caf1f76121416feb3edef1da29ed (diff) | |
download | boto-de70a62bef4c6672c49fa8e12b8408d2b5605ac8.tar.gz |
set max_length on TextProperty
-rw-r--r-- | boto/sdb/db/property.py | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/boto/sdb/db/property.py b/boto/sdb/db/property.py index df1feb49..f39fe8f8 100644 --- a/boto/sdb/db/property.py +++ b/boto/sdb/db/property.py @@ -121,17 +121,20 @@ class StringProperty(Property): validator=validate_string, choices=None, unique=False): Property.__init__(self, verbose_name, name, default, required, validator, choices, unique) -def validate_text(value): - if not isinstance(value, str) and not isinstance(value, unicode): - raise TypeError, 'Expecting Text, got %s' % type(value) - class TextProperty(Property): type_name = 'Text' def __init__(self, verbose_name=None, name=None, default='', required=False, - validator=validate_text, choices=None, unique=False): + validator=None, choices=None, unique=False, max_length=None): Property.__init__(self, verbose_name, name, default, required, validator, choices, unique) + self.max_length = max_length + + def validate(self, value): + if not isinstance(value, str) and not isinstance(value, unicode): + raise TypeError, 'Expecting Text, got %s' % type(value) + if self.max_length and len(value) > self.max_length: + raise ValueError, 'Length of value greater than maxlength %s' % self.max_length class PasswordProperty(StringProperty): """ |