-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"]
class usererror(dispatch.restart):
def __init__(self, message, *detail):
- super(usererror, self).__init__()
+ super().__init__()
self.message = message
self.detail = detail
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):
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 []
-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):
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()
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:
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)
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):