|
From: <mi...@us...> - 2020-12-09 15:52:19
|
Revision: 8589
http://sourceforge.net/p/docutils/code/8589
Author: milde
Date: 2020-12-09 15:52:16 +0000 (Wed, 09 Dec 2020)
Log Message:
-----------
Fix bug #410 The 'document' attribute is None for many nodes.
Use a "property" function to recursively fetch the
`Node.document` value from the parent node.
Modified Paths:
--------------
trunk/docutils/HISTORY.txt
trunk/docutils/docutils/nodes.py
Modified: trunk/docutils/HISTORY.txt
===================================================================
--- trunk/docutils/HISTORY.txt 2020-12-09 15:34:10 UTC (rev 8588)
+++ trunk/docutils/HISTORY.txt 2020-12-09 15:52:16 UTC (rev 8589)
@@ -25,7 +25,7 @@
- Installing with ``setup.py`` now requires ``setuptools``.
Alternatively, install with `pip`_ (or "manually").
- Apply patch for bug #399 Fixes in Korean translation.
-
+
.. _pip: https://pypi.org/project/pip/
@@ -43,13 +43,15 @@
(by Takeshi KOMIYA).
- Apply version of patch #167: Let document.set_id() register all
existing IDs (thanks to Takeshi KOMIYA).
-
+ - Fix bug #410: Use a "property" function to recursively fetch
+ `Node.document` value from parent node.
+
* docutils/parsers/recommonmark_wrapper.py
- New file. An experimental wrapper to integrate the
`recommonmark`__ Markdown parser for use with stock Docutils.
- __ https://pypi.org/project/recommonmark/
+ __ https://pypi.org/project/recommonmark/
* docutils/parsers/rst/directives/body.py
Modified: trunk/docutils/docutils/nodes.py
===================================================================
--- trunk/docutils/docutils/nodes.py 2020-12-09 15:34:10 UTC (rev 8588)
+++ trunk/docutils/docutils/nodes.py 2020-12-09 15:52:16 UTC (rev 8589)
@@ -73,9 +73,6 @@
parent = None
"""Back-reference to the Node immediately containing this Node."""
- document = None
- """The `document` node at the root of the tree containing this Node."""
-
source = None
"""Path or description of the input source which generated this Node."""
@@ -82,6 +79,22 @@
line = None
"""The line number (1-based) of the beginning of this Node in `source`."""
+ _document = None
+
+ @property
+ def document(self):
+ """
+ Return the `document` node at the root of the tree containing this Node.
+ """
+ try:
+ return self._document or self.parent.document
+ except AttributeError:
+ return None
+
+ @document.setter
+ def document(self, value):
+ self._document = value
+
def __bool__(self):
"""
Node instances are always true, even if they're empty. A node is more
@@ -1062,7 +1075,7 @@
def copy(self):
obj = self.__class__(rawsource=self.rawsource, **self.attributes)
- obj.document = self.document
+ obj._document = self._document
obj.source = self.source
obj.line = self.line
return obj
@@ -1344,7 +1357,7 @@
self.decoration = None
"""Document's `decoration` node."""
- self.document = self
+ self._document = self
def __getstate__(self):
"""
@@ -1864,7 +1877,7 @@
def copy(self):
obj = self.__class__(self.transform, self.details, self.rawsource,
**self.attributes)
- obj.document = self.document
+ obj._document = self._document
obj.source = self.source
obj.line = self.line
return obj
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|