diff options
| author | goodger <goodger@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2006-04-02 06:27:33 +0000 |
|---|---|---|
| committer | goodger <goodger@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2006-04-02 06:27:33 +0000 |
| commit | a5d3129cd03ea68b4460da9103c0d104f427b01c (patch) | |
| tree | 222b70e985d7f94fad7e870450914548c25f0455 | |
| parent | f52e891675d405eb4f7b1738265e47dc46259a62 (diff) | |
| download | docutils-a5d3129cd03ea68b4460da9103c0d104f427b01c.tar.gz | |
Added ``docutils.nodes.document.__getstate__`` method, for pickling.
git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk@4487 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
| -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() |
