Eli Bendersky added the comment:
Finally found time to look at this, sorry for the delay.
I agree with Amaury, and don't think any change is necessary in 2.7, the
behavior there is quite consistent with what was usually done in 2.x. For
porting or keeping the code 2/3 compatible, Amaury's
New submission from David Buxton:
The problem is an inconsistency between the ElementTree.write() method on
Python 2 and 3 when xml_declaration is True. For Python 2.7 the encoding
argument MUST NOT be a unicode string. For Python 3.2 the encoding argument
MUST be a unicode string.
On Python
Changes by Florent Xicluna florent.xicl...@gmail.com:
--
components: +Library (Lib)
nosy: +eli.bendersky, flox
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue15811
___
David Buxton added the comment:
A patch against the current default branch to add tests for the xml_declaration
keyword argument. This passes when applied to the 2.7 branch too.
This does NOT test whether one can use both bytes/unicode for the encoding
argument. It just uses the native string
Eli Bendersky added the comment:
Thanks for the patch, David.
Alas, due to personal reasons I will not be able to work on core Python in the
next 2-3 months. I may throw in a review here and there, but that's not a
promise ;-)
--
___
Python
Amaury Forgeot d'Arc added the comment:
Why is it a problem? Encoding must be a text string:
encoding='utf-8'
works with both Python 2 and 3.
Or if you used from __future__ import unicode_literals,
str('utf-8')
works as well.
--
nosy: +amaury.forgeotdarc
David Buxton added the comment:
Only a problem because I am using unicode_literals and it didn't occur to me to
use `str('utf-8')` to get a native string on both 2+3. Much the best solution,
thank you.
But that is still a little smelly - I think what I want ideally is for
ElementTree to