X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=wrw%2Fsp%2Fxhtml.py;h=a2c1eb1160ae9daa1ee737b9fe1b22796d24c9d0;hb=0d4c1b8b8da9e20c4bc9fb41ff1136283821b98e;hp=eb82f5736c6948e2eb1961c33177f13054b661ca;hpb=b0f95b219e2f9aea9f81d696adbfaaa0e41a6eaf;p=wrw.git diff --git a/wrw/sp/xhtml.py b/wrw/sp/xhtml.py index eb82f57..a2c1eb1 100644 --- a/wrw/sp/xhtml.py +++ b/wrw/sp/xhtml.py @@ -1,11 +1,11 @@ -import xml.dom.minidom, io -from . import cons as _cons -from . import util +import xml.dom.minidom, StringIO +import cons as _cons +import util dom = xml.dom.minidom.getDOMImplementation() -ns = "http://www.w3.org/1999/xhtml" -doctype = "-//W3C//DTD XHTML 1.1//EN" -dtd = "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" +ns = u"http://www.w3.org/1999/xhtml" +doctype = u"-//W3C//DTD XHTML 1.1//EN" +dtd = u"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" class htmlelement(_cons.element): def __todoc__(self): @@ -15,11 +15,11 @@ class htmlelement(_cons.element): return doc class xhtmlcontext(_cons.context): - attrmap = {"klass": "class"} + attrmap = {u"klass": u"class"} def addattr(self, node, k, v): - k = str(k) - super().addattr(node, self.attrmap.get(k, k), v) + k = unicode(k) + super(xhtmlcontext, self).addattr(node, self.attrmap.get(k, k), v) def cons(ctx=None): if ctx is None: ctx = xhtmlcontext() @@ -30,7 +30,7 @@ def head(title=None, css=None): head = h.head if title: head(h.title(title)) - if isinstance(css, str) or isinstance(css, bytes): + if isinstance(css, str) or isinstance(css, unicode): head(h.link(rel="stylesheet", type="text/css", href=css)) elif css: for ss in css: @@ -38,10 +38,10 @@ def head(title=None, css=None): return head class htmlformatter(util.formatter): - allowshort = {"br", "hr", "img", "input", "meta", "link"} + allowshort = set([u"br", u"hr", u"img", u"input", u"meta", u"link"]) def shorttag(self, el): if el.name in self.allowshort: - super().shorttag(el) + super(htmlformatter, self).shorttag(el) else: self.handle(">", el) self.handle("<", el) @@ -52,7 +52,7 @@ class htmlindenter(util.textindenter, htmlformatter): def forreq(req, tree): # XXX: Use proper Content-Type for clients accepting it. req.ohead["Content-Type"] = "text/html; charset=utf-8" - buf = io.BytesIO() + buf = StringIO.StringIO() htmlindenter.output(buf, tree, doctype=(doctype, dtd), charset="utf-8") ret = buf.getvalue() req.ohead["Content-Length"] = len(ret)