我们从Python开源项目中,提取了以下20个代码示例,用于说明如何使用cgi.parse()。
def do_test(buf, method): env = {} if method == "GET": fp = None env['REQUEST_METHOD'] = 'GET' env['QUERY_STRING'] = buf elif method == "POST": fp = BytesIO(buf.encode('latin-1')) # FieldStorage expects bytes env['REQUEST_METHOD'] = 'POST' env['CONTENT_TYPE'] = 'application/x-www-form-urlencoded' env['CONTENT_LENGTH'] = str(len(buf)) else: raise ValueError("unknown method: %s" % method) try: return cgi.parse(fp, env, strict_parsing=1) except Exception as err: return ComparableException(err)
def do_test(buf, method): env = {} if method == "GET": fp = None env['REQUEST_METHOD'] = 'GET' env['QUERY_STRING'] = buf elif method == "POST": fp = StringIO(buf) env['REQUEST_METHOD'] = 'POST' env['CONTENT_TYPE'] = 'application/x-www-form-urlencoded' env['CONTENT_LENGTH'] = str(len(buf)) else: raise ValueError, "unknown method: %s" % method try: return cgi.parse(fp, env, strict_parsing=1) except StandardError, err: return ComparableException(err)
def pyro_app(environ, start_response): """ The WSGI app function that is used to process the requests. You can stick this into a wsgi server of your choice, or use the main() method to use the default wsgiref server. """ config.SERIALIZER = "json" # we only talk json through the http proxy config.COMMTIMEOUT = pyro_app.comm_timeout method = environ.get("REQUEST_METHOD") path = environ.get('PATH_INFO', '').lstrip('/') if not path: return redirect(start_response, "/pyro/") if path.startswith("pyro/"): if method in ("GET", "POST"): parameters = singlyfy_parameters(cgi.parse(environ['wsgi.input'], environ)) return process_pyro_request(environ, path[5:], parameters, start_response) else: return invalid_request(start_response) return not_found(start_response)
def test_deprecated_parse_qs(self): # this func is moved to urllib.parse, this is just a sanity check with check_warnings(('cgi.parse_qs is deprecated, use urllib.parse.' 'parse_qs instead', DeprecationWarning)): self.assertEqual({'a': ['A1'], 'B': ['B3'], 'b': ['B2']}, cgi.parse_qs('a=A1&b=B2&B=B3'))
def test_deprecated_parse_qsl(self): # this func is moved to urllib.parse, this is just a sanity check with check_warnings(('cgi.parse_qsl is deprecated, use urllib.parse.' 'parse_qsl instead', DeprecationWarning)): self.assertEqual([('a', 'A1'), ('b', 'B2'), ('B', 'B3')], cgi.parse_qsl('a=A1&b=B2&B=B3'))
def params(self): return cgi.parse()
def params(self): return cgi.parse(environ=self._environ, fp=self._environ["wsgi.input"])
def extract(environ, empty=False, err=False): """Extracts strings in form data and returns a dict. :param environ: WSGI environ :param empty: Stops on empty fields (default: Fault) :param err: Stops on errors in fields (default: Fault) """ formdata = cgi.parse(environ['wsgi.input'], environ, empty, err) # Remove single entries from lists for key, value in iter(formdata.items()): if len(value) == 1: formdata[key] = value[0] return formdata