Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src/sugar/tutorius/constraints.py
diff options
context:
space:
mode:
authormike <michael.jmontcalm@gmail.com>2009-05-05 05:44:27 (GMT)
committer mike <michael.jmontcalm@gmail.com>2009-05-05 05:44:27 (GMT)
commit6fa568daae3291c7a876cd903f04079a12945dcb (patch)
treefaa112d6dee15fa9d6dc340762e7a45878842bee /src/sugar/tutorius/constraints.py
parentd66690142b643401429bfff84d42acac002e1980 (diff)
parentfb49b482f5bd478bada50cd1ab25a876806eff31 (diff)
Merge branch 'mike'
Conflicts: source/external/source/sugar-toolkit/src/sugar/tutorius/actions.py source/external/source/sugar-toolkit/src/sugar/tutorius/tests/actiontests.py source/external/source/sugar-toolkit/src/sugar/tutorius/tests/run-tests.py
Diffstat (limited to 'src/sugar/tutorius/constraints.py')
-rw-r--r--src/sugar/tutorius/constraints.py26
1 files changed, 22 insertions, 4 deletions
diff --git a/src/sugar/tutorius/constraints.py b/src/sugar/tutorius/constraints.py
index a666ecb..0e09664 100644
--- a/src/sugar/tutorius/constraints.py
+++ b/src/sugar/tutorius/constraints.py
@@ -81,10 +81,10 @@ class LowerLimitConstraint(ValueConstraint):
raise LowerLimitConstraintError()
return
-class SizeConstraintError(Exception):
+class MaxSizeConstraintError(Exception):
pass
-class SizeConstraint(ValueConstraint):
+class MaxSizeConstraint(ValueConstraint):
def validate(self, value):
"""
Evaluate whether a given object is smaller than the given size when
@@ -94,9 +94,27 @@ class SizeConstraint(ValueConstraint):
bigger than the limit.
"""
if self.limit is not None:
- if self.limit > len(value):
+ if self.limit >= len(value):
return
- raise SizeConstraintError("Setter : trying to set value of length %d while limit is %d"%(len(value), self.limit))
+ raise MaxSizeConstraintError("Setter : trying to set value of length %d while limit is %d"%(len(value), self.limit))
+ return
+
+class MinSizeConstraintError(Exception):
+ pass
+
+class MinSizeConstraint(ValueConstraint):
+ def validate(self, value):
+ """
+ Evaluate whether a given object is smaller than the given size when
+ run through len(). Great for string, lists and the like. ;)
+
+ @raise SizeConstraintError If the length of the value is strictly
+ bigger than the limit.
+ """
+ if self.limit is not None:
+ if self.limit <= len(value):
+ return
+ raise MinSizeConstraintError("Setter : trying to set value of length %d while limit is %d"%(len(value), self.limit))
return
class ColorConstraintError(Exception):