Skip to content
Browse files

Docs are now more or less up to date.

  • Loading branch information...
1 parent c615f8c commit 4d28bd2048bcc72cc7869d80bd28d498b160c098 @bigjason committed Jun 21, 2011
View
39 datatree/render/dictrender.py
@@ -1,9 +1,46 @@
+"""
+Outputs the tree as python dict. It is available under the alias ``'dict'``
+and ``'dictionary'``.
+
+Options
+-------
+
+================= ============================================================== ===========
+Name Description Example
+================= ============================================================== ===========
+pretty_string When True, outputs the ``dict`` as a string with pretty ``False``
+ formatting.
+allow_node_loss Determines if a duplicate node name will result in a node ``False``
+ loss due to duplicate keys in the dict.
+================= ============================================================== ===========
+
+Example Output
+--------------
+.. code-block:: python
+
+ tree('dict', pretty_string=True)
+
+.. code-block:: python
+
+ {'author': {'genre': 'Fantasy/Comedy',
+ 'name': 'Terry Pratchett',
+ 'novels': ['Small Gods', 'The Fifth Elephant', 'Guards! Guards!']}}
+
+Duplicate Node Names
+--------------------
+While xml handles duplicate nodes just fine, python dicts and json for that matter
+do not allow duplicates. To handle this the DictRenderer will attempt to
+group nodes with the same name into a sub dictionary. This is why in the above
+example there is only one key for "novels".
+
+"""
+
from pprint import pformat
from datatree.render.base import InternalRenderer
from datatree.tree import Tree
-class DictTreeRenderer(InternalRenderer):
+class DictRenderer(InternalRenderer):
default_options = {
'pretty_string': False,
'allow_node_loss': False
View
18 datatree/render/etreerender.py
@@ -1,3 +1,21 @@
+"""
+Outputs the tree as an elementtree. It is available under the alias ``'etree'``.
+
+**Note:** *This module is not fully implemented. It supports the basic node
+types, but not comments, declarations, instructions or cdata.*
+
+Options
+-------
+
+========= ================================================= ==========
+Name Description Default
+========= ================================================= ==========
+as_string Outputs the document as a string instead of a ``False``
+ populated elementtree.
+========= ================================================= ==========
+
+"""
+
try:
import xml.etree.cElementTree as e
except ImportError:
View
16 datatree/render/jsonrender.py
@@ -5,12 +5,12 @@
Options
-------
-========= =================================================
-Name Description
-========= =================================================
-pretty Outputs the json document with pretty formatting.
-sort_keys Sorts the keys in the json document.
-========= =================================================
+========= ================================================= ==========
+Name Description Default
+========= ================================================= ==========
+pretty Outputs the json document with pretty formatting. ``False``
+sort_keys Sorts the keys in the json document. ``False``
+========= ================================================= ==========
Example Output
--------------
@@ -35,9 +35,9 @@
"""
from json import dumps
-from .dictrender import DictTreeRenderer
+from .dictrender import DictRenderer
-class JsonRenderer(DictTreeRenderer):
+class JsonRenderer(DictRenderer):
default_options = {
'pretty': False,
'sort_keys': False
View
14 datatree/render/xmlrenderer.py
@@ -4,13 +4,13 @@
Options
-------
-======= ==============================================================
-Name Description
-======= ==============================================================
-pretty When True, Outputs the xml document with pretty formatting.
-indent Used with pretty formatting. It is the string that will
- be used to indent each level. Default is ``' '``.
-======= ==============================================================
+======= ============================================================== ===========
+Name Description Example
+======= ============================================================== ===========
+pretty When True, Outputs the xml document with pretty formatting. ``False``
+indent Used with pretty formatting. It is the string that will ``' '``
+ be used to indent each level.
+======= ============================================================== ===========
Example Output
--------------
View
12 datatree/render/yamlrender.py
@@ -6,11 +6,11 @@
Options
-------
-========= =================================================
-Name Description
-========= =================================================
+========= ================================================= ===========
+Name Description Default
+========= ================================================= ===========
*None*
-========= =================================================
+========= ================================================= ===========
Example Output
--------------
@@ -33,9 +33,9 @@
except ImportError:
from yaml import Dumper
-from .dictrender import DictTreeRenderer
+from .dictrender import DictRenderer
-class YamlRenderer(DictTreeRenderer):
+class YamlRenderer(DictRenderer):
default_options = {
}
View
8 datatree/tests/test_dictrenderer.py
@@ -4,7 +4,7 @@
import unittest
from datatree import Tree, n
-from datatree.render.dictrender import DictTreeRenderer, NodeLossError
+from datatree.render.dictrender import DictRenderer, NodeLossError
class test_DictRenderer(unittest.TestCase):
def test_nested_render(self):
@@ -35,7 +35,7 @@ def test__children_distinct_names(self):
root.person('Two')
root.person('Three')
- render = DictTreeRenderer()
+ render = DictRenderer()
self.assertSetEqual(render._children_distinct_names(root.__children__), set(["person"]))
def test__children_distinct_names_are_different(self):
@@ -45,12 +45,12 @@ def test__children_distinct_names_are_different(self):
root.different('Two')
root.strokes('Three')
- render = DictTreeRenderer()
+ render = DictRenderer()
expected = set(["person", "different", "strokes"])
self.assertSetEqual(render._children_distinct_names(root.__children__), expected)
def test__children_distinct_names_large(self):
- render = DictTreeRenderer()
+ render = DictRenderer()
tree = Tree()
with tree.root() as root:
root << [n('Node', i) for i in range(1000)]
View
2 datatree/tree.py
@@ -11,7 +11,7 @@
_plugins = [
[("xml",), 'datatree.render.xmlrenderer.XmlRenderer'],
[('etree'), 'datatree.render.etreerender.ETreeRenderer'],
- [('dict', 'dictionary'), 'datatree.render.dictrender.DictTreeRenderer'],
+ [('dict', 'dictionary'), 'datatree.render.dictrender.DictRenderer'],
[('json', 'jsn', 'js'), 'datatree.render.jsonrender.JsonRenderer'],
[('yaml', 'yml'), 'datatree.render.yamlrender.YamlRenderer']
]
View
8 docs/API.rst
@@ -55,3 +55,11 @@ JsonRenderer
YamlRenderer
^^^^^^^^^^^^
.. automodule:: datatree.render.yamlrender
+
+DictRenderer
+^^^^^^^^^^^^
+.. automodule:: datatree.render.dictrender
+
+ETreeRenderer
+^^^^^^^^^^^^^
+.. automodule:: datatree.render.etreerender
View
13 docs/changelog.rst
@@ -5,6 +5,19 @@ Change Log
.. contents::
:local:
+.. v0.1.8:
+
+0.1.8
+=====
+:Release Date: 06-21-2011
+
+* :class:`JsonRenderer <datatree.render.jsonrender>` pretty option
+ now defaults to ``False``.
+
+* Documentation updates.
+
+* Bug fixes.
+
.. v0.1.7:
0.1.7

0 comments on commit 4d28bd2

Please sign in to comment.
Something went wrong with that request. Please try again.