From: Fredrik Tolf Date: Thu, 3 Apr 2014 03:33:34 +0000 (+0200) Subject: Merge branch 'master' into python3 X-Git-Url: http://dolda2000.com/gitweb/?p=wrw.git;a=commitdiff_plain;h=8a7ba0dcff7734cce7328e487c1ab38712b84168 Merge branch 'master' into python3 Conflicts: wrw/form.py --- 8a7ba0dcff7734cce7328e487c1ab38712b84168 diff --cc wrw/form.py index c97b0f9,3bad8fc..7184635 --- a/wrw/form.py +++ b/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