Merge branch 'master' into python3
authorFredrik Tolf <fredrik@dolda2000.com>
Sun, 7 Apr 2013 17:06:40 +0000 (19:06 +0200)
committerFredrik Tolf <fredrik@dolda2000.com>
Sun, 7 Apr 2013 17:06:40 +0000 (19:06 +0200)
Conflicts:
wrw/sp/util.py

1  2 
wrw/sp/util.py

diff --cc wrw/sp/util.py
@@@ -1,4 -1,6 +1,6 @@@
 -import StringIO
 -from wrw import dispatch
 -import cons
++import io
++from .. import dispatch
 +from . import cons
  
  def findnsnames(el):
      names = {}
@@@ -144,6 -146,12 +146,12 @@@ class formatter(object)
      def fragment(cls, out, el, *args, **kw):
          cls(out=out, root=el, *args, **kw).node(el)
  
 -        buf = StringIO.StringIO()
+     @classmethod
+     def format(cls, el, *args, **kw):
++        buf = io.BytesIO()
+         cls.output(buf, el, *args, **kw)
+         return buf.getvalue()
      def update(self, **ch):
          ret = type(self).__new__(type(self))
          ret.__dict__.update(self.__dict__)
@@@ -212,3 -219,20 +220,20 @@@ class indenter(formatter)
      def start(self):
          super(indenter, self).start()
          self.write('\n')
 -        super(response, self).__init__()
+ class response(dispatch.restart):
+     charset = "utf-8"
+     doctype = None
+     formatter = indenter
+     def __init__(self, root):
++        super().__init__()
+         self.root = root
+     @property
+     def ctype(self):
+         raise Exception("a subclass of wrw.sp.util.response must override ctype")
+     def handle(self, req):
+         req.ohead["Content-Type"] = self.ctype
+         return [self.formatter.format(self.root, doctype=self.doctype, charset=self.charset)]