From a5d3129cd03ea68b4460da9103c0d104f427b01c Mon Sep 17 00:00:00 2001 From: goodger Date: Sun, 2 Apr 2006 06:27:33 +0000 Subject: 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 --- docutils/HISTORY.txt | 4 ++++ docutils/docs/dev/testing.txt | 6 ++++++ docutils/docutils/nodes.py | 9 +++++++++ docutils/test/test_pickle.py | 30 ++++++++++++++++++++++++++++++ 4 files changed, 49 insertions(+) create mode 100755 docutils/test/test_pickle.py (limited to 'docutils') 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() -- cgit v1.2.1