Issue 36227: Add default_namespace argument to xml.etree.ElementTree.tostring() (original ) (raw ) This issue has been migrated to GitHub: https://github.com/python/cpython/issues/80408
classification
process
Created on 2019-03-07 18:57 by Bernt.Røskar.Brenna , last changed 2022-04-11 14:59 by admin . This issue is now closed .
Pull Requests
URL
Status
Linked
Edit
PR 12225
merged
Bernt.Røskar.Brenna,2019-03-07 19:10
Messages (9)
msg337428 - (view)
Author: Bernt Røskar Brenna (Bernt.Røskar.Brenna) *
Date: 2019-03-07 18:57
default_namespace is often used when serializing ET elements. tostring() is mainly a wrapper around ElementTree.write(), and it is therefore natural that it mirrors write's argument. tostring() already passes encoding, method and short_empty_elements to write.
msg337455 - (view)
Author: Stefan Behnel (scoder) *
Date: 2019-03-08 08:37
The feature seems reasonable to me and the patch looks good.
msg337456 - (view)
Author: Serhiy Storchaka (serhiy.storchaka) *
Date: 2019-03-08 08:50
See also . I do not know what is better: make tostring() to accept all options of write(), or keep it simpler. What strategy lxml supports?
msg337458 - (view)
Author: Stefan Behnel (scoder) *
Date: 2019-03-08 08:58
lxml does not support the "default_namespace" option specifically (because its tree model preserves namespace prefixes), but it generally makes all (justifiable) serialisation options available to both tostring() and ET.write(). I think the same should apply to ElementTree. Both the "default_namespace" and "doctype" options seem useful regardless of the serialisation target.
msg337460 - (view)
Author: Serhiy Storchaka (serhiy.storchaka) *
Date: 2019-03-08 09:51
Okay. Bernt, do you mind to add also the xml_declaration option in PR 12225 or create a separate PR for ?
msg337473 - (view)
Author: Bernt Røskar Brenna (Bernt.Røskar.Brenna) *
Date: 2019-03-08 13:28
I will add xml_declaration and push to the existing PR.
msg337478 - (view)
Author: Bernt Røskar Brenna (Bernt.Røskar.Brenna) *
Date: 2019-03-08 14:02
I pushed changes to the PR. I also added xml_declaration and default_namespace to the tostringlist() method.
msg340190 - (view)
Author: Stefan Behnel (scoder) *
Date: 2019-04-14 08:07
New changeset ffca16e25a70fd44a87b13b379b5ec0c7a11e926 by Stefan Behnel (Bernt Røskar Brenna) in branch 'master': bpo-36227 : ElementTree.tostring() default_namespace and xml_declaration arguments (GH-12225 ) https://github.com/python/cpython/commit/ffca16e25a70fd44a87b13b379b5ec0c7a11e926
msg340193 - (view)
Author: Stefan Behnel (scoder) *
Date: 2019-04-14 08:16
Thank you for you contribution.
History
Date
User
Action
Args
2022-04-11 14:59:12
admin
set
github: 80408
2019-04-14 08:16:04
scoder
set
status: open -> closedmessages: + components: + XMLresolution: fixedstage: patch review -> resolved
2019-04-14 08:07:16
scoder
set
messages: +
2019-03-08 14:02:12
Bernt.Røskar.Brenna
set
messages: +
2019-03-08 13:28:32
Bernt.Røskar.Brenna
set
messages: +
2019-03-08 09:51:18
serhiy.storchaka
set
messages: +
2019-03-08 08:58:56
scoder
set
messages: +
2019-03-08 08:50:51
serhiy.storchaka
set
messages: +
2019-03-08 08:37:57
scoder
set
messages: +
2019-03-08 03:06:25
xtreak
set
nosy: + scoder , eli.bendersky , serhiy.storchaka
2019-03-07 19:10:22
Bernt.Røskar.Brenna
set
keywords: + patch stage: patch reviewpull_requests: + <pull%5Frequest12215>
2019-03-07 18:57:14
Bernt.Røskar.Brenna
create