From: Fredrik Tolf Date: Wed, 5 Jun 2013 10:58:21 +0000 (+0200) Subject: Merge branch 'master' into python3 X-Git-Url: http://dolda2000.com/gitweb/?p=wrw.git;a=commitdiff_plain;h=3b67497cb853ea7dd49f579566e5f0b60a3c97d7;hp=-c Merge branch 'master' into python3 --- 3b67497cb853ea7dd49f579566e5f0b60a3c97d7 diff --combined wrw/resp.py index b62ce0e,a27a143..bdceb90 --- a/wrw/resp.py +++ b/wrw/resp.py @@@ -1,5 -1,5 +1,5 @@@ -import dispatch, proto, env -from sp import xhtml +from . import dispatch, proto, env +from .sp import xhtml h = xhtml.cons() __all__ = ["skeleton", "skelfor", "setskel", "usererror"] @@@ -28,7 -28,7 +28,7 @@@ def setskel(req, skel) class usererror(dispatch.restart): def __init__(self, message, *detail): - super(usererror, self).__init__() + super().__init__() self.message = message self.detail = detail @@@ -36,9 -36,9 +36,9 @@@ return skelfor(req).error(req, self.message, *self.detail) class message(dispatch.restart): - def __init__(self, msg, *detail): - super(message, self).__init__() - self.message = msg + def __init__(self, message, *detail): + super().__init__() + self.message = message self.detail = detail def handle(self, req): @@@ -50,24 -50,25 +50,25 @@@ class httperror(usererror) message = proto.statusinfo[status][0] if detail is None: detail = (proto.statusinfo[status][1],) - super(httperror, self).__init__(message, *detail) + super().__init__(message, *detail) self.status = status def handle(self, req): req.status(self.status, self.message) - return super(httperror, self).handle(req) + return super().handle(req) class notfound(httperror): def __init__(self): - return super(notfound, self).__init__(404) + return super().__init__(404) class redirect(dispatch.restart): def __init__(self, url, status = 303): - super(redirect, self).__init__() + super().__init__() self.url = url self.status = status def handle(self, req): req.status(self.status, "Redirect") req.ohead["Location"] = proto.appendurl(proto.requrl(req), self.url) + req.ohead["Content-Length"] = 0 return [] diff --combined wrw/sp/xhtml.py index 17c5678,d19fc99..52e7f9f --- a/wrw/sp/xhtml.py +++ b/wrw/sp/xhtml.py @@@ -1,11 -1,11 +1,11 @@@ -import xml.dom.minidom, StringIO -import cons as _cons -import util +import xml.dom.minidom, io +from . import cons as _cons +from . import util dom = xml.dom.minidom.getDOMImplementation() -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" +ns = "http://www.w3.org/1999/xhtml" +doctype = "-//W3C//DTD XHTML 1.1//EN" +dtd = "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" class htmlelement(_cons.element): def __todoc__(self): @@@ -15,11 -15,11 +15,11 @@@ return doc class xhtmlcontext(_cons.context): - attrmap = {u"klass": u"class"} + attrmap = {"klass": "class"} def addattr(self, node, k, v): - k = unicode(k) - node.attrs[self.attrmap.get(k, k)] = unicode(v) + k = str(k) + node.attrs[self.attrmap.get(k, k)] = str(v) def cons(ctx=None): if ctx is None: ctx = xhtmlcontext() @@@ -30,7 -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, unicode): + if isinstance(css, str) or isinstance(css, bytes): head(h.link(rel="stylesheet", type="text/css", href=css)) elif css: for ss in css: @@@ -38,7 -38,7 +38,7 @@@ return head class htmlformatter(util.formatter): - allowshort = set([u"br", u"hr", u"img", u"input", u"meta", u"link"]) + 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) @@@ -51,9 -51,11 +51,11 @@@ class htmlindenter(util.indenter, htmlf def forreq(req, tree): # XXX: Use proper Content-Type for clients accepting it. req.ohead["Content-Type"] = "text/html; charset=utf-8" - buf = StringIO.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):