Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add default_namespace argument to xml.etree.ElementTree.tostring() #80408

Closed
codeape2 mannequin opened this issue Mar 7, 2019 · 9 comments
Closed

Add default_namespace argument to xml.etree.ElementTree.tostring() #80408

codeape2 mannequin opened this issue Mar 7, 2019 · 9 comments
Labels
3.8 only security fixes stdlib Python modules in the Lib dir topic-XML type-feature A feature request or enhancement

Comments

@codeape2
Copy link
Mannequin

codeape2 mannequin commented Mar 7, 2019

BPO 36227
Nosy @scoder, @codeape2, @serhiy-storchaka
PRs
  • bpo-36227: ElementTree.tostring() default_namespace argument #12225
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2019-04-14.08:16:04.080>
    created_at = <Date 2019-03-07.18:57:14.191>
    labels = ['expert-XML', '3.8', 'type-feature', 'library']
    title = 'Add default_namespace argument to xml.etree.ElementTree.tostring()'
    updated_at = <Date 2019-04-14.08:16:04.070>
    user = 'https://github.com/codeape2'

    bugs.python.org fields:

    activity = <Date 2019-04-14.08:16:04.070>
    actor = 'scoder'
    assignee = 'none'
    closed = True
    closed_date = <Date 2019-04-14.08:16:04.080>
    closer = 'scoder'
    components = ['Library (Lib)', 'XML']
    creation = <Date 2019-03-07.18:57:14.191>
    creator = 'Bernt.R\xc3\xb8skar.Brenna'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 36227
    keywords = ['patch']
    message_count = 9.0
    messages = ['337428', '337455', '337456', '337458', '337460', '337473', '337478', '340190', '340193']
    nosy_count = 4.0
    nosy_names = ['scoder', 'eli.bendersky', 'Bernt.R\xc3\xb8skar.Brenna', 'serhiy.storchaka']
    pr_nums = ['12225']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue36227'
    versions = ['Python 3.8']

    @codeape2
    Copy link
    Mannequin Author

    codeape2 mannequin commented Mar 7, 2019

    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.

    @codeape2 codeape2 mannequin added 3.8 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Mar 7, 2019
    @scoder
    Copy link
    Contributor

    scoder commented Mar 8, 2019

    The feature seems reasonable to me and the patch looks good.

    @serhiy-storchaka
    Copy link
    Member

    See also bpo-31256.

    I do not know what is better: make tostring() to accept all options of write(), or keep it simpler. What strategy lxml supports?

    @scoder
    Copy link
    Contributor

    scoder commented Mar 8, 2019

    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.

    @serhiy-storchaka
    Copy link
    Member

    Okay. Bernt, do you mind to add also the xml_declaration option in PR 12225 or create a separate PR for bpo-31256?

    @codeape2
    Copy link
    Mannequin Author

    codeape2 mannequin commented Mar 8, 2019

    I will add xml_declaration and push to the existing PR.

    @codeape2
    Copy link
    Mannequin Author

    codeape2 mannequin commented Mar 8, 2019

    I pushed changes to the PR. I also added xml_declaration and default_namespace to the tostringlist() method.

    @scoder
    Copy link
    Contributor

    scoder commented Apr 14, 2019

    New changeset ffca16e by Stefan Behnel (Bernt Røskar Brenna) in branch 'master':
    bpo-36227: ElementTree.tostring() default_namespace and xml_declaration arguments (GH-12225)
    ffca16e

    @scoder
    Copy link
    Contributor

    scoder commented Apr 14, 2019

    Thank you for you contribution.

    @scoder scoder closed this as completed Apr 14, 2019
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.8 only security fixes stdlib Python modules in the Lib dir topic-XML type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants