8000 correct parse_qs and parse_qsl test case descriptions. (#968) · python/cpython@257b980 · GitHub
[go: up one dir, main page]

Skip to content

Commit 257b980

Browse files
authored
correct parse_qs and parse_qsl test case descriptions. (#968)
* correct parse_qs and parse_qsl test case descriptions.
1 parent f78b119 commit 257b980

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
lines changed

Lib/test/test_urlparse.py

Lines changed: 6 additions & 6 deletions
10000
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
RFC3986_BASE = 'http://a/b/c/d;p?q'
77
SIMPLE_BASE = 'http://a/b/c/d'
88

9-
# A list of test cases. Each test case is a two-tuple that contains
10-
# a string with the query and a dictionary with the expected result.
9+
# Each parse_qsl testcase is a two-tuple that contains
10+
# a string with the query and a list with the expected result.
1111

1212
parse_qsl_test_cases = [
1313
("", []),
@@ -42,6 +42,9 @@
4242
(b"a=1;a=2", [(b'a', b'1'), (b'a', b'2')]),
4343
]
4444

45+
# Each parse_qs testcase is a two-tuple that contains
46+
# a string with the query and a dictionary with the expected result.
47+
4548
parse_qs_test_cases = [
4649
("", {}),
4750
("&", {}),
@@ -290,7 +293,6 @@ def test_RFC2368(self):
290293
def test_RFC2396(self):
291294
# cases from RFC 2396
292295

293-
294296
self.checkJoin(RFC2396_BASE, 'g:h', 'g:h')
295297
self.checkJoin(RFC2396_BASE, 'g', 'http://a/b/c/g')
296298
self.checkJoin(RFC2396_BASE, './g', 'http://a/b/c/g')
@@ -333,9 +335,7 @@ def test_RFC2396(self):
333335
# self.checkJoin(RFC2396_BASE, '/./g', 'http://a/./g')
334336
# self.checkJoin(RFC2396_BASE, '/../g', 'http://a/../g')
335337

336-
337338
def test_RFC3986(self):
338-
# Test cases from RFC3986
339339
self.checkJoin(RFC3986_BASE, '?y','http://a/b/c/d;p?y')
340340
self.checkJoin(RFC3986_BASE, ';x', 'http://a/b/c/;x')
341341
self.checkJoin(RFC3986_BASE, 'g:h','g:h')
@@ -363,7 +363,7 @@ def test_RFC3986(self):
363363
self.checkJoin(RFC3986_BASE, '../../g','http://a/g')
364364
self.checkJoin(RFC3986_BASE, '../../../g', 'http://a/g')
365365

366-
#Abnormal Examples
366+
# Abnormal Examples
367367

368368
# The 'abnormal scenarios' are incompatible with RFC2986 parsing
369369
# Tests are here for reference.

Lib/urllib/parse.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,7 @@ def unquote(string, encoding='utf-8', errors='replace'):
612612
append(bits[i + 1])
613613
return ''.join(res)
614614

615+
615616
def parse_qs(qs, keep_blank_values=False, strict_parsing=False,
616617
encoding='utf-8', errors='replace'):
617618
"""Parse a query given as a string argument.
@@ -633,6 +634,8 @@ def parse_qs(qs, keep_blank_values=False, strict_parsing=False,
633634
634635
encoding and errors: specify how to decode percent-encoded sequences
635636
into Unicode characters, as accepted by the bytes.decode() method.
637+
638+
Returns a dictionary.
636639
"""
637640
parsed_result = {}
638641
pairs = parse_qsl(qs, keep_blank_values, strict_parsing,
@@ -644,28 +647,29 @@ def parse_qs(qs, keep_blank_values=False, strict_parsing=False,
644647
parsed_result[name] = [value]
645648
return parsed_result
646649

650+
647651
def parse_qsl(qs, keep_blank_values=False, strict_parsing=False,
648652
encoding='utf-8', errors='replace'):
649653
"""Parse a query given as a string argument.
650654
651-
Arguments:
655+
Arguments:
652656
653-
qs: percent-encoded query string to be parsed
657+
qs: percent-encoded query string to be parsed
654658
655-
keep_blank_values: flag indicating whether blank values in
656-
percent-encoded queries should be treated as blank strings. A
657-
true value indicates that blanks should be retained as blank
658-
strings. The default false value indicates that blank values
659-
are to be ignored and treated as if they were not included.
659+
keep_blank_values: flag indicating whether blank values in
660+
percent-encoded queries should be treated as blank strings.
661+
A true value indicates that blanks should be retained as blank
662+
strings. The default false value indicates that blank values
663+
are to be ignored and treated as if they were not included.
660664
661-
strict_parsing: flag indicating what to do with parsing errors. If
662-
false (the default), errors are silently ignored. If true,
663-
errors raise a ValueError exception.
665+
strict_parsing: flag indicating what to do with parsing errors. If
666+
false (the default), errors are silently ignored. If true,
667+
errors raise a ValueError exception.
664668
665-
encoding and errors: specify how to decode percent-encoded sequences
666-
into Unicode characters, as accepted by the bytes.decode() method.
669+
encoding and errors: specify how to decode percent-encoded sequences
670+
into Unicode characters, as accepted by the bytes.decode() method.
667671
668-
Returns a list, as G-d intended.
672+
Returns a list, as G-d intended.
669673
"""
670674
qs, _coerce_result = _coerce_args(qs)
671675
pairs = [s2 for s1 in qs.split('&') for s2 in s1.split(';')]

0 commit comments

Comments
 (0)
0