buf = {}
buf.update(urllib.parse.parse_qsl(req.query))
if req.ihead.get("Content-Type") == "application/x-www-form-urlencoded":
- rbody = req.input.read(2 ** 20)
+ try:
+ rbody = req.input.read(2 ** 20)
+ except IOError as exc:
+ return exc
if len(rbody) >= 2 ** 20:
- raise ValueError("x-www-form-urlencoded data is absurdly long")
+ return ValueError("x-www-form-urlencoded data is absurdly long")
buf.update(urllib.parse.parse_qsl(rbody.decode("latin1")))
return buf
self.lastpart.parsehead(self.headcs)
return self.lastpart
-def formdata(req):
- return req.item(formparse)
+def formdata(req, onerror=Exception):
+ data = req.item(formparse)
+ if isinstance(data, Exception):
+ if onerror is Exception:
+ raise data
+ return onerror
+ return data