X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=wrw%2Fsp%2Fxhtml.py;h=73872b45b1641727d97967bfee731e7e504a7e67;hb=919b8a4ff35da1fce73f238754ef376705c52e18;hp=02e8dd666ed2656730c85688a6a3c007b6aa54e0;hpb=ab92e396057cd617b1607f437d860ff89f5780a2;p=wrw.git diff --git a/wrw/sp/xhtml.py b/wrw/sp/xhtml.py index 02e8dd6..73872b4 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) + super().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): @@ -30,14 +38,15 @@ def head(title=None, css=None): return head class htmlformatter(util.formatter): - allowshort = set(["br", "hr", "img", "input"]) - def element(self, el, **extra): + allowshort = {"br", "hr", "img", "input", "meta", "link"} + def shorttag(self, el): if el.name in self.allowshort: - super(htmlformatter, self).element(el, **extra) + super().shorttag(el) else: - self.longtag(el, **extra) + self.starttag(el) + self.endtag(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 = 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