diff options
| -rw-r--r-- | docutils/HISTORY.txt | 4 | ||||
| -rw-r--r-- | docutils/docs/dev/testing.txt | 6 | ||||
| -rw-r--r-- | docutils/docutils/nodes.py | 9 | ||||
| -rwxr-xr-x | docutils/test/test_pickle.py | 30 |
4 files changed, 49 insertions, 0 deletions
diff --git a/docutils/HISTORY.txt b/docutils/HISTORY.txt index 9b39d58ad..c19362173 100644 --- a/docutils/HISTORY.txt +++ b/docutils/HISTORY.txt @@ -15,6 +15,10 @@ Changes Since 0.4 ================= +* docutils/nodes.py: + + - Added ``document.__getstate__`` method, for pickling. + * docutils/parsers/rst/states.py: - Unquoted targets beginning with an underscore (``.. __target: diff --git a/docutils/docs/dev/testing.txt b/docutils/docs/dev/testing.txt index bde54116f..3b9297807 100644 --- a/docutils/docs/dev/testing.txt +++ b/docutils/docs/dev/testing.txt @@ -65,6 +65,12 @@ __ http://www.python.org/peps/pep-0290.html http://svn.berlios.de/svndumps/docutils-repos.gz +DocutilsTestSupport +=================== + + + + Unit Tests ========== diff --git a/docutils/docutils/nodes.py b/docutils/docutils/nodes.py index 1553013ad..69aa80ede 100644 --- a/docutils/docutils/nodes.py +++ b/docutils/docutils/nodes.py @@ -887,6 +887,15 @@ class document(Root, Structural, Element): self.document = self + def __getstate__(self): + """ + Return dict with unpicklable references removed. + """ + state = self.__dict__.copy() + state['reporter'] = None + state['transformer'] = None + return state + def asdom(self, dom=None): """Return a DOM representation of this document.""" if dom is None: diff --git a/docutils/test/test_pickle.py b/docutils/test/test_pickle.py new file mode 100755 index 000000000..f4b5c249f --- /dev/null +++ b/docutils/test/test_pickle.py @@ -0,0 +1,30 @@ +#! /usr/bin/env python +# Author: David Goodger +# Contact: goodger@python.org +# Revision: $Revision$ +# Date: $Date$ +# Copyright: This module has been placed in the public domain. + +""" +Tests of document tree pickling. +""" + +import unittest +import DocutilsTestSupport # must be imported before docutils +import pickle +from docutils import core + + +class PickleTests(unittest.TestCase): + + def test_pickle(self): + doctree = core.publish_doctree( + source='Title\n=====\n\nparagraph\n', + settings_overrides={'_disable_config': 1}) + dill = pickle.dumps(doctree) + reconstituted = pickle.loads(dill) + self.assertEquals(doctree.pformat(), reconstituted.pformat()) + + +if __name__ == '__main__': + unittest.main() |
