-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for year, yearmonth and duration field types (#152)
* Add support for year, yearmonth and duration types * Restore IntegerTypeTest and fix static analysis errors
- Loading branch information
Showing
11 changed files
with
248 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.9.0 | ||
0.9.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -165,4 +165,5 @@ def _get_available_types(): | |
types.ObjectType, | ||
types.GeoPointType, | ||
types.GeoJSONType, | ||
types.DurationType, | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import absolute_import | ||
from __future__ import division | ||
from __future__ import print_function | ||
from __future__ import unicode_literals | ||
|
||
import isodate | ||
from future.utils import raise_with_traceback | ||
|
||
from . import base | ||
from .. import exceptions | ||
from .. import helpers | ||
|
||
|
||
# Module API | ||
|
||
class DurationType(base.JTSType): | ||
# Public | ||
|
||
name = 'duration' | ||
null_values = helpers.NULL_VALUES | ||
supported_constraints = [ | ||
'required', | ||
'unique', | ||
'enum', | ||
'minimum', | ||
'maximum', | ||
] | ||
# --- | ||
python_type = isodate.Duration | ||
formats = 'default' | ||
|
||
def cast_default(self, value, fmt=None): | ||
|
||
if isinstance(value, self.python_type): | ||
return value | ||
|
||
try: | ||
return isodate.parse_duration(value) | ||
except isodate.ISO8601Error as e: | ||
raise_with_traceback(exceptions.InvalidDurationType(e)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import absolute_import | ||
from __future__ import division | ||
from __future__ import print_function | ||
from __future__ import unicode_literals | ||
|
||
import decimal | ||
|
||
from future.utils import raise_with_traceback | ||
|
||
from . import base | ||
from .. import exceptions | ||
from .. import helpers | ||
|
||
|
||
# Module API | ||
|
||
class YearType(base.JTSType): | ||
# Public | ||
|
||
name = 'year' | ||
null_values = helpers.NULL_VALUES | ||
supported_constraints = [ | ||
'required', | ||
'unique', | ||
'enum', | ||
'minimum', | ||
'maximum', | ||
] | ||
# --- | ||
python_type = int | ||
formats = 'default' | ||
|
||
def cast_default(self, value, fmt=None): | ||
|
||
if isinstance(value, self.python_type): | ||
return value | ||
|
||
if len(value) > 4: | ||
raise exceptions.InvalidYearType( | ||
'{0} is not a valid year value'.format(value)) | ||
|
||
try: | ||
return self.python_type(value) | ||
except (ValueError, TypeError, decimal.InvalidOperation) as e: | ||
raise_with_traceback(exceptions.InvalidYearType(e)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import absolute_import | ||
from __future__ import division | ||
from __future__ import print_function | ||
from __future__ import unicode_literals | ||
|
||
import decimal | ||
|
||
from future.utils import raise_with_traceback | ||
|
||
from . import base | ||
from .. import exceptions | ||
from .. import helpers | ||
|
||
|
||
# Module API | ||
|
||
class YearMonthType(base.JTSType): | ||
# Public | ||
|
||
name = 'yearmonth' | ||
null_values = helpers.NULL_VALUES | ||
supported_constraints = [ | ||
'required', | ||
'unique', | ||
'pattern', | ||
'enum', | ||
'minimum', | ||
'maximum', | ||
] | ||
# --- | ||
python_type = int | ||
formats = 'default' | ||
|
||
def cast_default(self, value, fmt=None): | ||
|
||
if isinstance(value, self.python_type): | ||
return value | ||
|
||
try: | ||
cast_value = self.python_type(value) | ||
if not (1 <= cast_value <= 12): | ||
raise exceptions.InvalidYearMonthType( | ||
'{0} is not a valid yearmonth value'.format(value)) | ||
return cast_value | ||
except (ValueError, TypeError, decimal.InvalidOperation) as e: | ||
raise_with_traceback(exceptions.InvalidYearMonthType(e)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters