Skip to content

Commit 8249938

Browse files
committed
Update xml from 3.13.7
1 parent a9a9e3b commit 8249938

File tree

14 files changed

+1056
-254
lines changed

14 files changed

+1056
-254
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import io
2+
import unittest
3+
from http import client
4+
from test.test_httplib import FakeSocket
5+
from unittest import mock
6+
from xml.dom import getDOMImplementation, minidom, xmlbuilder
7+
8+
SMALL_SAMPLE = b"""<?xml version="1.0"?>
9+
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xdc="http://www.xml.com/books">
10+
<!-- A comment -->
11+
<title>Introduction to XSL</title>
12+
<hr/>
13+
<p><xdc:author xdc:attrib="prefixed attribute" attrib="other attrib">A. Namespace</xdc:author></p>
14+
</html>"""
15+
16+
17+
class XMLBuilderTest(unittest.TestCase):
18+
def test_entity_resolver(self):
19+
body = (
20+
b"HTTP/1.1 200 OK\r\nContent-Type: text/xml; charset=utf-8\r\n\r\n"
21+
+ SMALL_SAMPLE
22+
)
23+
24+
sock = FakeSocket(body)
25+
response = client.HTTPResponse(sock)
26+
response.begin()
27+
attrs = {"open.return_value": response}
28+
opener = mock.Mock(**attrs)
29+
30+
resolver = xmlbuilder.DOMEntityResolver()
31+
32+
with mock.patch("urllib.request.build_opener") as mock_build:
33+
mock_build.return_value = opener
34+
source = resolver.resolveEntity(None, "http://example.com/2000/svg")
35+
36+
self.assertIsInstance(source, xmlbuilder.DOMInputSource)
37+
self.assertIsNone(source.publicId)
38+
self.assertEqual(source.systemId, "http://example.com/2000/svg")
39+
self.assertEqual(source.baseURI, "http://example.com/2000/")
40+
self.assertEqual(source.encoding, "utf-8")
41+
self.assertIs(source.byteStream, response)
42+
43+
self.assertIsNone(source.characterStream)
44+
self.assertIsNone(source.stringData)
45+
46+
def test_builder(self):
47+
imp = getDOMImplementation()
48+
self.assertIsInstance(imp, xmlbuilder.DOMImplementationLS)
49+
50+
builder = imp.createDOMBuilder(imp.MODE_SYNCHRONOUS, None)
51+
self.assertIsInstance(builder, xmlbuilder.DOMBuilder)
52+
53+
# TODO: RUSTPYTHON
54+
@unittest.expectedFailure
55+
def test_parse_uri(self):
56+
body = (
57+
b"HTTP/1.1 200 OK\r\nContent-Type: text/xml; charset=utf-8\r\n\r\n"
58+
+ SMALL_SAMPLE
59+
)
60+
61+
sock = FakeSocket(body)
62+
response = client.HTTPResponse(sock)
63+
response.begin()
64+
attrs = {"open.return_value": response}
65+
opener = mock.Mock(**attrs)
66+
67+
with mock.patch("urllib.request.build_opener") as mock_build:
68+
mock_build.return_value = opener
69+
70+
imp = getDOMImplementation()
71+
builder = imp.createDOMBuilder(imp.MODE_SYNCHRONOUS, None)
72+
document = builder.parseURI("http://example.com/2000/svg")
73+
74+
self.assertIsInstance(document, minidom.Document)
75+
self.assertEqual(len(document.childNodes), 1)
76+
77+
# TODO: RUSTPYTHON
78+
@unittest.expectedFailure
79+
def test_parse_with_systemId(self):
80+
response = io.BytesIO(SMALL_SAMPLE)
81+
82+
with mock.patch("urllib.request.urlopen") as mock_open:
83+
mock_open.return_value = response
84+
85+
imp = getDOMImplementation()
86+
source = imp.createDOMInputSource()
87+
builder = imp.createDOMBuilder(imp.MODE_SYNCHRONOUS, None)
88+
source.systemId = "http://example.com/2000/svg"
89+
document = builder.parse(source)
90+
91+
self.assertIsInstance(document, minidom.Document)
92+
self.assertEqual(len(document.childNodes), 1)

0 commit comments

Comments
 (0)