本文整理匯總了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'))