[issue20714] Please allow for ]]> in CDATA in minidom.py

2014-02-20 Thread Artur R. Czechowski

New submission from Artur R. Czechowski:

Current support for ]]> inside CDATA is to raise an Exception. However, it 
could be solved by dividing the ]]> to two strings:
- ]]
- >
and each one is a separate CDATA inside elemement. So, to put ]]> inside CDATA 
one can write:




--
components: XML
files: minidom.patch
keywords: patch
messages: 211791
nosy: arturcz
priority: normal
severity: normal
status: open
title: Please allow for ]]> in CDATA in minidom.py
type: behavior
versions: Python 2.7, Python 3.3
Added file: http://bugs.python.org/file34167/minidom.patch

___
Python tracker 
<http://bugs.python.org/issue20714>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue20714] Allow for ]]> in CDATA in minidom

2014-02-21 Thread Artur R. Czechowski

Artur R. Czechowski added the comment:

Eric, I'm not sure what exactly your concern is, but I'll try to address two 
issues I can see.

First: both strings  and  are a correct and valid 
examples of CDATA usage as per specification[1].

Second: is it allowed to have two occurences of CDATA inside one element? The 
same specification says only that ‟CDATA sections may occur anywhere character 
data may occur”. There is nothing said if multiple occurrences are allowed or 
disallowed.
Wikipedia suggests in [2] that it is OK, giving the same example of embedding 
]]> inside CDATA. There is no hints in Talk page that this solution doesn't 
work for someone.
In other example [3] there is explicitly stated that: ‟the [...] application 
shouldn't care about the difference between abc and  and 
”.

Last but not least: using following schema:


http://www.w3.org/2001/XMLSchema";>



following XML file:






validates correctly with xmllint:
$ xmllint -noout --schema schema.xsd t.xml
t.xml validates

I hope it dissolves your concerns.

PS. I noticed I missed one ] in provided patch. There should be four of them in 
second parameter of replace.

[1] http://www.w3.org/TR/REC-xml/#sec-cdata-sect
[2] http://en.wikipedia.org/wiki/CDATA#Nesting
[3] http://oxygenxml.com/archives/xsl-list/200502/msg00787.html

--

___
Python tracker 
<http://bugs.python.org/issue20714>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue20714] Allow for ]]> in CDATA in minidom

2014-02-23 Thread Artur R. Czechowski

Artur R. Czechowski added the comment:

Proper patch with tests available in remote hg repo attached to this comment.

--
hgrepos: +217

___
Python tracker 
<http://bugs.python.org/issue20714>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue20714] Allow for ]]> in CDATA in minidom

2014-02-23 Thread Artur R. Czechowski

Changes by Artur R. Czechowski :


Removed file: http://bugs.python.org/file34167/minidom.patch

___
Python tracker 
<http://bugs.python.org/issue20714>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue20714] Allow for ]]> in CDATA in minidom

2014-02-23 Thread Artur R. Czechowski

Artur R. Czechowski added the comment:

Martin, the exact information you need are:

1. this is what I did:

#!/usr/bin/env python
import unittest
import xmlrunner

class Foo(unittest.TestCase):
def testFoo(self):
self.assertTrue(False, ']]>')

unittest.main(testRunner=xmlrunner.XMLTestRunner(output='test-reports'))

2. this is what happened:
arturcz@szczaw:/tmp$ ./cdata.py 

Running tests...
--
F
==
FAIL [0.000s]: testFoo (__main__.Foo)
--
Traceback (most recent call last):
  File "./cdata.py", line 7, in testFoo
self.assertTrue(False, ']]>')
AssertionError: ]]>

--
Ran 1 test in 0.001s

FAILED (failures=1)

Generating XML reports...
Traceback (most recent call last):
  File "./cdata.py", line 9, in 
unittest.main(testRunner=xmlrunner.XMLTestRunner(output='test-reports'))
  File "/usr/lib/python2.7/unittest/main.py", line 95, in __init__
self.runTests()
  File "/usr/lib/python2.7/unittest/main.py", line 232, in runTests
self.result = testRunner.run(self.test)
  File "/usr/lib/python2.7/dist-packages/xmlrunner/__init__.py", line 415, in 
run
result.generate_reports(self)
  File "/usr/lib/python2.7/dist-packages/xmlrunner/__init__.py", line 312, in 
generate_reports
xml_content = doc.toprettyxml(indent='\t')
  File "/usr/lib/python2.7/xml/dom/minidom.py", line 58, in toprettyxml
self.writexml(writer, "", indent, newl, encoding)
  File "/usr/lib/python2.7/xml/dom/minidom.py", line 1749, in writexml
node.writexml(writer, indent, addindent, newl)
  File "/usr/lib/python2.7/xml/dom/minidom.py", line 814, in writexml
node.writexml(writer, indent+addindent, addindent, newl)
  File "/usr/lib/python2.7/xml/dom/minidom.py", line 814, in writexml
node.writexml(writer, indent+addindent, addindent, newl)
  File "/usr/lib/python2.7/xml/dom/minidom.py", line 814, in writexml
node.writexml(writer, indent+addindent, addindent, newl)
  File "/usr/lib/python2.7/xml/dom/minidom.py", line 1150, in writexml
raise ValueError("']]>' not allowed in a CDATA section")
ValueError: ']]>' not allowed in a CDATA section

and empty directory test-reports has been created.

3. this is what should have happened instead:
arturcz@szczaw:/tmp$ ./cdata.py 

Running tests...
--
F
==
FAIL [0.000s]: testFoo (__main__.Foo)
--
Traceback (most recent call last):
  File "./cdata.py", line 7, in testFoo
self.assertTrue(False, ']]>')
AssertionError: ]]>

--
Ran 1 test in 0.001s

FAILED (failures=1)

Generating XML reports...

and file test-reports/TEST-Foo-${timestamp}.xml is created with following 
content:




 







however, on the level of minidom.py module, there is an exact test provided in 
attached repository.

PS. I removed the patch by purpose - it's wrong and someone could be misleaded 
by it. The correct solution I propose is in the attached repository.

--

___
Python tracker 
<http://bugs.python.org/issue20714>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue20714] Allow for ]]> in CDATA in minidom

2014-02-23 Thread Artur R. Czechowski

Artur R. Czechowski added the comment:

Martin,
I partially agree with you.
After rethinking the issue I agree that changing the behavior of 
createCDATASection maybe is not a good idea.
On the other hand anyone in need of adding ]]> into CDATA must write a few 
lines of code, which will be essentially the same for each application. This 
part of code could be embedded into minidom module and it could be provided to 
each needing party. Please consider extending the interface of minidom module 
with method creating CDATA sections regardless of the provided data, splitting 
it into two CDATA if necessary.

If you disagree, feel free to close this issue.

--

___
Python tracker 
<http://bugs.python.org/issue20714>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com