Skip to content

Commit

Permalink
Merge pull request #97 from dimagi/type-configs
Browse files Browse the repository at this point in the history
Type configs
  • Loading branch information
millerdev committed Sep 9, 2014
2 parents 1dce008 + 64d3a4d commit c736667
Show file tree
Hide file tree
Showing 8 changed files with 324 additions and 216 deletions.
1 change: 0 additions & 1 deletion .travis.yml
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"
43 changes: 40 additions & 3 deletions jsonobject/api.py
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),
)
Loading

0 comments on commit c736667

Please sign in to comment.