slowdown.cgi
– Common Gateway Interface support¶
This module provides CGI protocol support for Slowdown Web Programming .
Examples:
>>> form = \
... slowdown.cgi.Form(
... rw, # the incoming `slowdown.http.File` object.
...
... max_size=10240 # the length of the http content containing
... # the CGI form data should be less than
... # `max_size` (bytes).
... )
>>> form['checkboxA']
'a'
>>> # If more than one form variable comes with the same name,
>>> # a list is returned.
>>> form['checkboxB']
['a', 'b', 'c']
>>> # The CGI message must be read completely in order to
>>> # respond further, so use 'for .. in' to ensure that
>>> # no parts are unprocessed.
>>> for part in \
... multipart(
... rw, # the incoming `slowdown.http.File` object
...
... # Uploaded files always store their binary filenames in
... # multi-parts heads. Those filenames require an encoding
... # to convert to strings.
... filename_encoding='utf-8' # the default is 'iso8859-1'
... ):
>>> # The reading of the current part must be completed
>>> # before the next part.
>>> if part.filename is None: # ordinary form variable
>>> print (f'key : {part.name }')
... print (f'value: {part.read()}')
>>> else: # file upload
>>> with open(part.filename, 'w') as file_out:
>>> while True:
>>> data = part.read(8192)
>>> file_out.write(data)
>>> if not data:
>>> break
-
exception
slowdown.cgi.
BadRequest
(msg='Bad Request')¶
-
class
slowdown.cgi.
Form
(rw: slowdown.http.File, max_size: int = None, key_encoding: str = 'utf-8', value_encoding: str = 'utf-8') → dict¶ The CGI form parser.
-
slowdown.cgi.
multipart
(rw: slowdown.http.File, filename_encoding: str = None, buffer_size: int = None) → Iterator[MultipartReader]¶
-
class
slowdown.cgi.
MultipartReader
(rw, raw, buffer_size=None)¶