On Mon, May 12, 2014 at 08:09:05AM +0200, Mikki Weesenaar wrote:
> Dave,
> I got a next question / thingy I am struggling with.
> A subsystem I am working with, sends me XSD DateTimes which have a
> decimal which contains 7 digits. When parsing this information, I get
> the following exception:
> A File "C:\Python26\lib\_strptime.py", line 328, in _strptime
> A A data_string[found.end():])
> ValueError: unconverted data remains: 7
> Attached is a ZIP file with this scenario.
> If you execute/open; you'll see that correct() will run (it contains a
> datetime with 6 decimals) and fail() will not.
> I have tried Googling for what the format should be of xsd:datetime -
> but I could not really find it...
> A solution for this problem could be to alter the length of the decimal
> to max of 6.A
> What is your opinion about this scenario?
Mikki,
It looks like a bug in the generated code. Before the generated
code (in gds_parse_datetime) uses datetime.strptime to parse the
time, it should convert fraction of a second to microseconds.
The code seems to handle this in the opposite direction in
gds_format_datetime, but somehow I seem to have forgotten that
conversion in gds_parse_datetime.
I've attached a patch for generateDS.py. I've also pushed this fix
to Bitbucket. So, you can get the already patched file here:
https://bitbucket.org/dkuhlman/generateds
When you get a chance to try this out, please let me know whether you
agree that this fixes the problem.
Thanks much for catching this.
FYI -- You can read about xs:dateTime here:
http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/datatypes.html#dateTime
It looks to me like time is defined, in XML Schema, using fraction
of a second, with unlimited precision.
And, the generated code uses the class method strptime in the
datetime object in the datatime module in the Python standard
library. In *that* module, a datetime object is defined to have
microseconds in the range: 0 <= microsecond < 1000000
See: https://docs.python.org/2/library/datetime.html#datetime-objects
Hope this helps.
Dave
--
Dave Kuhlman
http://www.davekuhlman.org
diff -r 930317042c7b generateDS.py
--- a/generateDS.py Wed Apr 02 15:16:34 2014 -0700
+++ b/generateDS.py Mon May 12 14:36:10 2014 -0700
@@ -3247,7 +3247,8 @@
wrt(" class_obj_ = self.get_class_obj_("
"child_, %s%s)\n" % (
prefix, cleanupName(mapName(childType)), ))
- wrt(" class_obj_ = %s%s.factory()\n")
+ wrt(" class_obj_ = %s%s.factory()\n" % (
+ prefix, cleanupName(mapName(childType)), ))
else:
wrt(" obj_ = %s%s.factory()\n" % (
prefix, cleanupName(mapName(childType))))
@@ -4496,7 +4497,10 @@
tz = GeneratedsSuper._FixedOffsetTZ(
tzoff, results.group(0))
input_data = input_data[:-6]
- if len(input_data.split('.')) > 1:
+ time_parts = input_data.split('.')
+ if len(time_parts) > 1:
+ micro_seconds = int(float('0.' + time_parts[1]) * 1000000)
+ input_data = '%%s.%%s' %% (time_parts[0], micro_seconds, )
dt = datetime_.datetime.strptime(
input_data, '%%Y-%%m-%%dT%%H:%%M:%%S.%%f')
else:
------------------------------------------------------------------------------
"Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
Instantly run your Selenium tests across 300+ browser/OS combos.
Get unparalleled scalability from the best Selenium testing platform available
Simple to use. Nothing to install. Get started now for free."
http://p.sf.net/sfu/SauceLabs
_______________________________________________
generateds-users mailing list
generateds-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/generateds-users