Issue2413
Created on 2015-10-21.08:45:50 by pekka.klarck, last changed 2016-09-14.16:15:37 by zyasoft.
msg10367 (view) |
Author: Pekka Klärck (pekka.klarck) |
Date: 2015-10-21.08:45:49 |
|
This seems to be a variation of #1479. To reproduce:
E:\>jython
Jython 2.7.0 (default:9987c746f838, Apr 29 2015, 02:25:11)
[Java HotSpot(TM) Client VM (Oracle Corporation)] on java1.8.0_60
Type "help", "copyright", "credits" or "license" for more information.
>>> from xml.etree import ElementTree as ET
>>> elem = ET.XML('<test/>')
>>> tree = ET.ElementTree(elem)
>>> tree.write('test.xml', encoding='blaaaah')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\jython2.7.0\Lib\xml\etree\ElementTree.py", line 818, in write
qnames, namespaces = _namespaces(
File "C:\jython2.7.0\Lib\xml\etree\ElementTree.py", line 886, in _namespaces
add_qname(tag)
File "C:\jython2.7.0\Lib\xml\etree\ElementTree.py", line 870, in add_qname
qnames[qname] = encode(qname)
File "C:\jython2.7.0\Lib\xml\etree\ElementTree.py", line 870, in add_qname
qnames[qname] = encode(qname)
File "C:\jython2.7.0\Lib\xml\etree\ElementTree.py", line 845, in encode
return text.encode(encoding)
LookupError: unknown encoding 'blaaaah'
>>> import os
>>> os.remove('test.xml')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OSError: unlink(): an unknown error occurred: E:\test.xml
A workaround is opening and closing output files explicitly:
with open('test.xml', 'wb') as output:
tree.write(output, ...)
|
msg10368 (view) |
Author: Jim Baker (zyasoft) |
Date: 2015-10-21.21:29:18 |
|
The fix is more or less the workaround Peke identified; in https://github.com/jythontools/jython/blob/master/lib-python/2.7/xml/etree/ElementTree.py#L789 which defines the write method, opened files must always be closed via a finally. I assume this never came up on non refcounted systems, and presumably it could be also a bug in PyPy today for example. Adding Phil...
It is not fixed in current CPython 2.7 source:
https://github.com/python/cpython/blob/2.7/Lib/xml/etree/ElementTree.py#L787
|
msg10371 (view) |
Author: Pekka Klärck (pekka.klarck) |
Date: 2015-10-22.21:17:05 |
|
Yeah, I would assume the same bug appears everywhere that uses CPython ElementTree but doesn't have refcounting GC. It is obviously pretty minor compared to #1479. I only noticed it because we had a test for invalid encoding and subsequent tests started to fail.
|
msg10372 (view) |
Author: Philip Jenvey (pjenvey) |
Date: 2015-10-22.21:25:34 |
|
Yup. The other fix was applied to CPython's Lib, so this one should definitely be fixed over there too
|
msg10385 (view) |
Author: Jim Baker (zyasoft) |
Date: 2015-10-26.20:41:38 |
|
Phil, are we still seeing updates against CPython 2.7 that are not security related? We haven't bothered sending updates to upstream for quite a while in Jython 2.7, because that's been our assumption.
|
msg10408 (view) |
Author: Jim Baker (zyasoft) |
Date: 2015-10-29.22:32:19 |
|
Let's see if we can get this fixed for 2.7.1, it is pretty easy to do so. We can look at upstreaming later.
|
msg10710 (view) |
Author: Jim Baker (zyasoft) |
Date: 2016-02-03.20:15:37 |
|
Fix now the xml stdlib has been updated (#2124). Just requires a minimal patch of course.
|
msg10724 (view) |
Author: Jim Baker (zyasoft) |
Date: 2016-02-05.16:08:26 |
|
Target RC
|
msg10927 (view) |
Author: Jeff Allen (jeff.allen) |
Date: 2016-09-02.18:51:16 |
|
I'll take, as you've made it so easy.
|
msg10930 (view) |
Author: Jeff Allen (jeff.allen) |
Date: 2016-09-03.08:52:09 |
|
Not quite so easy. Well, this particular bug is ok, but in attempting to add a doctest to test_xml_etree_jy, I find that quite a few other tests also fail. We'll handle those separately in #2518.
Stepping out of the time machine in 2009, it's the same :(
|
msg10934 (view) |
Author: Jim Baker (zyasoft) |
Date: 2016-09-05.16:27:13 |
|
Fixed as of https://hg.python.org/jython/rev/c168765aae66
But at least a fair number of gains since 2009, even if the progress is incremental. Hopefully Jython 3 will get us closer to the front and really seeing these fixes pushed up.
|
|
Date |
User |
Action |
Args |
2016-09-14 16:15:37 | zyasoft | set | status: pending -> closed |
2016-09-05 16:27:14 | zyasoft | set | status: open -> pending resolution: accepted -> fixed messages:
+ msg10934 |
2016-09-03 08:52:09 | jeff.allen | set | messages:
+ msg10930 |
2016-09-02 18:51:16 | jeff.allen | set | versions:
+ Jython 2.7 nosy:
+ jeff.allen messages:
+ msg10927 assignee: jeff.allen components:
+ Library type: behaviour resolution: accepted |
2016-02-18 21:35:07 | zyasoft | set | priority: high -> normal |
2016-02-05 16:08:26 | zyasoft | set | priority: normal -> high messages:
+ msg10724 |
2016-02-03 20:15:37 | zyasoft | set | messages:
+ msg10710 |
2015-12-30 00:11:50 | zyasoft | set | title: ElemetTree.write doesn't close files if used with invalid encoding -> ElementTree.write doesn't close files if used with invalid encoding |
2015-12-30 00:02:10 | zyasoft | set | priority: normal |
2015-10-29 22:32:19 | zyasoft | set | messages:
+ msg10408 milestone: Jython 2.7.1 |
2015-10-26 20:41:38 | zyasoft | set | messages:
+ msg10385 |
2015-10-22 21:25:34 | pjenvey | set | messages:
+ msg10372 |
2015-10-22 21:17:05 | pekka.klarck | set | messages:
+ msg10371 |
2015-10-21 21:29:19 | zyasoft | set | nosy:
+ pjenvey, zyasoft messages:
+ msg10368 |
2015-10-21 08:45:50 | pekka.klarck | create | |
|