| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 47e2175 commit 8420052
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -933,13 +933,15 @@ def test_tostring_xml_declaration_cases(self): | |||
| 933 | 933 | (b"<?xml version='1.0' encoding='ISO-8859-1'?>\n" | |
| 934 | 934 | b"<body><tag>\xf8</tag></body>", 'ISO-8859-1', None), | |
| 935 | 935 | ('<body><tag>ø</tag></body>', 'unicode', None), | |
| 936 | + (b"\xef\xbb\xbf<body><tag>\xc3\xb8</tag></body>", 'utf-8-sig', None), | ||
| 936 | 937 | ||
| 937 | 938 | # ... xml_declaration = False | |
| 938 | 939 | (b"<body><tag>ø</tag></body>", None, False), | |
| 939 | 940 | (b"<body><tag>\xc3\xb8</tag></body>", 'UTF-8', False), | |
| 940 | 941 | (b"<body><tag>ø</tag></body>", 'US-ASCII', False), | |
| 941 | 942 | (b"<body><tag>\xf8</tag></body>", 'ISO-8859-1', False), | |
| 942 | 943 | ("<body><tag>ø</tag></body>", 'unicode', False), | |
| 944 | + (b"\xef\xbb\xbf<body><tag>\xc3\xb8</tag></body>", 'utf-8-sig', False), | ||
| 943 | 945 | ||
| 944 | 946 | # ... xml_declaration = True | |
| 945 | 947 | (b"<?xml version='1.0' encoding='us-ascii'?>\n" | |
@@ -952,6 +954,8 @@ def test_tostring_xml_declaration_cases(self): | |||
| 952 | 954 | b"<body><tag>\xf8</tag></body>", 'ISO-8859-1', True), | |
| 953 | 955 | ("<?xml version='1.0' encoding='utf-8'?>\n" | |
| 954 | 956 | "<body><tag>ø</tag></body>", 'unicode', True), | |
| 957 | + (b"\xef\xbb\xbf<?xml version='1.0' encoding='utf-8'?>\n" | ||
| 958 | + b"<body><tag>\xc3\xb8</tag></body>", 'utf-8-sig', True), | ||
| 955 | 959 | ||
| 956 | 960 | ] | |
| 957 | 961 | for expected_retval, encoding, xml_declaration in TESTCASES: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -732,6 +732,8 @@ def write(self, file_or_filename, | |||
| 732 | 732 | if not encoding: | |
| 733 | 733 | encoding = "us-ascii" | |
| 734 | 734 | with _get_writer(file_or_filename, encoding) as (write, declared_encoding): | |
| 735 | + if declared_encoding.lower() == "utf-8-sig": | ||
| 736 | + declared_encoding = "utf-8" | ||
| 735 | 737 | if method == "xml" and (xml_declaration or | |
| 736 | 738 | (xml_declaration is None and | |
| 737 | 739 | encoding.lower() != "unicode" and | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,2 @@ | |||
| 1 | + :meth:`xml.etree.ElementTree.ElementTree.write` now treats the ``utf-8-sig`` | ||
| 2 | + encoding as ``utf-8`` in the XML declaration. | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments