* src/Date.py: Raise Exception.DateError on invalid arguments

svn: r4581
This commit is contained in:
Martin Hawlisch 2005-05-13 12:50:10 +00:00
parent 46f65e9d33
commit dffb9781b3
2 changed files with 23 additions and 2 deletions

View File

@ -6,6 +6,8 @@
* src/dates/Date_de.py: Register for all variants of german; Add other * src/dates/Date_de.py: Register for all variants of german; Add other
variants of month names for parser variants of month names for parser
* src/Date.py: Raise Exception.DateError on invalid arguments
2005-05-12 Don Allingham <don@gramps-project.org> 2005-05-12 Don Allingham <don@gramps-project.org>
* src/GrampsBSDDB.py: force database sync on transaction commit * src/GrampsBSDDB.py: force database sync on transaction commit

View File

@ -25,6 +25,7 @@
__author__ = "Donald N. Allingham" __author__ = "Donald N. Allingham"
__version__ = "$Revision$" __version__ = "$Revision$"
from Errors import DateError
from CalSdn import * from CalSdn import *
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
@ -143,9 +144,9 @@ class Date:
Comparison function. Allows the usage of equality tests. Comparison function. Allows the usage of equality tests.
This allows you do run statements like 'date1 <= date2' This allows you do run statements like 'date1 <= date2'
""" """
if isinstance(other,Date): if isinstance(other,Date):
return cmp(self.sortval,other.sortval) return cmp(self.sortval,other.sortval)
else: else:
return -1 return -1
def is_equal(self,other): def is_equal(self,other):
@ -233,6 +234,8 @@ class Date:
""" """
Sets the modifier for the 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 self.modifier = val
def get_quality(self): def get_quality(self):
@ -250,6 +253,8 @@ class Date:
""" """
Sets the quality selected for the 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 self.quality = val
def get_calendar(self): def get_calendar(self):
@ -270,6 +275,8 @@ class Date:
""" """
Sets the calendar selected for the 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 self.calendar = val
def get_start_date(self): def get_start_date(self):
@ -427,6 +434,18 @@ class Date:
The sort value is recalculated. 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.quality = quality
self.modifier = modifier self.modifier = modifier
self.calendar = calendar self.calendar = calendar