diff options
author | smerten <smerten@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2010-08-08 12:29:52 +0000 |
---|---|---|
committer | smerten <smerten@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2010-08-08 12:29:52 +0000 |
commit | ba4faf80bd15cd44a9ed6640baca351abe2b8b71 (patch) | |
tree | 0ef71dbdfeddfef105d072fffb942f3b0578c464 | |
parent | e0e71bacc99f67b84839bd544747acb660fce4ce (diff) | |
download | docutils-ba4faf80bd15cd44a9ed6640baca351abe2b8b71.tar.gz |
Once only elements no longer propagate their changes up. Though this
is correct this leads to sections not being replaced as a whole any
more.
git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk@6384 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
-rw-r--r-- | sandbox/rstdiff/global.log | 75 | ||||
-rwxr-xr-x | sandbox/rstdiff/rstdiff.py | 115 | ||||
-rw-r--r-- | sandbox/rstdiff/tag.log | 2 | ||||
-rw-r--r-- | sandbox/rstdiff/tests/simpleHtml/expected/attributes.html | 2 | ||||
-rw-r--r-- | sandbox/rstdiff/tests/simpleHtml/expected/inlineStyles.html | 2 | ||||
-rw-r--r-- | sandbox/rstdiff/tests/simpleHtml/expected/section.html | 2 | ||||
-rw-r--r-- | sandbox/rstdiff/tests/simpleHtml/expected/textDifferent.html | 2 | ||||
-rw-r--r-- | sandbox/rstdiff/tests/simpleHtml/expected/textEqual.html | 2 | ||||
-rw-r--r-- | sandbox/rstdiff/tests/simpleHtml/expected/textOnly.html | 2 | ||||
-rw-r--r-- | sandbox/rstdiff/tests/simpleNoSource/expected/onceOnly.xml | 42 |
10 files changed, 190 insertions, 56 deletions
diff --git a/sandbox/rstdiff/global.log b/sandbox/rstdiff/global.log index 624419129..0c25347bc 100644 --- a/sandbox/rstdiff/global.log +++ b/sandbox/rstdiff/global.log @@ -1,4 +1,79 @@ ************************************** +Date: Sun Aug 8 14:23:27 CEST 2010 +Author: stefan +Tag: rstdiff_1_74 + +-------------------------------------- +Update of /home/stefan/vault/sm/rstdiff +In directory rosalu:/home/stefan/free/rstdiff + +Modified Files: + rstdiff.py + +-------------------------------------- +Update of /home/stefan/vault/sm/rstdiff/tests/simpleNoSource/expected +In directory rosalu:/home/stefan/free/rstdiff/tests/simpleNoSource/expected + +Modified Files: + onceOnly.xml + +-------------------------------------- +Log Message: +Added todos. Corrected tests to pass for now. +************************************** +Date: Sun Aug 8 11:34:50 CEST 2010 +Author: stefan +Tag: rstdiff_1_73 + +-------------------------------------- +Update of /home/stefan/vault/sm/rstdiff +In directory rosalu:/home/stefan/free/rstdiff + +Modified Files: + rstdiff.py + +-------------------------------------- +Log Message: +Once only elements do not propagate their changes up. This leads to +sections not being replaced any more. Needs checking. +************************************** +Date: Sat Aug 7 11:46:06 CEST 2010 +Author: stefan +Tag: rstdiff_1_72 + +-------------------------------------- +Update of /home/stefan/vault/sm/rstdiff +In directory rosalu:/home/stefan/free/rstdiff + +Modified Files: + rstdiff.py + +-------------------------------------- +Update of /home/stefan/vault/sm/rstdiff/tests/simpleNoSource/expected +In directory rosalu:/home/stefan/free/rstdiff/tests/simpleNoSource/expected + +Modified Files: + onceOnly.xml + +-------------------------------------- +Log Message: +Changes in label and option_string are pulled up. +************************************** +Date: Fri Aug 6 00:24:15 CEST 2010 +Author: stefan +Tag: rstdiff_1_71 + +-------------------------------------- +Update of /home/stefan/vault/sm/rstdiff +In directory theowa:/home/stefan/free/rstdiff + +Modified Files: + rstdiff.py + +-------------------------------------- +Log Message: +Debugging. +************************************** Date: Sun Aug 1 12:36:44 CEST 2010 Author: stefan Tag: rstdiff_1_70 diff --git a/sandbox/rstdiff/rstdiff.py b/sandbox/rstdiff/rstdiff.py index 835d33ada..61b6c4f5a 100755 --- a/sandbox/rstdiff/rstdiff.py +++ b/sandbox/rstdiff/rstdiff.py @@ -484,6 +484,10 @@ class DocutilsDispatcher(HashableNodeImpl): for newChild in self.copyRange(srcRoot, srcRange, newType): self.addChild(diffRoot, newChild) elif command == Opcode.Replace: + # TODO Replacement doubles elements. This needs to be + # reflected by creation of unique @ids for replaced + # elements. This needs to be reflected in referring @refid + # and @backrefs. for newChild in self.copyRange(oldRoot, oldRange, self.NewReplaced): self.addChild(diffRoot, newChild) @@ -613,7 +617,7 @@ class DocutilsDispatcher(HashableNodeImpl): def rootEq_enumerated_list(self, node, other): return self.attributeEq_enumerated_list(node, other) - def childEq_option_argument(self, node, other): + def childEq_enumerated_list(self, node, other): return (self.attributeEq_enumerated_list(node, other) and self.childrenEq(node, other)) @@ -695,26 +699,49 @@ class DocutilsDispatcher(HashableNodeImpl): and self.childrenEq(node, other)) ########################################################################### + # A change in certain elements must propagate the change up since + # they may occur only once. Must be done by parents. - # TODO A change in certain elements must propagate the change up - # or down since they may occur only once. These elements are - # <title> (down), <subtitle> (down), <decoration> (down), - # <docinfo> (down), <transition>, <header> (down), <footer> - # (down), <info>, <term> (down), <definition> (down), <field_name> - # (down), <field_body> (down), <option_group> (down), - # <description> (down), <option_string> (up), <attribution> - # (down), <label> (up), <caption> (down), <legend> (down), - # <thead>, <tbody>, <entry> (down) (because otherwise the column - # count is wrong) - # - # However, only those need to be considered which may have - # replacing changes at all. Typically not the case for container - # elements. + # Checks whether `node` and `other` have both a node of type + # `childClass` and whether the first of thosee are equal. + def rootEqWithChild(self, node, other, childClass): + if node.__class__ != other.__class__: + return False + + nodeFound = None + for nodeChild in self.getChildren(node): + if isinstance(nodeChild, childClass): + nodeFound = nodeChild + break + + otherFound = None + for otherChild in self.getChildren(other): + if isinstance(otherChild, childClass): + otherFound = otherChild + break + + if nodeFound is None or otherFound is None: + return True + + return self.childEq(nodeFound, otherFound) + + ########################################################################### + # footnote + + def rootEq_footnote(self, node, other): + return self.rootEqWithChild(node, other, nodes.label) + + ########################################################################### + # citation + + def rootEq_citation(self, node, other): + return self.rootEqWithChild(node, other, nodes.label) + + ########################################################################### + # option - # TODO Why are changes in text are propagated up? For instance - # <entry><paragraph>+</paragraph></entry> => - # <entry><paragraph>++</paragraph></entry> becomes a change in the - # <entry>! + def rootEq_option(self, node, other): + return self.rootEqWithChild(node, other, nodes.option_string) ############################################################################### ############################################################################### @@ -791,16 +818,33 @@ def buildTree(dispatcher, diffRoot, opcodes, oldRoot, newRoot): dispatcher.mergeChildren(diffRoot, oldRoot, newRoot, command, oldRange, newRange) -def cleanOpcodes(opcodes): - """Replace some nasty results in `opcodes` by cleaner versions.""" +# A change in certain elements must not be propagated up since they +# may occur only once +replaceNotUp = ( nodes.title, nodes.subtitle, nodes.term, nodes.field_name, + nodes.attribution, nodes.caption, # (%text.model) + nodes.header, nodes.footer, nodes.definition, + nodes.field_body, nodes.description, nodes.legend, + nodes.entry, # (%body.elements;+) or (%body.elements;*) + nodes.decoration, nodes.docinfo, nodes.transition, + nodes.option_group, nodes.thead, + nodes.tbody, # different content model + ) + +def cleanOpcodes(opcodes, dispatcher, oldList, newList): + """Replace some nasty results in `opcodes` by cleaner versions. Opcodes + create `newList` from `oldList`.""" for i in range(len(opcodes)): opcode = Opcode(opcodes[i]) - subOpcodes = opcode.getSubOpcodes() + ( command, oldRange, newRange, subOpcodes, + ) = opcode.resolveOpcode(oldList, newList) if not subOpcodes: - # Nothing to clean for flat opcodes + # Nothing to clean for flat or empty opcodes continue - cleanOpcodes(subOpcodes) + oldNode = oldRange[0] + newNode = newRange[0] + cleanOpcodes(subOpcodes, dispatcher, dispatcher.getChildren(oldNode), + dispatcher.getChildren(newNode)) j = 1 while j < len(subOpcodes): prev = Opcode(subOpcodes[j - 1]) @@ -820,9 +864,24 @@ def cleanOpcodes(opcodes): opcode.setSubOpcodes(subOpcodes) if len(subOpcodes) == 1: subOpcode = Opcode(subOpcodes[0]) - if subOpcode.getCommand() != Opcode.Descend: - # Propagate 1-element sequences up - opcode.setCommand(subOpcode.getCommand()) + if (subOpcode.getCommand() != Opcode.Replace + or not reduce(lambda last, cls: + last or isinstance(oldNode, cls), + replaceNotUp, False)): + # TODO If a section/title would propagate up the + # propagation needs to be done if all siblings would + # propagate, too; this way a section replacement + # should work again + # + # This applies to section/title, section/subtitle, + # definition_list_item/term, field/field_name, + # block_quote/attribution, figure/caption, + # definition_list_item/definition, field/field_body, + # option_list_item/description, figure/legend, + # option_list_item/option_group + if subOpcode.getCommand() != Opcode.Descend: + # Propagate 1-element sequences up + opcode.setCommand(subOpcode.getCommand()) opcodes[i] = opcode.asTuple() def createDiff(oldTree, newTree): @@ -836,7 +895,7 @@ def createDiff(oldTree, newTree): print(newTree.asdom().toprettyxml()) pprint(opcodes, sys.stdout, 2, 40, None) print("^^^ Before cleaning vvv After cleaning") - cleanOpcodes(opcodes) + cleanOpcodes(opcodes, dispatcher, [ oldTree ], [ newTree ]) if dispatcher.debug: from pprint import pprint pprint(opcodes, sys.stdout, 2, 40, None) diff --git a/sandbox/rstdiff/tag.log b/sandbox/rstdiff/tag.log index 8c651b11c..df0f4e962 100644 --- a/sandbox/rstdiff/tag.log +++ b/sandbox/rstdiff/tag.log @@ -1 +1 @@ -rstdiff_1_70 +rstdiff_1_74 diff --git a/sandbox/rstdiff/tests/simpleHtml/expected/attributes.html b/sandbox/rstdiff/tests/simpleHtml/expected/attributes.html index 25e0ee9aa..08501bc70 100644 --- a/sandbox/rstdiff/tests/simpleHtml/expected/attributes.html +++ b/sandbox/rstdiff/tests/simpleHtml/expected/attributes.html @@ -9,7 +9,7 @@ /* :Author: David Goodger (goodger@python.org) -:Id: $Id$ +:Id: $Id: html4css1.css 5951 2009-05-18 18:03:10Z milde $ :Copyright: This stylesheet has been placed in the public domain. Default cascading style sheet for the HTML output of Docutils. diff --git a/sandbox/rstdiff/tests/simpleHtml/expected/inlineStyles.html b/sandbox/rstdiff/tests/simpleHtml/expected/inlineStyles.html index ba823e024..d9d651444 100644 --- a/sandbox/rstdiff/tests/simpleHtml/expected/inlineStyles.html +++ b/sandbox/rstdiff/tests/simpleHtml/expected/inlineStyles.html @@ -9,7 +9,7 @@ /* :Author: David Goodger (goodger@python.org) -:Id: $Id$ +:Id: $Id: html4css1.css 5951 2009-05-18 18:03:10Z milde $ :Copyright: This stylesheet has been placed in the public domain. Default cascading style sheet for the HTML output of Docutils. diff --git a/sandbox/rstdiff/tests/simpleHtml/expected/section.html b/sandbox/rstdiff/tests/simpleHtml/expected/section.html index 5966908a2..cb8fc47ef 100644 --- a/sandbox/rstdiff/tests/simpleHtml/expected/section.html +++ b/sandbox/rstdiff/tests/simpleHtml/expected/section.html @@ -9,7 +9,7 @@ /* :Author: David Goodger (goodger@python.org) -:Id: $Id$ +:Id: $Id: html4css1.css 5951 2009-05-18 18:03:10Z milde $ :Copyright: This stylesheet has been placed in the public domain. Default cascading style sheet for the HTML output of Docutils. diff --git a/sandbox/rstdiff/tests/simpleHtml/expected/textDifferent.html b/sandbox/rstdiff/tests/simpleHtml/expected/textDifferent.html index 9980117b9..a31abb5d2 100644 --- a/sandbox/rstdiff/tests/simpleHtml/expected/textDifferent.html +++ b/sandbox/rstdiff/tests/simpleHtml/expected/textDifferent.html @@ -9,7 +9,7 @@ /* :Author: David Goodger (goodger@python.org) -:Id: $Id$ +:Id: $Id: html4css1.css 5951 2009-05-18 18:03:10Z milde $ :Copyright: This stylesheet has been placed in the public domain. Default cascading style sheet for the HTML output of Docutils. diff --git a/sandbox/rstdiff/tests/simpleHtml/expected/textEqual.html b/sandbox/rstdiff/tests/simpleHtml/expected/textEqual.html index 4d4ca9ca1..63571abf0 100644 --- a/sandbox/rstdiff/tests/simpleHtml/expected/textEqual.html +++ b/sandbox/rstdiff/tests/simpleHtml/expected/textEqual.html @@ -9,7 +9,7 @@ /* :Author: David Goodger (goodger@python.org) -:Id: $Id$ +:Id: $Id: html4css1.css 5951 2009-05-18 18:03:10Z milde $ :Copyright: This stylesheet has been placed in the public domain. Default cascading style sheet for the HTML output of Docutils. diff --git a/sandbox/rstdiff/tests/simpleHtml/expected/textOnly.html b/sandbox/rstdiff/tests/simpleHtml/expected/textOnly.html index 753d28235..3c297e0dd 100644 --- a/sandbox/rstdiff/tests/simpleHtml/expected/textOnly.html +++ b/sandbox/rstdiff/tests/simpleHtml/expected/textOnly.html @@ -9,7 +9,7 @@ /* :Author: David Goodger (goodger@python.org) -:Id: $Id$ +:Id: $Id: html4css1.css 5951 2009-05-18 18:03:10Z milde $ :Copyright: This stylesheet has been placed in the public domain. Default cascading style sheet for the HTML output of Docutils. diff --git a/sandbox/rstdiff/tests/simpleNoSource/expected/onceOnly.xml b/sandbox/rstdiff/tests/simpleNoSource/expected/onceOnly.xml index afe8aa181..ecfaec2e2 100644 --- a/sandbox/rstdiff/tests/simpleNoSource/expected/onceOnly.xml +++ b/sandbox/rstdiff/tests/simpleNoSource/expected/onceOnly.xml @@ -9,7 +9,7 @@ Each TITLE may occur only once </inline> </title> - <subtitle classes="change-replaced" ids="a-document-subtitle subtitles-as-well" names="a\ document\ subtitle subtitles\ as\ well"> + <subtitle ids="a-document-subtitle" names="a\ document\ subtitle"> <inline classes="change-replaced"> A document subtitle </inline> @@ -17,26 +17,26 @@ Subtitles as well </inline> </subtitle> - <decoration classes="change-replaced"> + <decoration> <header> - <paragraph classes="change-replacement"> + <paragraph classes="change-replaced"> The document header is once only. </paragraph> - <paragraph classes="change-replaced"> + <paragraph classes="change-replacement"> All parts of decoration may occur singly. </paragraph> </header> - <footer> - <paragraph classes="change-removed"> + <footer classes="change-removed"> + <paragraph> And the document footer. </paragraph> </footer> </decoration> <docinfo> - <author classes="change-removed"> + <author classes="change-replaced"> Stefan Merten </author> - <organization classes="change-added"> + <organization classes="change-replacement"> Should propagate to docinfo </organization> </docinfo> @@ -50,14 +50,14 @@ up. These are the references of <citation_reference classes="change-replaced" ids="id1" refid="cita"> CITA </citation_reference> - <citation_reference classes="change-replacement" ids="id2" refid="citation"> + <citation_reference classes="change-replacement" ids="id1" refid="citation"> CITATION </citation_reference> and footnotes - <footnote_reference classes="change-replaced" ids="id3" refid="id4"> + <footnote_reference classes="change-replaced" ids="id2" refid="id3"> 1 </footnote_reference> - <footnote_reference classes="change-replacement" ids="id5" refid="id6"> + <footnote_reference classes="change-replacement" ids="id2" refid="id3"> 2 </footnote_reference> . @@ -317,7 +317,7 @@ entry The option_group and the description may also appear only once </paragraph> - <paragraph classes="change-replaced"> + <paragraph classes="change-replacement"> THE DESCRIPTION AS WELL AS THE OPTION_GROUP MUST BE SINGLE. </paragraph> </description> @@ -331,23 +331,23 @@ only once The label of a citation. </paragraph> </citation> - <citation backrefs="id2" classes="change-replacement" ids="citation" names="citation"> + <footnote backrefs="id2" classes="change-replaced" ids="id3" names="1"> <label> - CITATION + 1 </label> <paragraph> - The label of a citation. + The label of a footnote. </paragraph> - </citation> - <footnote backrefs="id3" classes="change-replaced" ids="id4" names="1"> + </footnote> + <citation backrefs="id1" classes="change-replacement" ids="citation" names="citation"> <label> - 1 + CITATION </label> <paragraph> - The label of a footnote. + The label of a citation. </paragraph> - </footnote> - <footnote backrefs="id5" classes="change-replacement" ids="id6" names="2"> + </citation> + <footnote backrefs="id2" classes="change-replacement" ids="id3" names="2"> <label> 2 </label> |