Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
E
erp5diff
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
erp5diff
Commits
10d08679
Commit
10d08679
authored
Aug 08, 2011
by
Nicolas Delaby
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve Handling of mixed content
parent
b0dbe4fd
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
2 deletions
+39
-2
CHANGES.txt
CHANGES.txt
+1
-0
src/ERP5Diff/ERP5Diff.py
src/ERP5Diff/ERP5Diff.py
+26
-1
src/tests/erp5diff_test_suite.py
src/tests/erp5diff_test_suite.py
+12
-1
No files found.
CHANGES.txt
View file @
10d08679
0.8.1.5 (unreleased)
--------------------
* Fix rst syntax
* Improve Handling of mixed content
0.8.1.4 (2011/08/05)
--------------------
...
...
src/ERP5Diff/ERP5Diff.py
View file @
10d08679
...
...
@@ -206,6 +206,15 @@ class ERP5Diff:
update_element
.
text
=
element
.
text
root
.
append
(
update_element
)
def
_xupdateUpdateTextNode
(
self
,
element
,
text
,
path
,
nsmap
=
None
):
"""Update only text attribute
"""
root
=
self
.
_getResultRoot
()
update_element
=
etree
.
Element
(
'{%s}update'
%
self
.
_ns
,
nsmap
=
nsmap
)
update_element
.
attrib
[
'select'
]
=
path
update_element
.
text
=
text
root
.
append
(
update_element
)
def
_xupdateRemoveElement
(
self
,
path
,
nsmap
=
None
):
"""
Remove an element at 'path'.
...
...
@@ -571,7 +580,7 @@ class ERP5Diff:
# This means that the semantics of this element is quite different.
self
.
_p
(
"One of them has only text and the other does not, so just update all the contents."
)
self
.
_xupdateUpdateElement
(
new_element
,
path
,
nsmap
=
new_element
.
nsmap
)
elif
not
old_ignore_text
:
elif
not
old_ignore_text
and
not
len
(
old_element
)
:
# The contents are only text.
self
.
_p
(
"Both have only text."
)
old_text
=
self
.
_aggregateText
(
old_element
)
...
...
@@ -596,6 +605,22 @@ class ERP5Diff:
new_node
=
new_list
[
new_current
]
if
self
.
_testElements
(
old_node
,
new_node
):
self
.
_testAttributes
(
old_node
,
new_node
,
child_path
)
if
not
old_ignore_text
and
len
(
old_element
):
# Mixed Content
if
old_node
.
text
and
old_node
.
text
.
strip
()
and
new_node
.
text
\
and
new_node
.
text
.
strip
()
and
old_node
.
text
!=
new_node
.
text
:
text_path
=
child_path
+
'/text()[%i]'
%
(
new_node
.
getparent
().
index
(
new_node
))
self
.
_xupdateUpdateTextNode
(
new_node
,
new_node
.
text
,
text_path
,
nsmap
=
new_element
.
nsmap
)
if
old_node
.
tail
and
old_node
.
tail
.
strip
()
and
new_node
.
tail
\
and
new_node
.
tail
.
strip
()
and
old_node
.
tail
!=
new_node
.
tail
:
position
=
1
if
new_node
.
getparent
().
text
:
position
+=
1
position
+=
len
([
sibling
for
sibling
in
old_node
.
itersiblings
(
preceding
=
True
)
if
sibling
.
tail
])
text_path
=
path
+
'/text()[%i]'
%
(
position
)
self
.
_xupdateUpdateTextNode
(
new_node
,
new_node
.
tail
,
text_path
,
nsmap
=
new_element
.
nsmap
)
self
.
_compareChildNodes
(
old_node
,
new_node
,
child_path
)
new_start
=
new_current
+
1
if
new_current
in
new_object_left_index_set
:
...
...
src/tests/erp5diff_test_suite.py
View file @
10d08679
...
...
@@ -1117,16 +1117,27 @@ class TestERP5Diff(unittest.TestCase):
old_xml
=
"""
<ul>
<node/>blablabla
<node>AAA<blank/>BBB</node>
<node>AAA<blank/>BBB</node>
<node>AAA<blank/>BBB<blank/>BBB</node>CCC
</ul>
"""
new_xml
=
"""
<ul>
<node/>yayaya
<node>C<blank/>BBB</node>
<node>AAA<blank/>D</node>
<node>AAA<blank/>BBB<blank/>E</node>F
</ul>
"""
expected_result_string
=
"""<xupdate:modifications xmlns:xupdate="http://www.xmldb.org/xupdate" version="1.0">
<xupdate:update select="/ul"><node/>yayaya
<xupdate:update select="/ul/text()[1]">yayaya
</xupdate:update>
<xupdate:update select="/ul/node[2]/text()[1]">C</xupdate:update>
<xupdate:update select="/ul/node[3]/text()[2]">D</xupdate:update>
<xupdate:update select="/ul/text()[2]">F
</xupdate:update>
<xupdate:update select="/ul/node[4]/text()[3]">E</xupdate:update>
</xupdate:modifications>
"""
self
.
_assertERP5DiffWorks
(
old_xml
,
new_xml
,
expected_result_string
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment