Merge branch 'master' into python3
authorFredrik Tolf <fredrik@dolda2000.com>
Mon, 2 Sep 2013 01:26:39 +0000 (03:26 +0200)
committerFredrik Tolf <fredrik@dolda2000.com>
Mon, 2 Sep 2013 01:26:39 +0000 (03:26 +0200)
Conflicts:
wrw/resp.py
wrw/util.py

1  2 
wrw/cookie.py
wrw/form.py
wrw/proto.py
wrw/req.py
wrw/resp.py
wrw/session.py
wrw/sp/cons.py
wrw/util.py

diff --cc wrw/cookie.py
Simple merge
diff --cc wrw/form.py
@@@ -88,10 -88,10 +88,10 @@@ class formpart(object)
              self.buf = ""
          return ret
  
-     def readline(self, limit = -1):
+     def readline(self, limit=-1):
          last = 0
          while True:
 -            p = self.buf.find('\n', last)
 +            p = self.buf.find(b'\n', last)
              if p < 0:
                  if self.eof:
                      ret = self.buf
diff --cc wrw/proto.py
Simple merge
diff --cc wrw/req.py
@@@ -19,9 -19,9 +19,9 @@@ class headdict(object)
          del self.dict[key.lower()]
  
      def __iter__(self):
 -        return iter((list[0] for list in self.dict.itervalues()))
 +        return iter((list[0] for list in self.dict.values()))
      
-     def get(self, key, default = ""):
+     def get(self, key, default=""):
          if key.lower() in self.dict:
              return self.dict[key.lower()][1]
          return default
diff --cc wrw/resp.py
@@@ -59,13 -59,19 +59,19 @@@ class httperror(usererror)
  
  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):
+     bases = {"url": proto.requrl,
+              "script": proto.scripturl,
+              "site": proto.siteurl}
+     def __init__(self, url, status=303, base="url"):
 -        super(redirect, self).__init__()
 +        super().__init__()
          self.url = url
          self.status = status
+         self.bases[base]
+         self.base = base
  
      def handle(self, req):
          req.status(self.status, "Redirect")
diff --cc wrw/session.py
Simple merge
diff --cc wrw/sp/cons.py
@@@ -59,10 -60,10 +59,10 @@@ class context(object)
          node.children.append(self.nodefrom(child))
  
      def addattr(self, node, k, v):
 -        node.attrs[unicode(k)] = unicode(v)
 +        node.attrs[str(k)] = str(v)
  
  class constructor(object):
-     def __init__(self, ns, elcls = element, ctx=None):
+     def __init__(self, ns, elcls=element, ctx=None):
          self._ns = ns
          self._elcls = elcls
          if ctx is None: ctx = context()
diff --cc wrw/util.py
@@@ -7,26 -7,17 +7,26 @@@ def wsgiwrap(callable)
      wrapper.__wrapped__ = callable
      return wrapper
  
 +def stringwrap(charset):
 +    def dec(callable):
 +        def wrapper(*args, **kwargs):
 +            bk = callable(*args, **kwargs)
 +            for string in bk:
 +                yield string.encode(charset)
 +        return wrapper
 +    return dec
 +
  def formparams(callable):
+     spec = inspect.getargspec(callable)
      def wrapper(req):
          data = form.formdata(req)
-         spec = inspect.getargspec(callable)
          args = dict(data.items())
          args["req"] = req
          if not spec.keywords:
              for arg in list(args):
                  if arg not in spec.args:
                      del args[arg]
-         for i in range(len(spec.args) - len(spec.defaults)):
 -        for i in xrange(len(spec.args) - (len(spec.defaults) if spec.defaults else 0)):
++        for i in range(len(spec.args) - (len(spec.defaults) if spec.defaults else 0)):
              if spec.args[i] not in args:
                  raise resp.httperror(400, "Missing parameter", ("The query parameter `", resp.h.code(spec.args[i]), "' is required but not supplied."))
          return callable(**args)