[Osaas-commits] r67 - in trunk: . server/osaas

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Mar 19 19:02:59 CET 2010


Author: bh
Date: 2010-03-19 19:02:59 +0100 (Fri, 19 Mar 2010)
New Revision: 67

Modified:
   trunk/ChangeLog
   trunk/server/osaas/formparser.py
Log:
* server/osaas/formparser.py (DateField.deserialize): Extend the
format for timestamps with milliseconds which are formatted as a
decimal point and three digits after the seconds.  This format
cannot be handled by strptime anymore, so we use a regular
expression now.


Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2010-03-19 17:55:38 UTC (rev 66)
+++ trunk/ChangeLog	2010-03-19 18:02:59 UTC (rev 67)
@@ -1,5 +1,13 @@
 2010-03-19  Bernhard Herzog  <bh at intevation.de>
 
+	* server/osaas/formparser.py (DateField.deserialize): Extend the
+	format for timestamps with milliseconds which are formatted as a
+	decimal point and three digits after the seconds.  This format
+	cannot be handled by strptime anymore, so we use a regular
+	expression now.
+
+2010-03-19  Bernhard Herzog  <bh at intevation.de>
+
 	* server/test/serversupport.py (ServerTest::run_simple_http_test):
 	Add comment about printing the error lod for debug purposes.
 

Modified: trunk/server/osaas/formparser.py
===================================================================
--- trunk/server/osaas/formparser.py	2010-03-19 17:55:38 UTC (rev 66)
+++ trunk/server/osaas/formparser.py	2010-03-19 18:02:59 UTC (rev 67)
@@ -1,4 +1,4 @@
-# Copyright (C) 2007, 2008 by Intevation GmbH
+# Copyright (C) 2007, 2008, 2010 by Intevation GmbH
 # Authors:
 # Bernhard Herzog <bh at intevation.de>
 #
@@ -10,7 +10,9 @@
 import cgi
 import datetime
 import time
+import re
 
+
 class FormParserException(Exception):
 
     pass
@@ -28,12 +30,20 @@
 
 class DateField(Field):
 
+    regexp = re.compile("([0-9]{4})-([0-9]{2})-([0-9]{2})"
+                        "T([0-9]{2}):([0-9]{2}):([0-9]{2}).([0-9]{3})Z$")
+
     def deserialize(self, string):
-        return datetime.datetime(*time.strptime(string.strip(),
-                                                "%Y-%m-%dT%H:%M:%SZ")[:6])
+        match = self.regexp.match(string)
+        if match:
+            parts = [int(part) for part in match.groups()]
+            # the last part is given in milliseconds but must be
+            # converted to microseconds.
+            parts[-1] *= 1000
+            return datetime.datetime(*parts)
+        raise ValueError("Timestamp %r is not formatted correctly" % string)
 
 
-
 class Record:
 
     def __init__(self):



More information about the Osaas-commits mailing list