1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-22 10:42:34 +01:00

remove 'text.clean_xml()'

was not used anywhere
This commit is contained in:
Mike Fährmann 2021-03-28 04:05:16 +02:00
parent 8553b218d9
commit 78fd63b8f0
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88
2 changed files with 0 additions and 44 deletions

View File

@ -13,29 +13,8 @@ import html
import datetime import datetime
import urllib.parse import urllib.parse
HTML_RE = re.compile("<[^>]+>") HTML_RE = re.compile("<[^>]+>")
INVALID_XML_CHARS = (
"\x00", "\x01", "\x02", "\x03", "\x04", "\x05", "\x06", "\x07",
"\x08", "\x0b", "\x0c", "\x0e", "\x0f", "\x10", "\x11", "\x12",
"\x13", "\x14", "\x15", "\x16", "\x17", "\x18", "\x19", "\x1a",
"\x1b", "\x1c", "\x1d", "\x1e", "\x1f",
)
def clean_xml(xmldata, repl=""):
"""Replace/Remove invalid control characters in 'xmldata'"""
if not isinstance(xmldata, str):
try:
xmldata = "".join(xmldata)
except TypeError:
return ""
for char in INVALID_XML_CHARS:
if char in xmldata:
xmldata = xmldata.replace(char, repl)
return xmldata
def remove_html(txt, repl=" ", sep=" "): def remove_html(txt, repl=" ", sep=" "):
"""Remove html-tags from a string""" """Remove html-tags from a string"""

View File

@ -23,29 +23,6 @@ INVALID_ALT = ((), [], {}, None, "")
class TestText(unittest.TestCase): class TestText(unittest.TestCase):
def test_clean_xml(self, f=text.clean_xml):
# standard usage
self.assertEqual(f(""), "")
self.assertEqual(f("foo"), "foo")
self.assertEqual(f("\tfoo\nbar\r"), "\tfoo\nbar\r")
self.assertEqual(f("<foo>\ab\ba\fr\v</foo>"), "<foo>bar</foo>")
# 'repl' argument
repl = "#"
self.assertEqual(f("", repl), "")
self.assertEqual(f("foo", repl), "foo")
self.assertEqual(f("\tfoo\nbar\r", repl), "\tfoo\nbar\r")
self.assertEqual(
f("<foo>\ab\ba\fr\v</foo>", repl), "<foo>#b#a#r#</foo>")
# removal of all illegal control characters
value = "".join(chr(x) for x in range(32))
self.assertEqual(f(value), "\t\n\r")
# 'invalid' arguments
for value in INVALID:
self.assertEqual(f(value), "")
def test_remove_html(self, f=text.remove_html): def test_remove_html(self, f=text.remove_html):
result = "Hello World." result = "Hello World."