本文整理汇总了Python中cgi.parse方法的典型用法代码示例。如果您正苦于以下问题:Python cgi.parse方法的具体用法?Python cgi.parse怎么用?Python cgi.parse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cgi
的用法示例。
在下文中一共展示了cgi.parse方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: pyro_app
# 需要导入模块: import cgi [as 别名]
# 或者: from cgi import parse [as 别名]
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)
示例2: do_test
# 需要导入模块: import cgi [as 别名]
# 或者: from cgi import parse [as 别名]
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)
示例3: do_test
# 需要导入模块: import cgi [as 别名]
# 或者: from cgi import parse [as 别名]
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)
示例4: do_POST
# 需要导入模块: import cgi [as 别名]
# 或者: from cgi import parse [as 别名]
def do_POST(self):
length = self.headers.get('content-length')
if not length:
return self._bad_request()
if hasattr(self.headers, 'get_content_type'):
ctype = self.headers.get_content_type()
elif self.headers.typeheader is None:
ctype = self.headers.type
else:
ctype = self.headers.typeheader
bare_ctype = ctype.split(";", 1)[0].strip()
if bare_ctype in ("application/x-www-form-urlencoded", "multipart/form-data"):
env = {"CONTENT_LENGTH": length,
"CONTENT_TYPE" : ctype,
"REQUEST_METHOD": "POST"
}
cgi_args = cgi.parse(self.rfile, environ=env, keep_blank_values=True)
else:
cgi_args = {None: [self.rfile.read(int(length))]}
self.is_head = False
self._do_req2(self.path, cgi_args)
示例5: do_test
# 需要导入模块: import cgi [as 别名]
# 或者: from cgi import parse [as 别名]
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)
# A list of test cases. Each test case is a a two-tuple that contains
# a string with the query and a dictionary with the expected result.
示例6: test_deprecated_parse_qs
# 需要导入模块: import cgi [as 别名]
# 或者: from cgi import parse [as 别名]
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'))
示例7: test_deprecated_parse_qsl
# 需要导入模块: import cgi [as 别名]
# 或者: from cgi import parse [as 别名]
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'))