Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(12)

Side by Side Diff: Lib/xml/etree/ElementTree.py

Issue 25047: xml.etree.ElementTree encoding declaration should be capital ('UTF-8') rather than lowercase ('utf-8')
Patch Set: Created 4 years, 6 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/test/test_xml_etree.py ('k') | Misc/NEWS » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 """Lightweight XML support for Python. 1 """Lightweight XML support for Python.
2 2
3 XML is an inherently hierarchical data format, and the most natural way to 3 XML is an inherently hierarchical data format, and the most natural way to
4 represent it is with a tree. This module has two classes for this purpose: 4 represent it is with a tree. This module has two classes for this purpose:
5 5
6 1. ElementTree represents the whole XML document as a tree and 6 1. ElementTree represents the whole XML document as a tree and
7 7
8 2. Element represents a single node in this tree. 8 2. Element represents a single node in this tree.
9 9
10 Interactions with the whole document (reading and writing to/from files) are 10 Interactions with the whole document (reading and writing to/from files) are
(...skipping 738 matching lines...) Expand 10 before | Expand all | Expand 10 after
749 """ 749 """
750 if not method: 750 if not method:
751 method = "xml" 751 method = "xml"
752 elif method not in _serialize: 752 elif method not in _serialize:
753 raise ValueError("unknown method %r" % method) 753 raise ValueError("unknown method %r" % method)
754 if not encoding: 754 if not encoding:
755 if method == "c14n": 755 if method == "c14n":
756 encoding = "utf-8" 756 encoding = "utf-8"
757 else: 757 else:
758 encoding = "us-ascii" 758 encoding = "us-ascii"
759 else: 759 enc_lower = encoding.lower()
760 encoding = encoding.lower() 760 with _get_writer(file_or_filename, enc_lower) as write:
761 with _get_writer(file_or_filename, encoding) as write:
762 if method == "xml" and (xml_declaration or 761 if method == "xml" and (xml_declaration or
763 (xml_declaration is None and 762 (xml_declaration is None and
764 encoding not in ("utf-8", "us-ascii", "unicode"))): 763 enc_lower not in ("utf-8", "us-ascii", "unicode"))):
765 declared_encoding = encoding 764 declared_encoding = encoding
766 if encoding == "unicode": 765 if enc_lower == "unicode":
767 # Retrieve the default encoding for the xml declaration 766 # Retrieve the default encoding for the xml declaration
768 import locale 767 import locale
769 declared_encoding = locale.getpreferredencoding() 768 declared_encoding = locale.getpreferredencoding()
770 write("<?xml version='1.0' encoding='%s'?>\n" % ( 769 write("<?xml version='1.0' encoding='%s'?>\n" % (
771 declared_encoding,)) 770 declared_encoding,))
772 if method == "text": 771 if method == "text":
773 _serialize_text(write, self._root) 772 _serialize_text(write, self._root)
774 else: 773 else:
775 qnames, namespaces = _namespaces(self._root, default_namespace) 774 qnames, namespaces = _namespaces(self._root, default_namespace)
776 serialize = _serialize[method] 775 serialize = _serialize[method]
(...skipping 881 matching lines...) Expand 10 before | Expand all | Expand 10 after
1658 try: 1657 try:
1659 # Element is going to be shadowed by the C implementation. We need to keep 1658 # Element is going to be shadowed by the C implementation. We need to keep
1660 # the Python version of it accessible for some "creative" by external code 1659 # the Python version of it accessible for some "creative" by external code
1661 # (see tests) 1660 # (see tests)
1662 _Element_Py = Element 1661 _Element_Py = Element
1663 1662
1664 # Element, SubElement, ParseError, TreeBuilder, XMLParser 1663 # Element, SubElement, ParseError, TreeBuilder, XMLParser
1665 from _elementtree import * 1664 from _elementtree import *
1666 except ImportError: 1665 except ImportError:
1667 pass 1666 pass
OLDNEW
« no previous file with comments | « Lib/test/test_xml_etree.py ('k') | Misc/NEWS » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+