Uname:Linux mail.sarafai.ru 6.1.0-43-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.162-1 (2026-02-08) x86_64

403WebShell
403Webshell
Server IP : 82.148.16.210  /  Your IP : 216.73.216.19
Web Server : nginx/1.29.5
System : Linux mail.sarafai.ru 6.1.0-43-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.162-1 (2026-02-08) x86_64
User : root ( 0)
PHP Version : 7.4.33
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : OFF
Directory :  /usr/local/lib/python3.13/test/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /usr/local/lib/python3.13/test/test_xml_dom_xmlbuilder.py
import io
import unittest
from http import client
from test.test_httplib import FakeSocket
from unittest import mock
from xml.dom import getDOMImplementation, minidom, xmlbuilder

SMALL_SAMPLE = b"""<?xml version="1.0"?>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xdc="http://www.xml.com/books">
<!-- A comment -->
<title>Introduction to XSL</title>
<hr/>
<p><xdc:author xdc:attrib="prefixed attribute" attrib="other attrib">A. Namespace</xdc:author></p>
</html>"""


class XMLBuilderTest(unittest.TestCase):
    def test_entity_resolver(self):
        body = (
            b"HTTP/1.1 200 OK\r\nContent-Type: text/xml; charset=utf-8\r\n\r\n"
            + SMALL_SAMPLE
        )

        sock = FakeSocket(body)
        response = client.HTTPResponse(sock)
        response.begin()
        attrs = {"open.return_value": response}
        opener = mock.Mock(**attrs)

        resolver = xmlbuilder.DOMEntityResolver()

        with mock.patch("urllib.request.build_opener") as mock_build:
            mock_build.return_value = opener
            source = resolver.resolveEntity(None, "http://example.com/2000/svg")

        self.assertIsInstance(source, xmlbuilder.DOMInputSource)
        self.assertIsNone(source.publicId)
        self.assertEqual(source.systemId, "http://example.com/2000/svg")
        self.assertEqual(source.baseURI, "http://example.com/2000/")
        self.assertEqual(source.encoding, "utf-8")
        self.assertIs(source.byteStream, response)

        self.assertIsNone(source.characterStream)
        self.assertIsNone(source.stringData)

    def test_builder(self):
        imp = getDOMImplementation()
        self.assertIsInstance(imp, xmlbuilder.DOMImplementationLS)

        builder = imp.createDOMBuilder(imp.MODE_SYNCHRONOUS, None)
        self.assertIsInstance(builder, xmlbuilder.DOMBuilder)

    def test_parse_uri(self):
        body = (
            b"HTTP/1.1 200 OK\r\nContent-Type: text/xml; charset=utf-8\r\n\r\n"
            + SMALL_SAMPLE
        )

        sock = FakeSocket(body)
        response = client.HTTPResponse(sock)
        response.begin()
        attrs = {"open.return_value": response}
        opener = mock.Mock(**attrs)

        with mock.patch("urllib.request.build_opener") as mock_build:
            mock_build.return_value = opener

            imp = getDOMImplementation()
            builder = imp.createDOMBuilder(imp.MODE_SYNCHRONOUS, None)
            document = builder.parseURI("http://example.com/2000/svg")

        self.assertIsInstance(document, minidom.Document)
        self.assertEqual(len(document.childNodes), 1)

    def test_parse_with_systemId(self):
        response = io.BytesIO(SMALL_SAMPLE)

        with mock.patch("urllib.request.urlopen") as mock_open:
            mock_open.return_value = response

            imp = getDOMImplementation()
            source = imp.createDOMInputSource()
            builder = imp.createDOMBuilder(imp.MODE_SYNCHRONOUS, None)
            source.systemId = "http://example.com/2000/svg"
            document = builder.parse(source)

        self.assertIsInstance(document, minidom.Document)
        self.assertEqual(len(document.childNodes), 1)

Youez - 2016 - github.com/yon3zu
LinuXploit