3737import os
3838import urllib .parse
3939import email .parser
40+ from warnings import warn
4041
4142__all__ = ["MiniFieldStorage" , "FieldStorage" ,
4243 "parse" , "parse_qs" , "parse_qsl" , "parse_multipart" ,
@@ -153,75 +154,23 @@ def parse(fp=None, environ=os.environ, keep_blank_values=0, strict_parsing=0):
153154 else :
154155 qs = ""
155156 environ ['QUERY_STRING' ] = qs # XXX Shouldn't, really
156- return parse_qs (qs , keep_blank_values , strict_parsing )
157+ return urllib . parse . parse_qs (qs , keep_blank_values , strict_parsing )
157158
158159
159- def parse_qs (qs , keep_blank_values = 0 , strict_parsing = 0 ):
160- """Parse a query given as a string argument.
161-
162- Arguments:
160+ # parse query string function called from urlparse,
161+ # this is done in order to maintain backward compatiblity.
163162
164- qs: URL-encoded query string to be parsed
165-
166- keep_blank_values: flag indicating whether blank values in
167- URL encoded queries should be treated as blank strings.
168- A true value indicates that blanks should be retained as
169- blank strings. The default false value indicates that
170- blank values are to be ignored and treated as if they were
171- not included.
172-
173- strict_parsing: flag indicating what to do with parsing errors.
174- If false (the default), errors are silently ignored.
175- If true, errors raise a ValueError exception.
176- """
177- dict = {}
178- for name , value in parse_qsl (qs , keep_blank_values , strict_parsing ):
179- if name in dict :
180- dict [name ].append (value )
181- else :
182- dict [name ] = [value ]
183- return dict
163+ def parse_qs (qs , keep_blank_values = 0 , strict_parsing = 0 ):
164+ """Parse a query given as a string argument."""
165+ warn ("cgi.parse_qs is deprecated, use urllib.parse.parse_qs instead" ,
166+ DeprecationWarning )
167+ return urllib .parse .parse_qs (qs , keep_blank_values , strict_parsing )
184168
185169def parse_qsl (qs , keep_blank_values = 0 , strict_parsing = 0 ):
186- """Parse a query given as a string argument.
187-
188- Arguments:
189-
190- qs: URL-encoded query string to be parsed
191-
192- keep_blank_values: flag indicating whether blank values in
193- URL encoded queries should be treated as blank strings. A
194- true value indicates that blanks should be retained as blank
195- strings. The default false value indicates that blank values
196- are to be ignored and treated as if they were not included.
197-
198- strict_parsing: flag indicating what to do with parsing errors. If
199- false (the default), errors are silently ignored. If true,
200- errors raise a ValueError exception.
201-
202- Returns a list, as G-d intended.
203- """
204- pairs = [s2 for s1 in qs .split ('&' ) for s2 in s1 .split (';' )]
205- r = []
206- for name_value in pairs :
207- if not name_value and not strict_parsing :
208- continue
209- nv = name_value .split ('=' , 1 )
210- if len (nv ) != 2 :
211- if strict_parsing :
212- raise ValueError ("bad query field: %r" % (name_value ,))
213- # Handle case of a control-name with no equal sign
214- if keep_blank_values :
215- nv .append ('' )
216- else :
217- continue
218- if len (nv [1 ]) or keep_blank_values :
219- name = urllib .parse .unquote (nv [0 ].replace ('+' , ' ' ))
220- value = urllib .parse .unquote (nv [1 ].replace ('+' , ' ' ))
221- r .append ((name , value ))
222-
223- return r
224-
170+ """Parse a query given as a string argument."""
171+ warn ("cgi.parse_qsl is deprecated, use urllib.parse.parse_qs instead" ,
172+ DeprecationWarning )
173+ return urllib .parse .parse_qsl (qs , keep_blank_values , strict_parsing )
225174
226175def parse_multipart (fp , pdict ):
227176 """Parse multipart input.
@@ -624,8 +573,8 @@ def read_urlencoded(self):
624573 if self .qs_on_post :
625574 qs += '&' + self .qs_on_post
626575 self .list = list = []
627- for key , value in parse_qsl (qs , self .keep_blank_values ,
628- self .strict_parsing ):
576+ for key , value in urllib . parse . parse_qsl (qs , self .keep_blank_values ,
577+ self .strict_parsing ):
629578 list .append (MiniFieldStorage (key , value ))
630579 self .skip_lines ()
631580
@@ -638,8 +587,8 @@ def read_multi(self, environ, keep_blank_values, strict_parsing):
638587 raise ValueError ('Invalid boundary in multipart form: %r' % (ib ,))
639588 self .list = []
640589 if self .qs_on_post :
641- for key , value in parse_qsl (self .qs_on_post , self . keep_blank_values ,
642- self .strict_parsing ):
590+ for key , value in urllib . parse . parse_qsl (self .qs_on_post ,
591+ self . keep_blank_values , self .strict_parsing ):
643592 self .list .append (MiniFieldStorage (key , value ))
644593 FieldStorageClass = None
645594
0 commit comments