summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Merickel <michael@merickel.org>2012-04-16 22:57:23 -0500
committerMichael Merickel <michael@merickel.org>2012-04-16 22:57:23 -0500
commitdfaf54a7018971c08ed4a437dbec0ffb57d1ff8a (patch)
treecd83f41b777931f2eda8cff6560719691a29b44c
parent8c44765063c5e969e8afb049fe31c4014500d339 (diff)
downloadpyramid-dfaf54a7018971c08ed4a437dbec0ffb57d1ff8a.tar.gz
pyramid-dfaf54a7018971c08ed4a437dbec0ffb57d1ff8a.tar.bz2
pyramid-dfaf54a7018971c08ed4a437dbec0ffb57d1ff8a.zip
fixed coverage, removed json encoder
-rw-r--r--pyramid/renderers.py31
-rw-r--r--pyramid/tests/test_renderers.py8
2 files changed, 4 insertions, 35 deletions
diff --git a/pyramid/renderers.py b/pyramid/renderers.py
index 3b1e0f44f..441976ce4 100644
--- a/pyramid/renderers.py
+++ b/pyramid/renderers.py
@@ -157,35 +157,6 @@ def string_renderer_factory(info):
return value
return _render
-class ObjectJSONEncoder(json.JSONEncoder):
- """ The default JSON object encoder (a subclass of json.Encoder) used by
- :class:`pyramid.renderers.JSON` and :class:`pyramid.renderers.JSONP`. It
- is used when an object returned from a view and presented to a JSON-based
- renderer is not a builtin Python type otherwise serializable to JSON.
-
- This ``json.Encoder`` subclass overrides the ``json.Encoder.default``
- method. The overridden method looks for a ``__json__`` attribute on the
- object it is passed. If it's found, the encoder will assume it's
- callable, and will call it with no arguments to obtain a value. The
- overridden ``default`` method will then return that value (which must be
- a JSON-serializable basic Python type).
-
- If the object passed to the overridden ``default`` method has no
- ``__json__`` attribute, the ``json.JSONEncoder.default`` method is called
- with the object that it was passed (which will end up raising a
- :exc:`TypeError`, as it would with any other unserializable type).
-
- This class will be used only when you set a JSON or JSONP
- renderer and you do not define your own custom encoder class.
-
- .. note:: This feature is new in Pyramid 1.4.
- """
-
- def default(self, obj):
- if hasattr(obj, '__json__'):
- return obj.__json__()
- return json.JSONEncoder.default(self, obj)
-
class JSON(object):
""" Renderer that returns a JSON-encoded string.
@@ -332,7 +303,7 @@ class JSONP(JSON):
plain-JSON encoded string with content-type ``application/json``"""
def _render(value, system):
request = system['request']
- val = self.value_to_json(value)
+ val = self.dumps(value)
callback = request.GET.get(self.param_name)
if callback is None:
ct = 'application/json'
diff --git a/pyramid/tests/test_renderers.py b/pyramid/tests/test_renderers.py
index f03c7acda..55ed3f7fd 100644
--- a/pyramid/tests/test_renderers.py
+++ b/pyramid/tests/test_renderers.py
@@ -371,12 +371,10 @@ class TestJSON(unittest.TestCase):
def test_with_custom_encoder(self):
from datetime import datetime
- from json import JSONEncoder
- class MyEncoder(JSONEncoder):
- def default(self, obj):
- return obj.isoformat()
+ def default(obj):
+ return obj.isoformat()
now = datetime.utcnow()
- renderer = self._makeOne(cls=MyEncoder)(None)
+ renderer = self._makeOne(default=default)(None)
result = renderer({'a':now}, {})
self.assertEqual(result, '{"a": "%s"}' % now.isoformat())