diff --git a/Lib/xml/etree/ElementTree.py b/Lib/xml/etree/ElementTree.py index ce67d7d7d54748..32a6ecd2dd2d50 100644 --- a/Lib/xml/etree/ElementTree.py +++ b/Lib/xml/etree/ElementTree.py @@ -679,6 +679,7 @@ def iterfind(self, path, namespaces=None): def write(self, file_or_filename, encoding=None, xml_declaration=None, + xml_declaration_definition='', default_namespace=None, method=None, *, short_empty_elements=True): @@ -694,6 +695,14 @@ def write(self, file_or_filename, is added if encoding IS NOT either of: US-ASCII, UTF-8, or Unicode + *xml_declaration_definition* -- string for customizing encoding declaration + as documentation always shows doublequotes but + singlequote where hardcoded here. + to be rfc conform which allows doublequotes and + singlequote for declaration. default value is + switched to doublquotes here to stay on one format. + placeholders: {version}, {encoding} + *default_namespace* -- sets the default XML namespace (for "xmlns") *method* -- either "xml" (default), "html, "text", or "c14n" @@ -719,8 +728,10 @@ def write(self, file_or_filename, (xml_declaration is None and encoding.lower() != "unicode" and declared_encoding.lower() not in ("utf-8", "us-ascii"))): - write("\n" % ( - declared_encoding,)) + # version configuration is'nt necessary, can be overwritten + # in declaration_definition at runtime + data = {'version':'1.0', 'encoding': declared_encoding} + write(xml_declaration_definition.format(**data)+"\n") if method == "text": _serialize_text(write, self._root) else: