X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=wrw%2Fsp%2Fxhtml.py;h=a2c1eb1160ae9daa1ee737b9fe1b22796d24c9d0;hb=7e9080af248b38edec371f117eb4749b09a3caca;hp=928dcd9ab46db41d88d3810a257adec64aeb0495;hpb=d11a27e202a7c7a4698778e5f30bbe2c9f9a56fe;p=wrw.git diff --git a/wrw/sp/xhtml.py b/wrw/sp/xhtml.py index 928dcd9..a2c1eb1 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) + super(xhtmlcontext, self).addattr(node, self.attrmap.get(k, k), v) + def cons(ctx=None): + if ctx is None: ctx = xhtmlcontext() return _cons.constructor(ns, htmlelement, ctx) def head(title=None, css=None): @@ -31,13 +39,14 @@ def head(title=None, css=None): class htmlformatter(util.formatter): allowshort = set([u"br", u"hr", u"img", u"input", u"meta", u"link"]) - def element(self, el, **extra): + def shorttag(self, el): if el.name in self.allowshort: - super(htmlformatter, self).element(el, **extra) + super(htmlformatter, self).shorttag(el) else: - self.longtag(el, **extra) + self.handle(">", el) + self.handle("<", el) -class htmlindenter(util.indenter, htmlformatter): +class htmlindenter(util.textindenter, htmlformatter): pass def forreq(req, tree): @@ -45,9 +54,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