[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnue] r9333 - trunk/gnue-forms/src/input/displayHandlers
From: |
johannes |
Subject: |
[gnue] r9333 - trunk/gnue-forms/src/input/displayHandlers |
Date: |
Fri, 26 Jan 2007 04:59:36 -0600 (CST) |
Author: johannes
Date: 2007-01-26 04:59:35 -0600 (Fri, 26 Jan 2007)
New Revision: 9333
Modified:
trunk/gnue-forms/src/input/displayHandlers/datehandler.py
Log:
Catch invalid values and raise a proper exception
Modified: trunk/gnue-forms/src/input/displayHandlers/datehandler.py
===================================================================
--- trunk/gnue-forms/src/input/displayHandlers/datehandler.py 2007-01-26
10:08:58 UTC (rev 9332)
+++ trunk/gnue-forms/src/input/displayHandlers/datehandler.py 2007-01-26
10:59:35 UTC (rev 9333)
@@ -137,6 +137,9 @@
"""
"""
+ if not display:
+ return None
+
try:
# First have a look wether the input follows the requested format
temp = time.strptime(display, self.__input_mask)
@@ -151,8 +154,12 @@
# If the input is a number of length 2 we treat it as day
if display.isdigit() and len(display) <= 2:
- return today.replace(day=int(display))
+ try:
+ return today.replace(day=int(display))
+ except ValueError:
+ raise InvalidDateLiteral, display
+
# If the input is a 4-digit number or a string with two numbers
# separated by a non-digit string we treat it as "day and month"
# according to the order of the original input mask
@@ -170,8 +177,12 @@
day = int(val2)
month = int(val1)
- return today.replace(day=day, month=month)
+ try:
+ return today.replace(day=day, month=month)
+ except ValueError:
+ raise InvalidDateLiteral, display
+
# If the input is a 6-digit number or a triple of numeric values
# separated by non-digit characters it is likely a complete date
match = re.match('^(\d+)\D+(\d+)\D+(\d+).*$', display)
@@ -192,8 +203,12 @@
value += 2000
kw[self.__order[index].lower()] = value
- return datetime.date(**kw)
+ try:
+ return datetime.date(**kw)
+ except ValueError:
+ raise InvalidDateLiteral, display
+
# If the input is a 8-digit number it should be a complete date. We
# derive the order of the elements from the order as given in the input
# mask.
@@ -209,7 +224,11 @@
day = int(display[:2])
display = display[2:]
- return datetime.date(day=day, month=month, year=year)
+ try:
+ return datetime.date(day=day, month=month, year=year)
+
+ except ValueError:
+ raise InvalidDateLiteral, display
raise InvalidDateLiteral, display
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnue] r9333 - trunk/gnue-forms/src/input/displayHandlers,
johannes <=