XML/HTML pretty view tweaks.
This commit is contained in:
parent
f1dc3f2ab2
commit
a4f7728fad
|
@ -7,7 +7,7 @@ import common
|
|||
from .. import utils, encoding, flow
|
||||
from ..contrib import jsbeautifier
|
||||
|
||||
VIEW_CUTOFF = 1024*200
|
||||
VIEW_CUTOFF = 1024*100
|
||||
|
||||
VIEW_AUTO = 0
|
||||
VIEW_JSON = 1
|
||||
|
@ -126,7 +126,6 @@ def view_xml(hdrs, content):
|
|||
try:
|
||||
document = lxml.etree.fromstring(content, parser)
|
||||
except lxml.etree.XMLSyntaxError, v:
|
||||
print v
|
||||
return None
|
||||
docinfo = document.getroottree().docinfo
|
||||
|
||||
|
@ -138,12 +137,16 @@ def view_xml(hdrs, content):
|
|||
lxml.etree.tostring(p)
|
||||
)
|
||||
p = p.getprevious()
|
||||
doctype=docinfo.doctype
|
||||
if prev:
|
||||
doctype += "\n".join(prev).strip()
|
||||
doctype = doctype.strip()
|
||||
|
||||
s = lxml.etree.tostring(
|
||||
document,
|
||||
pretty_print=True,
|
||||
xml_declaration=True,
|
||||
doctype=docinfo.doctype + "\n".join(prev),
|
||||
doctype=doctype or None,
|
||||
encoding = docinfo.encoding
|
||||
)
|
||||
|
||||
|
@ -162,14 +165,7 @@ def view_html(hdrs, content):
|
|||
d = lxml.html.fromstring(content, parser=parser)
|
||||
docinfo = d.getroottree().docinfo
|
||||
s = lxml.etree.tostring(d, pretty_print=True, doctype=docinfo.doctype)
|
||||
|
||||
txt = []
|
||||
for i in s[:VIEW_CUTOFF].strip().split("\n"):
|
||||
txt.append(
|
||||
urwid.Text(("text", i)),
|
||||
)
|
||||
trailer(len(content), txt)
|
||||
return "HTML", txt
|
||||
return "HTML", _view_text(s[:VIEW_CUTOFF], len(s))
|
||||
|
||||
|
||||
def view_json(hdrs, content):
|
||||
|
|
|
@ -32,7 +32,7 @@ class uContentView(libpry.AutoTree):
|
|||
),
|
||||
"foo"
|
||||
)
|
||||
assert f is cv.view_xmlish
|
||||
assert f is cv.view_html
|
||||
|
||||
f = cv.get_view_func(
|
||||
cv.VIEW_AUTO,
|
||||
|
@ -50,7 +50,7 @@ class uContentView(libpry.AutoTree):
|
|||
),
|
||||
"<xml></xml>"
|
||||
)
|
||||
assert f is cv.view_xmlish
|
||||
assert f is cv.view_xml
|
||||
|
||||
def test_view_urlencoded(self):
|
||||
d = utils.urlencode([("one", "two"), ("three", "four")])
|
||||
|
@ -71,18 +71,17 @@ class uContentView(libpry.AutoTree):
|
|||
assert cv.view_json([], "[" + ",".join(["0"]*cv.VIEW_CUTOFF) + "]")
|
||||
|
||||
def test_view_xml(self):
|
||||
#assert cv.view_xml([], "<foo></foo>")
|
||||
#assert not cv.view_xml([], "<foo>")
|
||||
|
||||
assert cv.view_xml([], "<foo></foo>")
|
||||
assert not cv.view_xml([], "<foo>")
|
||||
s = """<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?xml-stylesheet title="XSL_formatting"?>
|
||||
<rss
|
||||
<rss
|
||||
xmlns:media="http://search.yahoo.com/mrss/"
|
||||
xmlns:atom="http://www.w3.org/2005/Atom"
|
||||
version="2.0">
|
||||
</rss>
|
||||
"""
|
||||
print cv.view_xml([], s)
|
||||
assert cv.view_xml([], s)
|
||||
|
||||
def test_view_raw(self):
|
||||
assert cv.view_raw([], "foo")
|
||||
|
@ -170,7 +169,7 @@ Larry
|
|||
encoding.encode('gzip', "[1, 2, 3]")
|
||||
)
|
||||
assert "decoded gzip" in r[0]
|
||||
assert "XML" in r[0]
|
||||
assert "Raw" in r[0]
|
||||
|
||||
|
||||
tests = [
|
||||
|
|
Loading…
Reference in New Issue