MCPcopy Index your code
hub / github.com/webpy/webpy / rawinput

Function rawinput

web/webapi.py:404–453  ·  view source on GitHub ↗

Returns storage object with GET or POST arguments.

(method=None)

Source from the content-addressed store, hash-verified

402
403
404def rawinput(method=None):
405 """Returns storage object with GET or POST arguments."""
406 method = method or "both"
407
408 def dictify(fs):
409 return {k: fs[k] for k in fs}
410
411 env = ctx.env.copy()
412 post_req = get_req = {}
413
414 if method.lower() in ["both", "post", "put", "patch"]:
415 if env["REQUEST_METHOD"] in ["POST", "PUT", "PATCH"]:
416 if env.get("CONTENT_TYPE", "").lower().startswith("multipart/"):
417 # since wsgi.input is directly passed to multipart,
418 # it can not be called multiple times. Saving the result
419 # object in ctx to allow calling web.input multiple times.
420 post_req = ctx.get(
421 "_fieldstorage"
422 ) # TODO: Rename? is this visible anywhere else?
423 if not post_req:
424 try:
425 # This returns two dicts, forms & files.
426 forms, files = multipart.parse_form_data(environ=env)
427 post_req = dictadd(forms, files)
428 ctx._fieldstorage = post_req
429 except IndexError:
430 post_req = {}
431
432 else:
433 post_data = data().decode("utf-8")
434 post_req = parse_qs(post_data, keep_blank_values=True)
435 post_req = dictify(post_req)
436
437 if method.lower() in ["both", "get"]:
438 env["REQUEST_METHOD"] = "GET"
439 get_req = dict(
440 urllib.parse.parse_qs(env.get("QUERY_STRING", ""), keep_blank_values=True)
441 )
442
443 def process_values(values):
444 if isinstance(values, list):
445 return [process_values(x) for x in values]
446 elif hasattr(values, "filename") and values.filename is None:
447 return values.value
448 else:
449 return values
450
451 return storage(
452 [(k, process_values(v)) for k, v in dictadd(get_req, post_req).items()]
453 )
454
455
456def input(*requireds, **defaults):

Callers 1

inputFunction · 0.85

Calls 8

dictaddFunction · 0.85
dataFunction · 0.85
dictifyFunction · 0.85
process_valuesFunction · 0.85
decodeMethod · 0.80
itemsMethod · 0.80
copyMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected