X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=wrw%2Fsp%2Fxhtml.py;h=5f1ca45eda7608e53a3f592283f474cf4fb2c334;hb=a9a78095b1696f56946abfc7c284f86a21fdcc2d;hp=70581382bd50f381d16074fe53e68c1c172644f2;hpb=625517699b4576f727b9cd81eb7053a0bc31e9b9;p=wrw.git diff --git a/wrw/sp/xhtml.py b/wrw/sp/xhtml.py index 7058138..5f1ca45 100644 --- a/wrw/sp/xhtml.py +++ b/wrw/sp/xhtml.py @@ -14,7 +14,15 @@ class htmlelement(_cons.element): doc.appendChild(self.__todom__(doc)) return doc +class xhtmlcontext(_cons.context): + attrmap = {"klass": "class"} + + def addattr(self, node, k, v): + k = str(k) + node.attrs[self.attrmap.get(k, k)] = str(v) + def cons(ctx=None): + if ctx is None: ctx = xhtmlcontext() return _cons.constructor(ns, htmlelement, ctx) def head(title=None, css=None): @@ -30,7 +38,7 @@ def head(title=None, css=None): return head class htmlformatter(util.formatter): - allowshort = set(["br", "hr", "img", "input"]) + allowshort = set(["br", "hr", "img", "input", "meta", "link"]) def element(self, el, **extra): if el.name in self.allowshort: super(htmlformatter, self).element(el, **extra) @@ -43,11 +51,14 @@ class htmlindenter(util.indenter, 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.StringIO() + buf = io.BytesIO() htmlindenter.output(buf, tree, doctype=(doctype, dtd), charset="utf-8") - return [buf.getvalue()] + ret = buf.getvalue() + req.ohead["Content-Length"] = len(ret) + return [ret] def xhtmlresp(callable): def wrapper(req): return forreq(req, callable(req)) + wrapper.__wrapped__ = callable return wrapper