Kaydet (Commit) e7808778 authored tarafından Guido van Rossum's avatar Guido van Rossum

added parse_qs(query_string)

üst f54d967f
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
# #
# modified by Steve Majewski <sdm7g@Virginia.EDU> 12/5/94 # modified by Steve Majewski <sdm7g@Virginia.EDU> 12/5/94
# #
# now maintained as part of the Python distribution
# Several classes to parse the name/value pairs that are passed to # Several classes to parse the name/value pairs that are passed to
# a server's CGI by GET, POST or PUT methods by a WWW FORM. This # a server's CGI by GET, POST or PUT methods by a WWW FORM. This
...@@ -42,11 +43,17 @@ from os import environ ...@@ -42,11 +43,17 @@ from os import environ
def parse(): def parse():
"""Parse the query passed in the environment or on stdin"""
if environ['REQUEST_METHOD'] == 'POST': if environ['REQUEST_METHOD'] == 'POST':
qs = sys.stdin.read(string.atoi(environ['CONTENT_LENGTH'])) qs = sys.stdin.read(string.atoi(environ['CONTENT_LENGTH']))
environ['QUERY_STRING'] = qs environ['QUERY_STRING'] = qs
else: else:
qs = environ['QUERY_STRING'] qs = environ['QUERY_STRING']
return parse_qs(qs)
def parse_qs(qs):
"""Parse a query given as a string argument"""
name_value_pairs = string.splitfields(qs, '&') name_value_pairs = string.splitfields(qs, '&')
dict = {} dict = {}
for name_value in name_value_pairs: for name_value in name_value_pairs:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment