165
175
return parse_qs(qs, keep_blank_values, strict_parsing)
178
# parse query string function called from urlparse,
179
# this is done in order to maintain backward compatiblity.
168
181
def parse_qs(qs, keep_blank_values=0, strict_parsing=0):
169
"""Parse a query given as a string argument.
173
qs: URL-encoded query string to be parsed
175
keep_blank_values: flag indicating whether blank values in
176
URL encoded queries should be treated as blank strings.
177
A true value indicates that blanks should be retained as
178
blank strings. The default false value indicates that
179
blank values are to be ignored and treated as if they were
182
strict_parsing: flag indicating what to do with parsing errors.
183
If false (the default), errors are silently ignored.
184
If true, errors raise a ValueError exception.
187
for name, value in parse_qsl(qs, keep_blank_values, strict_parsing):
189
dict[name].append(value)
182
"""Parse a query given as a string argument."""
183
warn("cgi.parse_qs is deprecated, use urlparse.parse_qs \
184
instead",PendingDeprecationWarning)
185
return urlparse.parse_qs(qs, keep_blank_values, strict_parsing)
194
188
def parse_qsl(qs, keep_blank_values=0, strict_parsing=0):
195
"""Parse a query given as a string argument.
199
qs: URL-encoded query string to be parsed
201
keep_blank_values: flag indicating whether blank values in
202
URL encoded queries should be treated as blank strings. A
203
true value indicates that blanks should be retained as blank
204
strings. The default false value indicates that blank values
205
are to be ignored and treated as if they were not included.
207
strict_parsing: flag indicating what to do with parsing errors. If
208
false (the default), errors are silently ignored. If true,
209
errors raise a ValueError exception.
211
Returns a list, as G-d intended.
213
pairs = [s2 for s1 in qs.split('&') for s2 in s1.split(';')]
215
for name_value in pairs:
216
if not name_value and not strict_parsing:
218
nv = name_value.split('=', 1)
221
raise ValueError, "bad query field: %r" % (name_value,)
222
# Handle case of a control-name with no equal sign
223
if keep_blank_values:
227
if len(nv[1]) or keep_blank_values:
228
name = urllib.unquote(nv[0].replace('+', ' '))
229
value = urllib.unquote(nv[1].replace('+', ' '))
230
r.append((name, value))
189
"""Parse a query given as a string argument."""
190
warn("cgi.parse_qsl is deprecated, use urlparse.parse_qsl instead",
191
PendingDeprecationWarning)
192
return urlparse.parse_qsl(qs, keep_blank_values, strict_parsing)
235
194
def parse_multipart(fp, pdict):
236
195
"""Parse multipart input.
631
593
def read_urlencoded(self):
632
594
"""Internal: read data in query string format."""
633
595
qs = self.fp.read(self.length)
597
qs += '&' + self.qs_on_post
634
598
self.list = list = []
635
for key, value in parse_qsl(qs, self.keep_blank_values,
636
self.strict_parsing):
599
for key, value in urlparse.parse_qsl(qs, self.keep_blank_values,
600
self.strict_parsing):
637
601
list.append(MiniFieldStorage(key, value))
638
602
self.skip_lines()
645
609
if not valid_boundary(ib):
646
610
raise ValueError, 'Invalid boundary in multipart form: %r' % (ib,)
613
for key, value in urlparse.parse_qsl(self.qs_on_post,
614
self.keep_blank_values, self.strict_parsing):
615
self.list.append(MiniFieldStorage(key, value))
616
FieldStorageClass = None
648
618
klass = self.FieldStorageClass or self.__class__
649
619
part = klass(self.fp, {}, ib,
650
620
environ, keep_blank_values, strict_parsing)