-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #97 from dimagi/type-configs
Type configs
- Loading branch information
Showing
8 changed files
with
324 additions
and
216 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,6 +1,5 @@ | ||
language: python | ||
python: | ||
- "2.6" | ||
- "2.7" | ||
install: "pip install . --use-mirrors" | ||
script: "python setup.py test" |
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,13 +1,50 @@ | ||
from __future__ import absolute_import | ||
from .base import JsonObjectBase, _LimitedDictInterfaceMixin | ||
from .convert import STRING_CONVERSIONS | ||
|
||
import decimal | ||
import datetime | ||
|
||
class JsonObject(JsonObjectBase, _LimitedDictInterfaceMixin): | ||
from . import properties | ||
import re | ||
|
||
|
||
re_date = re.compile(r'^(\d{4})\D?(0[1-9]|1[0-2])\D?([12]\d|0[1-9]|3[01])$') | ||
re_time = re.compile( | ||
r'^([01]\d|2[0-3])\D?([0-5]\d)\D?([0-5]\d)?\D?(\d{3,6})?$') | ||
re_datetime = re.compile( | ||
r'^(\d{4})\D?(0[1-9]|1[0-2])\D?([12]\d|0[1-9]|3[01])' | ||
r'(\D?([01]\d|2[0-3])\D?([0-5]\d)\D?([0-5]\d)?\D?(\d{3,6})?' | ||
r'([zZ]|([\+-])([01]\d|2[0-3])\D?([0-5]\d)?)?)?$' | ||
) | ||
re_decimal = re.compile('^(\d+)\.(\d+)$') | ||
|
||
_string_conversions = STRING_CONVERSIONS | ||
|
||
class JsonObject(JsonObjectBase, _LimitedDictInterfaceMixin): | ||
def __getstate__(self): | ||
return self.to_json() | ||
|
||
def __setstate__(self, dct): | ||
self.__init__(dct) | ||
|
||
class Meta(object): | ||
properties = { | ||
decimal.Decimal: properties.DecimalProperty, | ||
datetime.datetime: properties.DateTimeProperty, | ||
datetime.date: properties.DateProperty, | ||
datetime.time: properties.TimeProperty, | ||
str: properties.StringProperty, | ||
unicode: properties.StringProperty, | ||
bool: properties.BooleanProperty, | ||
int: properties.IntegerProperty, | ||
long: properties.IntegerProperty, | ||
float: properties.FloatProperty, | ||
list: properties.ListProperty, | ||
dict: properties.DictProperty, | ||
set: properties.SetProperty, | ||
} | ||
string_conversions = ( | ||
(re_date, datetime.date), | ||
(re_time, datetime.time), | ||
(re_datetime, datetime.datetime), | ||
(re_decimal, decimal.Decimal), | ||
) |
Oops, something went wrong.