diff --git a/CHANGES.rst b/CHANGES.rst index 74cc4ef..536aea3 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,6 +1,22 @@ Changes ======= +0.3.1 +----- + +- Fixed decimal serialization error. Improved restify method to use the resource client or JSONClient to avoid decimal errors. + + +0.3.0 +----- + +- Fix pypi error + +0.3(beta) +--------- + +- Removing distribute dependence + 0.2 --- **December 4, 2012** diff --git a/README.rst b/README.rst index b15862e..ca1ba5a 100644 --- a/README.rst +++ b/README.rst @@ -2,8 +2,10 @@ :alt: Build Status :target: http://travis-ci.org/joeribekker/restorm -RestORM -======= +RestORM-setuptools +================== + +**This is a fork to RestORM egg** RestORM allows you to interact with resources as if they were objects (object relational mapping), mock an entire API and incorporate custom client logic. @@ -111,8 +113,8 @@ Installation RestORM is on PyPI, so you can simply use:: - $ pip install restorm + $ pip install restorm-setuptools If you want the latest development version, get the code from Github:: - $ pip install -e git+git://github.com/joeribekker/restorm.git#egg=restorm + $ pip install -e git+git://github.com/goinnn/restorm.git#egg=restorm diff --git a/restorm/__init__.py b/restorm/__init__.py index 864a0fa..e28fcec 100644 --- a/restorm/__init__.py +++ b/restorm/__init__.py @@ -1 +1 @@ -__version__ = (0, 3, 'beta') +__version__ = (0, 3, 1) diff --git a/restorm/clients/jsonclient.py b/restorm/clients/jsonclient.py index 08d8d16..4b79f9e 100644 --- a/restorm/clients/jsonclient.py +++ b/restorm/clients/jsonclient.py @@ -33,10 +33,14 @@ def serialize(self, data): if data is None: return '' return json.dumps(data, cls=CustomEncoder) - - def deserialize(self, data): + + def deserialize(self, data, object_hook=None): if data == '': return None + if object_hook: + return json.loads(data, + parse_float=Decimal, + object_hook=object_hook) return json.loads(data, parse_float=Decimal) diff --git a/restorm/rest.py b/restorm/rest.py index 4aa7b6f..4216c26 100644 --- a/restorm/rest.py +++ b/restorm/rest.py @@ -1,4 +1,4 @@ -from restorm.clients.jsonclient import json +from restorm.clients.jsonclient import JSONClient class RestObject(object): @@ -19,9 +19,9 @@ def __new__(cls, data=None, *args, **kwargs): new_class = type('Dynamic%s' % cls.__name__, (cls,), related_resources) return super(RestObject, cls).__new__(new_class) - + def __init__(self, data=None, **kwargs): - + if data is not None: self._obj = data else: @@ -50,14 +50,21 @@ def __iter__(self): def restify(data, resource): """ Turns Python objects (dict, list, etc) into Rest objects. - + :param data: Any Python object. :param resource: The resource this data belongs to. - :return: Rest objects. + :return: Rest objects. """ def rest_object(dct): return RestObject(dct, resource=resource) - - json_data = json.dumps(data) - return json.loads(json_data, object_hook=rest_object) + + if isinstance(resource.client, JSONClient): + serialize = resource.client.serialize + deserialize = resource.client.deserialize + else: + serialize = JSONClient().serialize + deserialize = JSONClient().deserialize + + json_data = serialize(data) + return deserialize(json_data, object_hook=rest_object) diff --git a/setup.py b/setup.py index 973e280..c4cf669 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,4 @@ #!/usr/bin/env python -from distribute_setup import use_setuptools -use_setuptools() - import os import sys import restorm @@ -33,7 +30,7 @@ def read_file(name): setup( - name='restorm', + name='restorm-setuptools', version='.'.join(map(str, restorm.__version__)), # Packaging. @@ -50,7 +47,7 @@ def read_file(name): author_email='joeri@maykinmedia.nl', license='MIT', platforms=['any'], - url='http://github.com/joeribekker/restorm', + url='http://github.com/goinnn/restorm', classifiers=[ 'Development Status :: 4 - Beta', 'Intended Audience :: Developers',