kartagis / pysimplesoap

Automatically exported from code.google.com/p/pysimplesoap
0 stars 0 forks source link

Fails to parse isoformat datetime strings with fractional seconds #32

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1.try and parse a soap response with a timestamp with fractional seconds

What is the expected output? What do you see instead?

You get a valueError.  Should parse just fine.

What version of the product are you using? On what operating system?

python2.7

Please provide any additional information below.

Original issue reported on code.google.com by pjimen...@gmail.com on 15 Jun 2011 at 9:58

GoogleCodeExporter commented 8 years ago
This will fix it; there may be a better way, but this worked for me:

diff -r 5714ec754542 pysimplesoap/simplexml.py
--- a/pysimplesoap/simplexml.py Tue May 31 11:36:30 2011 +0100
+++ b/pysimplesoap/simplexml.py Wed Jun 15 16:57:24 2011 -0500
@@ -25,7 +25,14 @@
 DEBUG = False

 # Functions to serialize/unserialize special immutable types:
-datetime_u = lambda s: datetime.datetime.strptime(s, "%Y-%m-%dT%H:%M:%S")
+#datetime_u = lambda s: datetime.datetime.strptime(s, "%Y-%m-%dT%H:%M:%S.%f")
+def datetime_u(s):
+    fmt = "%Y-%m-%dT%H:%M:%S"
+    try:
+        return datetime.datetime.strptime(s, fmt)
+    except:
+       return datetime.datetime.strptime(s, fmt + ".%f")
+
 datetime_m = lambda dt: dt.isoformat('T')
 date_u = lambda s: datetime.datetime.strptime(s[0:10], "%Y-%m-%d").date()
 date_m = lambda d: d.strftime("%Y-%m-%d")

Original comment by pjimen...@gmail.com on 15 Jun 2011 at 9:59

GoogleCodeExporter commented 8 years ago
Great, could you commit it? 
I've made you contributor ;-)

Also, if you can, a test case would be helpful too.

Original comment by reingart@gmail.com on 15 Jun 2011 at 10:19

GoogleCodeExporter commented 8 years ago
Pushed as rev 16d61b27e9a8, with a test case in the __main__ section. No idea 
how to mark this issue fixed though.

Original comment by pjimen...@gmail.com on 16 Jun 2011 at 2:23

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Closed, thanks.

Sorry, I forgot to give you Edit Issue permission, now you can modify this 
tickets. 

Original comment by reingart@gmail.com on 16 Jun 2011 at 8:59