From 2a1c6d6fbcb60c44d8690add635260faf243dcd6 Mon Sep 17 00:00:00 2001 From: mike Date: Sun, 26 Apr 2009 21:42:20 +0000 Subject: (LP 352437) Core : Completed basic serializer interactions with core (actions, event filters) - needs tests Also, merged branch 'mike' into jc_support Conflicts: source/external/source/sugar-toolkit/src/sugar/tutorius/actions.py source/external/source/sugar-toolkit/src/sugar/tutorius/bundler.py source/external/source/sugar-toolkit/src/sugar/tutorius/tests/run-tests.py source/external/source/sugar-toolkit/src/sugar/tutorius/tests/serializertests.py --- (limited to 'src/sugar/tutorius/constraints.py') 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): -- cgit v0.9.1