Merge branch 'master' into python3
authorFredrik Tolf <fredrik@dolda2000.com>
Thu, 3 Apr 2014 03:33:34 +0000 (05:33 +0200)
committerFredrik Tolf <fredrik@dolda2000.com>
Thu, 3 Apr 2014 03:33:34 +0000 (05:33 +0200)
Conflicts:
wrw/form.py

1  2 
wrw/form.py

diff --cc wrw/form.py
@@@ -1,41 -1,17 +1,17 @@@
- import cgi
 -import urlparse
 -import proto
++import urllib.parse
 +from . import proto
  
  __all__ = ["formdata"]
  
- class formwrap(object):
-     def __init__(self, req):
-         if req.ihead.get("Content-Type") == "application/x-www-form-urlencoded":
-             self.cf = cgi.parse(environ = req.env, fp = req.input)
-         else:
-             self.cf = cgi.parse(environ = req.env)
-     def __getitem__(self, key):
-         return self.cf[key][0]
-     def get(self, key, default=""):
-         if key in self:
-             return self.cf[key][0]
-         return default
-     def __contains__(self, key):
-         return key in self.cf and len(self.cf[key]) > 0
-     def __iter__(self):
-         return iter(self.cf)
-     def items(self):
-         def iter():
-             for key, list in self.cf.items():
-                 for val in list:
-                     yield key, val
-         return list(iter())
-     def keys(self):
-         return list(self.cf.keys())
-     def values(self):
-         return [val for key, val in self.items()]
+ def formparse(req):
+     buf = {}
 -    buf.update(urlparse.parse_qsl(req.query))
++    buf.update(urllib.parse.parse_qsl(req.query))
+     if req.ihead.get("Content-Type") == "application/x-www-form-urlencoded":
+         if req.input.limit > 2 ** 20:
+             raise ValueError("x-www-form-urlencoded data is absurdly long")
+         rbody = req.input.read()
 -        buf.update(urlparse.parse_qsl(rbody))
++        buf.update(urllib.parse.parse_qsl(rbody))
+     return buf
  
  class badmultipart(Exception):
      pass