X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=wrw%2Fsp%2Fxhtml.py;h=e78d1972da005d7fca4d47bc6daa045d14bd6f3a;hb=7756066bff7ee01d615cbce0d5ddd58441108bd6;hp=abf4b965e83ac9e44139b7b6940dc9db3e3553cb;hpb=ff79cdbf7d4d95e6a84d6b002e28e6df86847954;p=wrw.git diff --git a/wrw/sp/xhtml.py b/wrw/sp/xhtml.py index abf4b96..e78d197 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 = {u"klass": u"class"} + + def addattr(self, node, k, v): + k = unicode(k) + node.attrs[self.attrmap.get(k, k)] = unicode(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([u"br", u"hr", u"img", u"input"]) + allowshort = set([u"br", u"hr", u"img", u"input", u"meta", u"link"]) def element(self, el, **extra): if el.name in self.allowshort: super(htmlformatter, self).element(el, **extra) @@ -45,9 +53,12 @@ def forreq(req, tree): req.ohead["Content-Type"] = "text/html; charset=utf-8" buf = StringIO.StringIO() 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