diff options
| author | milde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2018-01-16 13:30:57 +0000 |
|---|---|---|
| committer | milde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2018-01-16 13:30:57 +0000 |
| commit | ddde4af2ad7ac51f41537ce356d7c190817ce714 (patch) | |
| tree | f5c10d40d62e8e1d9d3924d8e87b062d95d4da39 | |
| parent | 94041206ff045582fc88ef5ead790805a14b0963 (diff) | |
| download | docutils-ddde4af2ad7ac51f41537ce356d7c190817ce714.tar.gz | |
Fix [ 251 ] system_message.copy() TypeError. Fix nodes.Element.copy()
Avoid clash with multiple values for keyword argument "rawsource".
Let nodes.Element.copy() also copy "document", "line",
and "source" attributes.
git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk@8212 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
| -rw-r--r-- | docutils/HISTORY.txt | 6 | ||||
| -rw-r--r-- | docutils/docutils/nodes.py | 20 | ||||
| -rwxr-xr-x | docutils/test/test_nodes.py | 3 |
3 files changed, 23 insertions, 6 deletions
diff --git a/docutils/HISTORY.txt b/docutils/HISTORY.txt index fa5b3020c..e6fa70fba 100644 --- a/docutils/HISTORY.txt +++ b/docutils/HISTORY.txt @@ -29,11 +29,13 @@ Changes Since 0.14 * docutils/nodes.py - `Text.rstrip` and `Text.lstrip` now handle `rawsource` attribute. - + - Fix [ 251 ] system_message.copy() TypeError. + Element.copy() also copies `document`, `line`, and `source` attributes. + * docutils/parsers/rst/states.py: - Allow embedded colons in field list field names. - - Add "rawsource" attribute for text of inline elements and definition + - Add `rawsource` attribute for text of inline elements and definition list terms. * docutils/parsers/rst/directives/html.py: diff --git a/docutils/docutils/nodes.py b/docutils/docutils/nodes.py index 2b31e7771..1490f43fb 100644 --- a/docutils/docutils/nodes.py +++ b/docutils/docutils/nodes.py @@ -1005,7 +1005,11 @@ class Element(Node): for child in self.children]) def copy(self): - return self.__class__(rawsource=self.rawsource, **self.attributes) + obj = self.__class__(rawsource=self.rawsource, **self.attributes) + obj.document = self.document + obj.source = self.source + obj.line = self.line + return obj def deepcopy(self): copy = self.copy() @@ -1472,8 +1476,11 @@ class document(Root, Structural, Element): self.current_line = offset + 1 def copy(self): - return self.__class__(self.settings, self.reporter, + obj = self.__class__(self.settings, self.reporter, **self.attributes) + obj.source = self.source + obj.line = self.line + return obj def get_decoration(self): if not self.decoration: @@ -1672,11 +1679,12 @@ class system_message(Special, BackLinkable, PreBibliographic, Element): """ def __init__(self, message=None, *children, **attributes): + rawsource = attributes.get('rawsource', '') if message: p = paragraph('', message) children = (p,) + children try: - Element.__init__(self, '', *children, **attributes) + Element.__init__(self, rawsource, *children, **attributes) except: print 'system_message: children=%r' % (children,) raise @@ -1752,8 +1760,12 @@ class pending(Special, Invisible, Element): for line in internals])) def copy(self): - return self.__class__(self.transform, self.details, self.rawsource, + obj = self.__class__(self.transform, self.details, self.rawsource, **self.attributes) + obj.document = self.document + obj.source = self.source + obj.line = self.line + return obj class raw(Special, Inline, PreBibliographic, FixedTextElement): diff --git a/docutils/test/test_nodes.py b/docutils/test/test_nodes.py index 557078c77..6541c699e 100755 --- a/docutils/test/test_nodes.py +++ b/docutils/test/test_nodes.py @@ -616,6 +616,9 @@ class MiscTests(unittest.TestCase): self.assertEqual(e.rawsource, 'rawsource') self.assertEqual(e_copy.rawsource, e.rawsource) self.assertEqual(e_copy['att'], 'e') + self.assertEqual(e_copy.document, e.document) + self.assertEqual(e_copy.source, e.source) + self.assertEqual(e_copy.line, e.line) # Children are not copied. self.assertEqual(len(e_copy), 0) # Deep copy: |
