[Fedora-suds-list] ValueError parsing date with negative timezone (w/ fix)

Grant Kushida Grant.Kushida at fox.com
Thu Aug 13 22:40:05 UTC 2009


I've run into an ValueError issue when parsing an xsd:date response with
a negative UTC timezone offset. This is happening in suds 0.3.6 as well
as on the trunk.

 

Sorry I can't provide the WSDL, since this is internal-only - but
instead, I have some patches which fix the issue in sxdate.py, and add
two test cases to builtin.py. If these changes look acceptable I'd
appreciate it if they were integrated into some future Suds version.

 

The server uses Apache CXF 2.1.1 and JAX-B 2.1.6. The WSDL defines a
response element as follows:

<xsd:element name="startDate" type="xsd:date"/>

 

The response includes the timezone offset (US Pacific time), which
happens to be negative:

<startDate>2008-01-01-08:00</startDate>

 

This gives a ValueError exception, similar to the following (this is
actually from the test case I implemented, not the original web service
client where I found the error):

Traceback (most recent call last):

  File "tests/builtin.py", line 121, in
test_should_return_correct_date_object_given_date_with_different_negativ
e_timezone

    date = XDate().translate("1945-08-20-03:00")

  File "<my home dir>/suds/trunk/suds/xsd/sxdate.py", line 82, in
translate

    return self.toPython(value)

  File "<my home dir>/suds/trunk/suds/xsd/sxdate.py", line 55, in
toPython

    year, month, day = value.rsplit('-', 3)

ValueError: too many values to unpack

 

Here are the diffs from SVN trunk revision 547, for the one-line fix to
sxdate.py and the two testcases added to builtin.py. 

 

Index: tests/builtin.py

===================================================================

--- tests/builtin.py    (revision 547)

+++ tests/builtin.py    (working copy)

@@ -117,11 +117,25 @@

         self.assertEqual(date.second, 0)

         self.assertEqual(date.hour, self.getHour(0, 3))

 

+    def
test_should_return_correct_date_object_given_date_with_different_negativ
e_timezone(self):

+        date = XDate().translate("1945-08-20-03:00")

+        self.assertEqual(date.day, self.getDay(20, 0, -3))

+        self.assertEqual(date.month, 8)

+        self.assertEqual(date.year, 1945)

+        self.assertEqual(date.minute, 0)

+        self.assertEqual(date.second, 0)

+        self.assertEqual(date.hour, self.getHour(0, -3))

+

     def
test_should_return_correct_string_from_date_object_given_date_with_timez
one(self):

         date = XDate().translate(XDate().translate("1945-08-20+03:00"),
False)

 

         self.assertEquals("1945-08-%s%s" % (str(self.getDay(20, 0, 3)),
self.getTestersTimezoneString()), date)

 

+    def
test_should_return_correct_string_from_date_object_given_date_with_negat
ive_timezone(self):

+        date = XDate().translate(XDate().translate("1945-08-20-03:00"),
False)

+

+        self.assertEquals("1945-08-%s%s" % (str(self.getDay(20, 0,
-3)), self.getTestersTimezoneString()), date)

+

     def
test_should_return_correct_date_object_given_date_with_different_utc(sel
f):

         #from where I am, this is 6 hours off and would become a
different day

         date = XDate().translate("1945-08-20Z")

Index: suds/xsd/sxdate.py

===================================================================

--- suds/xsd/sxdate.py  (revision 547)

+++ suds/xsd/sxdate.py  (working copy)

@@ -52,7 +52,7 @@

         if len(value) == 0:

             return None

 

-        year, month, day = value.rsplit('-', 3)

+        year, month, day = value.split('-', 2)

 

         #if it has a tz set, convert to user's tz

         if len(day) > 2:

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.fedoraproject.org/pipermail/suds/attachments/20090813/aac95b0f/attachment.html 


More information about the suds mailing list