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

make minidom.toxml() encoding argument useful #47325

Closed
janssen mannequin opened this issue Jun 10, 2008 · 5 comments
Closed

make minidom.toxml() encoding argument useful #47325

janssen mannequin opened this issue Jun 10, 2008 · 5 comments
Labels
easy stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@janssen
Copy link
Mannequin

janssen mannequin commented Jun 10, 2008

BPO 3075
Nosy @merwok

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 2010-08-08.09:38:24.677>
created_at = <Date 2008-06-10.18:12:01.869>
labels = ['easy', 'type-feature', 'library']
title = 'make minidom.toxml() encoding argument useful'
updated_at = <Date 2010-08-08.09:38:24.676>
user = 'https://bugs.python.org/janssen'

bugs.python.org fields:

activity = <Date 2010-08-08.09:38:24.676>
actor = 'BreamoreBoy'
assignee = 'none'
closed = True
closed_date = <Date 2010-08-08.09:38:24.677>
closer = 'BreamoreBoy'
components = ['Library (Lib)']
creation = <Date 2008-06-10.18:12:01.869>
creator = 'janssen'
dependencies = []
files = []
hgrepos = []
issue_num = 3075
keywords = ['easy']
message_count = 5.0
messages = ['67909', '67910', '107649', '111607', '113244']
nosy_count = 3.0
nosy_names = ['janssen', 'eric.araujo', 'BreamoreBoy']
pr_nums = []
priority = 'normal'
resolution = 'out of date'
stage = None
status = 'closed'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue3075'
versions = ['Python 3.2']

@janssen
Copy link
Mannequin Author

janssen mannequin commented Jun 10, 2008

Right now, the encoding argument added to
xml.dom.minidom.DOMObject.toxml() in Python 2.3 seems fairly useless.
It has to be UTF-8. But a one-line change to the implementation of
toprettyxml would make it useful; instead of the encoding error method
being "strict", make it "xmlcharrefreplace". So change

    writer = codecs.lookup(encoding)[3](writer)

to

    writer = codecs.lookup(encoding)[3](writer, "xmlcharrefreplace")

@janssen janssen mannequin added stdlib Python modules in the Lib dir easy labels Jun 10, 2008
@janssen
Copy link
Mannequin Author

janssen mannequin commented Jun 10, 2008

The method "toxml" is actually on xml.dom.minidom.Node.

@janssen janssen mannequin added the type-feature A feature request or enhancement label Jun 10, 2008
@merwok
Copy link
Member

merwok commented Jun 12, 2010

Is this still relevant for 3.2?

@BreamoreBoy
Copy link
Mannequin

BreamoreBoy mannequin commented Jul 26, 2010

This is how toprettyxml looks in 3.1/2 which seems to meet the OP's need, I'll close in a few days time unless someone objects.

def toprettyxml(self, indent="\t", newl="\n", encoding=None):
    # indent = the indentation string to prepend, per level
    # newl = the newline string to append
    use_encoding = "utf-8" if encoding is None else encoding
    writer = codecs.getwriter(use_encoding)(io.BytesIO())
    if self.nodeType == Node.DOCUMENT_NODE:
        # Can pass encoding only to document, to put it into XML header
        self.writexml(writer, "", indent, newl, encoding)
    else:
        self.writexml(writer, "", indent, newl)
    if encoding is None:
        return writer.stream.getvalue().decode(use_encoding)
    else:
        return writer.stream.getvalue()

@BreamoreBoy
Copy link
Mannequin

BreamoreBoy mannequin commented Aug 8, 2010

Closing as no response to msg111607.

@BreamoreBoy BreamoreBoy mannequin closed this as completed Aug 8, 2010
@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
easy stdlib Python modules in the Lib dir type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

1 participant