From 486cf54e95248a54c7264d3d0a821a0b97dcc7de Mon Sep 17 00:00:00 2001 From: Tsuyoshi Hombashi Date: Mon, 4 Jul 2016 21:44:45 +0900 Subject: [PATCH 1/3] Add error string --- dataproperty/converter/_core.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dataproperty/converter/_core.py b/dataproperty/converter/_core.py index a896bc1..08a9dc8 100644 --- a/dataproperty/converter/_core.py +++ b/dataproperty/converter/_core.py @@ -99,7 +99,8 @@ def convert(self): try: self.__datetime = dateutil.parser.parse(self._value) except (AttributeError, ValueError, OverflowError): - raise TypeConversionError + raise TypeConversionError( + "failed to parse as datetime: " + str(self._value)) try: dst_timezone_name = self.__get_dst_timezone_name( From fa6d8a3a891ab2b2410fc6e2e4264d82a1ec7895 Mon Sep 17 00:00:00 2001 From: Tsuyoshi Hombashi Date: Mon, 4 Jul 2016 22:12:31 +0900 Subject: [PATCH 2/3] Fix type detection for version string A version string (such as "3.3.5") converted to a datetime. --- dataproperty/converter/_core.py | 21 +++++++++++++++++++++ test/test_property.py | 3 +++ 2 files changed, 24 insertions(+) diff --git a/dataproperty/converter/_core.py b/dataproperty/converter/_core.py index 08a9dc8..2d6780b 100644 --- a/dataproperty/converter/_core.py +++ b/dataproperty/converter/_core.py @@ -6,6 +6,7 @@ from __future__ import absolute_import import abc +import re from .._error import TypeConversionError @@ -82,6 +83,8 @@ class DateTimeConverter(ValueConverter): 7200: "Africa/Tripoli", # 0200 } + __RE_VERSION_STR = re.compile("\d+\.\d+\.\d") + def __init__(self, value): super(DateTimeConverter, self).__init__(value) @@ -96,6 +99,8 @@ def convert(self): self.__datetime = self._value return self.__datetime + self.__validate_datetime_string() + try: self.__datetime = dateutil.parser.parse(self._value) except (AttributeError, ValueError, OverflowError): @@ -128,3 +133,19 @@ def __get_timedelta_sec(self): def __get_dst_timezone_name(self, offset): return self.__COMMON_DST_TIMEZONE_TABLE[offset] + + def __validate_datetime_string(self): + """ + This validation is required for version string (such as "3.3.5"). + A version string is converted to a datetime value if this + validation is not executed. + """ + + try: + if self.__RE_VERSION_STR.search(self._value) is not None: + raise TypeConversionError( + "invalid datetime string: version string found " + + self._value) + except TypeError: + raise TypeConversionError( + "invalid datetime string: " + str(self._value)) diff --git a/test/test_property.py b/test/test_property.py index 695ae90..80453b5 100644 --- a/test/test_property.py +++ b/test/test_property.py @@ -32,6 +32,9 @@ class Test_DataPeroperty_data_typecode: ["a", True, "a", Typecode.STRING], ["a", False, "a", Typecode.STRING], + ["3.3.5", True, "3.3.5", Typecode.STRING], + ["51.0.2704.106", True, "51.0.2704.106", Typecode.STRING], + [True, True, True, Typecode.BOOL], [False, False, False, Typecode.BOOL], From 3d5c9fbfb411938f3127ad249e6ea66fb0494fe2 Mon Sep 17 00:00:00 2001 From: Tsuyoshi Hombashi Date: Mon, 4 Jul 2016 22:13:27 +0900 Subject: [PATCH 3/3] Bump version --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 219dd62..9b1865a 100644 --- a/setup.py +++ b/setup.py @@ -28,7 +28,7 @@ setuptools.setup( name=project_name, - version="0.5.3", + version="0.5.4", url="https://github.com/thombashi/" + project_name, bugtrack_url="https://github.com/thombashi/%s/issues" % (project_name),