n6sdk.pyramid_commons.renderers¶
Note
To learn how to implement your own renderer, please analyze the source code of the classes defined in this module.
Note
To learn how to register your own renderer (to make it usable with in your n6sdk-based application), please consult the n6sdk.pyramid_commons.register_stream_renderer() documentation.
- class n6sdk.pyramid_commons.renderers.BaseStreamRenderer(data_generator, request)[source]¶
Bases: object
The base class for renderers.
- content_type = None¶
- class n6sdk.pyramid_commons.renderers.StreamRenderer_sjson(data_generator, request)[source]¶
Bases: n6sdk.pyramid_commons.renderers.BaseStreamRenderer
The class of the renderer registered as the json one.
- content_type = 'text/plain'¶
- class n6sdk.pyramid_commons.renderers.StreamRenderer_json(data_generator, request)[source]¶
Bases: n6sdk.pyramid_commons.renderers.BaseStreamRenderer
The class of the renderer registered as the sjson one.
- content_type = 'application/json'¶
- n6sdk.pyramid_commons.renderers.dict_with_nulls_removed(d, _container_with_nulls_removed=<function _container_with_nulls_removed at 0x7fabb3bc0c08>, _isinstance=<built-in function isinstance>, _jsonable_container=(<type 'dict'>, <type 'list'>, <type 'tuple'>), _dict_items=<method 'iteritems' of 'dict' objects>)[source]¶
Get a copy of the given dictionary with empty-or-None items removed recursively.
(A helper function used by the StreamRenderer_json and StreamRenderer_sjson renderers.)
Note
Values equal to 0 (including False) are not removed. Other false values – such as empty sequences (including strings) or None – are removed.
>>> d = { ... 'a': 'A', 'b': '', 'c': [], 'd': (), 'e': {}, 'f': [''], 'g': ['x'], ... 'h': { ... 'a': 'A', 'b': '', 'c': [], 'd': (), 'e': {}, 'f': [''], 'g': ['x'], ... }, ... 'i': ['A', '', 0, [], (), {}, [None], [0.0], ['x']], ... 'j': ['', [{}], ([{}]), {'x': ()}, ['']], ... 'k': [None], ... 'l': {'x': None}, ... 'm': None, ... 'x': [0], ... 'y': {'x': False}, ... 'z': 0, ... } >>> d2 = dict_with_nulls_removed(d) >>> d2 == { ... 'a': 'A', 'g': ['x'], ... 'h': {'a': 'A', 'g': ['x']}, ... 'i': ['A', 0, [0.0], ['x']], ... 'x': [0], ... 'y': {'x': False}, ... 'z': 0, ... } True
>>> dict_with_nulls_removed({}) {}