diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index 88dffc389..cbb1a1863 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -6,6 +6,8 @@ * src/dates/Date_de.py: Register for all variants of german; Add other variants of month names for parser + * src/Date.py: Raise Exception.DateError on invalid arguments + 2005-05-12 Don Allingham * src/GrampsBSDDB.py: force database sync on transaction commit diff --git a/gramps2/src/Date.py b/gramps2/src/Date.py index c2b09e636..ce2bf5cee 100644 --- a/gramps2/src/Date.py +++ b/gramps2/src/Date.py @@ -25,6 +25,7 @@ __author__ = "Donald N. Allingham" __version__ = "$Revision$" +from Errors import DateError from CalSdn import * #------------------------------------------------------------------------- @@ -143,9 +144,9 @@ class Date: Comparison function. Allows the usage of equality tests. This allows you do run statements like 'date1 <= date2' """ - if isinstance(other,Date): + if isinstance(other,Date): return cmp(self.sortval,other.sortval) - else: + else: return -1 def is_equal(self,other): @@ -233,6 +234,8 @@ class Date: """ Sets the modifier for the date. """ + if val not in (MOD_NONE,MOD_BEFORE,MOD_AFTER,MOD_ABOUT,MOD_RANGE,MOD_SPAN,MOD_TEXTONLY): + raise DateError("Invalid modifier") self.modifier = val def get_quality(self): @@ -250,6 +253,8 @@ class Date: """ Sets the quality selected for the date. """ + if val not in (QUAL_NONE,QUAL_ESTIMATED,QUAL_CALCULATED): + raise DateError("Invalid quality") self.quality = val def get_calendar(self): @@ -270,6 +275,8 @@ class Date: """ Sets the calendar selected for the date. """ + if val not in (CAL_GREGORIAN,CAL_JULIAN,CAL_HEBREW,CAL_FRENCH,CAL_PERSIAN,CAL_ISLAMIC): + raise DateError("Invalid calendar") self.calendar = val def get_start_date(self): @@ -427,6 +434,18 @@ class Date: The sort value is recalculated. """ + + if modifier in (MOD_NONE,MOD_BEFORE,MOD_AFTER,MOD_ABOUT) and len(value) < 4: + raise DateError("Invalid value. Should be: (DD,MM,YY,slash)") + if modifier in (MOD_RANGE,MOD_SPAN) and len(value) < 8: + raise DateError("Invalid value. Should be: (DD,MM,YY,slash1,DD,MM,YY,slash2)") + if modifier not in (MOD_NONE,MOD_BEFORE,MOD_AFTER,MOD_ABOUT,MOD_RANGE,MOD_SPAN,MOD_TEXTONLY): + raise DateError("Invalid modifier") + if quality not in (QUAL_NONE,QUAL_ESTIMATED,QUAL_CALCULATED): + raise DateError("Invalid quality") + if calendar not in (CAL_GREGORIAN,CAL_JULIAN,CAL_HEBREW,CAL_FRENCH,CAL_PERSIAN,CAL_ISLAMIC): + raise DateError("Invalid calendar") + self.quality = quality self.modifier = modifier self.calendar = calendar