Merge branch 'master' into python3
authorFredrik Tolf <fredrik@dolda2000.com>
Wed, 5 Jun 2013 10:58:21 +0000 (12:58 +0200)
committerFredrik Tolf <fredrik@dolda2000.com>
Wed, 5 Jun 2013 10:58:21 +0000 (12:58 +0200)
1  2 
wrw/resp.py
wrw/sp/xhtml.py

diff --combined 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
@@@ -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):
          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):