mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-02-22 18:22:40 +00:00
De-Nevow `get_arg
`
This commit is contained in:
parent
7f02128973
commit
743ead71a4
@ -6,13 +6,7 @@ Can eventually be merged back into allmydata.web.common.
|
|||||||
|
|
||||||
from future.utils import PY2
|
from future.utils import PY2
|
||||||
|
|
||||||
if PY2:
|
|
||||||
from nevow.inevow import IRequest as INevowRequest
|
|
||||||
else:
|
|
||||||
INevowRequest = None
|
|
||||||
|
|
||||||
from twisted.web import resource, http
|
from twisted.web import resource, http
|
||||||
from twisted.web.iweb import IRequest
|
|
||||||
|
|
||||||
from allmydata.util import abbreviate
|
from allmydata.util import abbreviate
|
||||||
|
|
||||||
@ -23,7 +17,7 @@ class WebError(Exception):
|
|||||||
self.code = code
|
self.code = code
|
||||||
|
|
||||||
|
|
||||||
def get_arg(ctx_or_req, argname, default=None, multiple=False):
|
def get_arg(req, argname, default=None, multiple=False):
|
||||||
"""Extract an argument from either the query args (req.args) or the form
|
"""Extract an argument from either the query args (req.args) or the form
|
||||||
body fields (req.fields). If multiple=False, this returns a single value
|
body fields (req.fields). If multiple=False, this returns a single value
|
||||||
(or the default, which defaults to None), and the query args take
|
(or the default, which defaults to None), and the query args take
|
||||||
@ -31,16 +25,10 @@ def get_arg(ctx_or_req, argname, default=None, multiple=False):
|
|||||||
empty), starting with all those in the query args.
|
empty), starting with all those in the query args.
|
||||||
"""
|
"""
|
||||||
results = []
|
results = []
|
||||||
if PY2:
|
if argname in req.args:
|
||||||
req = INevowRequest(ctx_or_req)
|
results.extend(req.args[argname])
|
||||||
if argname in req.args:
|
if req.fields and argname in req.fields:
|
||||||
results.extend(req.args[argname])
|
results.append(req.fields[argname].value)
|
||||||
if req.fields and argname in req.fields:
|
|
||||||
results.append(req.fields[argname].value)
|
|
||||||
else:
|
|
||||||
req = IRequest(ctx_or_req)
|
|
||||||
if argname in req.args:
|
|
||||||
results.extend(req.args[argname])
|
|
||||||
if multiple:
|
if multiple:
|
||||||
return tuple(results)
|
return tuple(results)
|
||||||
if results:
|
if results:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user