aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_utils.py
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2011-02-06 14:17:30 +1300
committerAldo Cortesi <aldo@nullcube.com>2011-02-06 14:17:30 +1300
commit7156d1a73ab6ce39ae8f8325bc8a62c0083cd054 (patch)
tree42baa74035d979deb122632a3e46b44ff0f08cf1 /test/test_utils.py
parent44dc3a052e724bdf10e9c04e1756db89615f5685 (diff)
downloadmitmproxy-7156d1a73ab6ce39ae8f8325bc8a62c0083cd054.tar.gz
mitmproxy-7156d1a73ab6ce39ae8f8325bc8a62c0083cd054.tar.bz2
mitmproxy-7156d1a73ab6ce39ae8f8325bc8a62c0083cd054.zip
Rip out BeautifulSoup, and use a custom XML-ish prettyprinter.
Diffstat (limited to 'test/test_utils.py')
-rw-r--r--test/test_utils.py60
1 files changed, 53 insertions, 7 deletions
diff --git a/test/test_utils.py b/test/test_utils.py
index 325664a4..1ec4f2f5 100644
--- a/test/test_utils.py
+++ b/test/test_utils.py
@@ -1,4 +1,4 @@
-import textwrap, cStringIO, os, time
+import textwrap, cStringIO, os, time, re
import libpry
from libmproxy import utils
@@ -228,13 +228,59 @@ class umake_bogus_cert(libpry.AutoTree):
assert "CERTIFICATE" in d
-class uprettybody(libpry.AutoTree):
+class upretty_xmlish(libpry.AutoTree):
+ def test_tagre(self):
+ def f(s):
+ return re.search(utils.TAG, s, re.VERBOSE|re.MULTILINE)
+ assert f(r"<body>")
+ assert f(r"<body/>")
+ assert f(r"< body/>")
+ assert f(r"< body/ >")
+ assert f(r"< body / >")
+ assert f(r"<foo a=b>")
+ assert f(r"<foo a='b'>")
+ assert f(r"<foo a='b\"'>")
+ assert f(r'<a b=(a.b) href="foo">')
+ assert f('<td width=25%>')
+
def test_all(self):
- s = "<html><p></p></html>"
- assert utils.prettybody(s)
+ def isbalanced(ret):
+ # The last tag should have no indent
+ assert ret[-1].strip() == ret[-1]
+
+ s = "<html><br><br></br><p>one</p></html>"
+ ret = utils.pretty_xmlish(s)
+ isbalanced(ret)
+
+ s = r"""
+<body bgcolor=#ffffff text=#000000 link=#0000cc vlink=#551a8b alink=#ff0000 onload="document.f.q.focus();if(document.images)new Image().src='/images/srpr/nav_logo27.png'" ><textarea id=csi style=display:none></textarea></body>
+ """
+ isbalanced(utils.pretty_xmlish(textwrap.dedent(s)))
+
+ s = r"""
+ <a href="http://foo.com" target="">
+ <img src="http://foo.gif" alt="bar" height="25" width="132">
+ </a>
+ """
+ isbalanced(utils.pretty_xmlish(textwrap.dedent(s)))
+
+ s = r"""
+ <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
+ \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
+ <html></html>
+ """
+ ret = utils.pretty_xmlish(textwrap.dedent(s))
+ isbalanced(ret)
+
+ s = "<html><br/><p>one</p></html>"
+ ret = utils.pretty_xmlish(s)
+ assert len(ret) == 6
+ isbalanced(ret)
+
+ s = "gobbledygook"
+ print utils.pretty_xmlish(s)
+
- s = "".join([chr(i) for i in range(256)])
- assert utils.prettybody(s)
@@ -249,5 +295,5 @@ tests = [
uMultiDict(),
uHeaders(),
uData(),
- uprettybody(),
+ upretty_xmlish(),
]