* src/DateParser.py: Catch DateError and use text only date as fallback
* src/plugins/TestcaseGenerator.py: Handle DateError exception svn: r4582
This commit is contained in:
		| @@ -7,6 +7,8 @@ | |||||||
| 	variants of month names for parser | 	variants of month names for parser | ||||||
|  |  | ||||||
| 	* src/Date.py: Raise Exception.DateError on invalid arguments | 	* src/Date.py: Raise Exception.DateError on invalid arguments | ||||||
|  | 	* src/DateParser.py: Catch DateError and use text only date as fallback | ||||||
|  | 	* src/plugins/TestcaseGenerator.py: Handle DateError exception | ||||||
|  |  | ||||||
| 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 | ||||||
|   | |||||||
| @@ -44,7 +44,7 @@ import calendar | |||||||
| # | # | ||||||
| #------------------------------------------------------------------------- | #------------------------------------------------------------------------- | ||||||
| import Date | import Date | ||||||
|  | from Errors import DateError | ||||||
| #------------------------------------------------------------------------- | #------------------------------------------------------------------------- | ||||||
| # | # | ||||||
| # Top-level module functions | # Top-level module functions | ||||||
| @@ -587,5 +587,8 @@ class DateParser: | |||||||
|         Parses the text, returning a Date object. |         Parses the text, returning a Date object. | ||||||
|         """ |         """ | ||||||
|         new_date = Date.Date() |         new_date = Date.Date() | ||||||
|         self.set_date(new_date,text) |         try: | ||||||
|  |             self.set_date(new_date,text) | ||||||
|  |         except DateError: | ||||||
|  |             new_date.set_as_text(text) | ||||||
|         return new_date |         return new_date | ||||||
|   | |||||||
| @@ -420,19 +420,25 @@ class TestcaseGenerator: | |||||||
|         # test invalid dates |         # test invalid dates | ||||||
|         dateval = (4,7,1789,False,5,8,1876,False) |         dateval = (4,7,1789,False,5,8,1876,False) | ||||||
|         for l in range(1,len(dateval)): |         for l in range(1,len(dateval)): | ||||||
|  |             d = Date.Date() | ||||||
|             try: |             try: | ||||||
|                 d = Date.Date() |  | ||||||
|                 d.set(Date.QUAL_NONE,Date.MOD_NONE,Date.CAL_GREGORIAN,dateval[:l],"Text comment") |                 d.set(Date.QUAL_NONE,Date.MOD_NONE,Date.CAL_GREGORIAN,dateval[:l],"Text comment") | ||||||
|                 dates.append( d) |                 dates.append( d) | ||||||
|  |             except Errors.DateError, e: | ||||||
|  |                 d.set_as_text("Date identified value correctly as invalid.\n%s" % e) | ||||||
|  |                 dates.append( d) | ||||||
|             except: |             except: | ||||||
|                 d = Date.Date() |                 d = Date.Date() | ||||||
|                 d.set_as_text("Date.set Exception %s" % ("".join(traceback.format_exception(*sys.exc_info())),)) |                 d.set_as_text("Date.set Exception %s" % ("".join(traceback.format_exception(*sys.exc_info())),)) | ||||||
|                 dates.append( d) |                 dates.append( d) | ||||||
|         for l in range(1,len(dateval)): |         for l in range(1,len(dateval)): | ||||||
|  |             d = Date.Date() | ||||||
|             try: |             try: | ||||||
|                 d = Date.Date() |  | ||||||
|                 d.set(Date.QUAL_NONE,Date.MOD_SPAN,Date.CAL_GREGORIAN,dateval[:l],"Text comment") |                 d.set(Date.QUAL_NONE,Date.MOD_SPAN,Date.CAL_GREGORIAN,dateval[:l],"Text comment") | ||||||
|                 dates.append( d) |                 dates.append( d) | ||||||
|  |             except Errors.DateError, e: | ||||||
|  |                 d.set_as_text("Date identified value correctly as invalid.\n%s" % e) | ||||||
|  |                 dates.append( d) | ||||||
|             except: |             except: | ||||||
|                 d = Date.Date() |                 d = Date.Date() | ||||||
|                 d.set_as_text("Date.set Exception %s" % ("".join(traceback.format_exception(*sys.exc_info())),)) |                 d.set_as_text("Date.set Exception %s" % ("".join(traceback.format_exception(*sys.exc_info())),)) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user