diff --git a/CHANGES b/CHANGES index 89c7fd7b..099d7a57 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,7 @@ +4.3.1 (2024-10-16) +------------------ + - Fix regression in parsing xsd:Date with negative timezone + 4.3.0 (2024-10-13) ------------------ - Drop support for Python 3.7 and 3.8 and add support for Python 3.12 and 3.13 (#1421, #1408) diff --git a/src/zeep/xsd/types/builtins.py b/src/zeep/xsd/types/builtins.py index 9ab771f8..d98e2526 100644 --- a/src/zeep/xsd/types/builtins.py +++ b/src/zeep/xsd/types/builtins.py @@ -201,6 +201,7 @@ def pythonvalue(self, value): class Date(BuiltinType): _default_qname = xsd_ns("date") accepted_types = [datetime.date, str] + _pattern = re.compile(r"(\d{4})-(\d{2})-(\d{2})") @check_no_collection def xmlvalue(self, value): @@ -215,13 +216,10 @@ def pythonvalue(self, value): except isodate.ISO8601Error: # Recent versions of isodate don't support timezone in date's. This # is not really ISO8601 compliant anway, but we should try to handle - # it. This is a hack to support this. - if "+" in value: - value = value.split("+")[0] - return isodate.parse_date(value) - if "Z" in value: - value = value.split("Z")[0] - return isodate.parse_date(value) + # it, so lets just use a regex to parse the date directly. + m = self._pattern.match(value) + if m: + return datetime.date(*map(int, m.groups())) raise diff --git a/tests/test_xsd_builtins.py b/tests/test_xsd_builtins.py index 1b001b1c..4063771e 100644 --- a/tests/test_xsd_builtins.py +++ b/tests/test_xsd_builtins.py @@ -242,6 +242,8 @@ def test_pythonvalue(self): instance = builtins.Date() assert instance.pythonvalue("2016-03-04") == datetime.date(2016, 3, 4) assert instance.pythonvalue("2001-10-26+02:00") == datetime.date(2001, 10, 26) + assert instance.pythonvalue("2001-10-26-02:00") == datetime.date(2001, 10, 26) + assert instance.pythonvalue("2024-08-21-10:00") == datetime.date(2024, 8, 21) assert instance.pythonvalue("2001-10-26Z") == datetime.date(2001, 10, 26) assert instance.pythonvalue("2001-10-26+00:00") == datetime.date(2001, 10, 26) assert instance.pythonvalue("\r\n\t 2016-03-04 ") == datetime.date(2016, 3, 4)