Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_cgi.py @ 79453:366c19bb5ca2
MERGE: Closes #16126: PyErr_Format format mismatch in _testcapimodule.c
| author | Jesus Cea <jcea@jcea.es> |
|---|---|
| date | Thu, 04 Oct 2012 16:07:03 +0200 |
| parents | bc91c251a4e9 |
| children | 59ea872d8b6b |
| rev | line source |
|---|---|
|
59671
80dc4d131d85
Merged revisions 79030-79032 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58415
diff
changeset
|
1 from test.support import run_unittest, check_warnings |
|
13842
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
2 import cgi |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
3 import os |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
4 import sys |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39575
diff
changeset
|
5 import tempfile |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
6 import unittest |
|
76565
bc91c251a4e9
Silence DeprecationWarning for cgi.escape() usage in test_cgi.
Brett Cannon <brett@python.org>
parents:
75583
diff
changeset
|
7 import warnings |
|
67590
d864328a74e4
Issue #4953: cgi.FieldStorage and cgi.parse() parse the request as bytes, not
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66530
diff
changeset
|
8 from io import StringIO, BytesIO |
|
13842
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
9 |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
10 class HackedSysModule: |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
11 # The regression test will have real values in sys.argv, which |
|
15305
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14606
diff
changeset
|
12 # will completely confuse the test of the cgi module |
|
13842
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
13 argv = [] |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
14 stdin = sys.stdin |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
15 |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
16 cgi.sys = HackedSysModule() |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
17 |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
18 class ComparableException: |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
19 def __init__(self, err): |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
20 self.err = err |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
21 |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
22 def __str__(self): |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
23 return str(self.err) |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
24 |
|
39644
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39610
diff
changeset
|
25 def __eq__(self, anExc): |
|
13842
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
26 if not isinstance(anExc, Exception): |
|
39644
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39610
diff
changeset
|
27 return NotImplemented |
|
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39610
diff
changeset
|
28 return (self.err.__class__ == anExc.__class__ and |
|
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39610
diff
changeset
|
29 self.err.args == anExc.args) |
|
13842
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
30 |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
31 def __getattr__(self, attr): |
|
15936
bec0f61cfcd5
Fix a bizarre typo in the helper class ComparableException: the
Guido van Rossum <guido@python.org>
parents:
15305
diff
changeset
|
32 return getattr(self.err, attr) |
|
13842
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
33 |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
34 def do_test(buf, method): |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
35 env = {} |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
36 if method == "GET": |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
37 fp = None |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
38 env['REQUEST_METHOD'] = 'GET' |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
39 env['QUERY_STRING'] = buf |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
40 elif method == "POST": |
|
67590
d864328a74e4
Issue #4953: cgi.FieldStorage and cgi.parse() parse the request as bytes, not
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66530
diff
changeset
|
41 fp = BytesIO(buf.encode('latin-1')) # FieldStorage expects bytes |
|
13842
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
42 env['REQUEST_METHOD'] = 'POST' |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
43 env['CONTENT_TYPE'] = 'application/x-www-form-urlencoded' |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
44 env['CONTENT_LENGTH'] = str(len(buf)) |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
45 else: |
|
43014
9834301a2fd3
Raise statement normalization in Lib/test/.
Collin Winter <collinw@gmail.com>
parents:
42930
diff
changeset
|
46 raise ValueError("unknown method: %s" % method) |
|
13842
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
47 try: |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
48 return cgi.parse(fp, env, strict_parsing=1) |
|
42084
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40809
diff
changeset
|
49 except Exception as err: |
|
13842
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
50 return ComparableException(err) |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
51 |
|
32758
859ea8612eb0
Don't return spurious empty fields if 'keep_empty_values' is True.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
24442
diff
changeset
|
52 parse_strict_test_cases = [ |
|
13842
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
53 ("", ValueError("bad query field: ''")), |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
54 ("&", ValueError("bad query field: ''")), |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
55 ("&&", ValueError("bad query field: ''")), |
|
14606
f2fc66a6153b
fix bug #110661 (PR#356) -- accept either & or ; as separator for CGI
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14196
diff
changeset
|
56 (";", ValueError("bad query field: ''")), |
|
f2fc66a6153b
fix bug #110661 (PR#356) -- accept either & or ; as separator for CGI
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14196
diff
changeset
|
57 (";&;", ValueError("bad query field: ''")), |
|
13842
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
58 # Should the next few really be valid? |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
59 ("=", {}), |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
60 ("=&=", {}), |
|
14606
f2fc66a6153b
fix bug #110661 (PR#356) -- accept either & or ; as separator for CGI
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14196
diff
changeset
|
61 ("=;=", {}), |
|
13842
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
62 # This rest seem to make sense |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
63 ("=a", {'': ['a']}), |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
64 ("&=a", ValueError("bad query field: ''")), |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
65 ("=a&", ValueError("bad query field: ''")), |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
66 ("=&a", ValueError("bad query field: 'a'")), |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
67 ("b=a", {'b': ['a']}), |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
68 ("b+=a", {'b ': ['a']}), |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
69 ("a=b=a", {'a': ['b=a']}), |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
70 ("a=+b=a", {'a': [' b=a']}), |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
71 ("&b=a", ValueError("bad query field: ''")), |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
72 ("b&=a", ValueError("bad query field: 'b'")), |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
73 ("a=a+b&b=b+c", {'a': ['a b'], 'b': ['b c']}), |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
74 ("a=a+b&a=b+a", {'a': ['a b', 'b a']}), |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
75 ("x=1&y=2.0&z=2-3.%2b0", {'x': ['1'], 'y': ['2.0'], 'z': ['2-3.+0']}), |
|
14606
f2fc66a6153b
fix bug #110661 (PR#356) -- accept either & or ; as separator for CGI
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14196
diff
changeset
|
76 ("x=1;y=2.0&z=2-3.%2b0", {'x': ['1'], 'y': ['2.0'], 'z': ['2-3.+0']}), |
|
f2fc66a6153b
fix bug #110661 (PR#356) -- accept either & or ; as separator for CGI
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14196
diff
changeset
|
77 ("x=1;y=2.0;z=2-3.%2b0", {'x': ['1'], 'y': ['2.0'], 'z': ['2-3.+0']}), |
|
13842
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
78 ("Hbc5161168c542333633315dee1182227:key_store_seqid=400006&cuyer=r&view=bustomer&order_id=0bb2e248638833d48cb7fed300000f1b&expire=964546263&lobale=en-US&kid=130003.300038&ss=env", |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
79 {'Hbc5161168c542333633315dee1182227:key_store_seqid': ['400006'], |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
80 'cuyer': ['r'], |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
81 'expire': ['964546263'], |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
82 'kid': ['130003.300038'], |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
83 'lobale': ['en-US'], |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
84 'order_id': ['0bb2e248638833d48cb7fed300000f1b'], |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
85 'ss': ['env'], |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
86 'view': ['bustomer'], |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
87 }), |
|
15305
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14606
diff
changeset
|
88 |
|
13842
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
89 ("group_id=5470&set=custom&_assigned_to=31392&_status=1&_category=100&SUBMIT=Browse", |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
90 {'SUBMIT': ['Browse'], |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
91 '_assigned_to': ['31392'], |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
92 '_category': ['100'], |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
93 '_status': ['1'], |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
94 'group_id': ['5470'], |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
95 'set': ['custom'], |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
96 }) |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
97 ] |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
98 |
|
39644
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39610
diff
changeset
|
99 def norm(seq): |
|
40809
f340cb045bf9
- PEP 3106: dict.iterkeys(), .iteritems(), .itervalues() are now gone;
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
100 return sorted(seq, key=repr) |
|
13842
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
101 |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
102 def first_elts(list): |
|
42142
a53e48be6df9
Merged revisions 56125-56153 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42084
diff
changeset
|
103 return [p[0] for p in list] |
|
13842
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
104 |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
105 def first_second_elts(list): |
|
42142
a53e48be6df9
Merged revisions 56125-56153 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42084
diff
changeset
|
106 return [(p[0], p[1][0]) for p in list] |
|
a53e48be6df9
Merged revisions 56125-56153 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42084
diff
changeset
|
107 |
|
48410
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
108 def gen_result(data, environ): |
|
67590
d864328a74e4
Issue #4953: cgi.FieldStorage and cgi.parse() parse the request as bytes, not
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66530
diff
changeset
|
109 encoding = 'latin-1' |
|
d864328a74e4
Issue #4953: cgi.FieldStorage and cgi.parse() parse the request as bytes, not
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66530
diff
changeset
|
110 fake_stdin = BytesIO(data.encode(encoding)) |
|
48410
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
111 fake_stdin.seek(0) |
|
67590
d864328a74e4
Issue #4953: cgi.FieldStorage and cgi.parse() parse the request as bytes, not
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66530
diff
changeset
|
112 form = cgi.FieldStorage(fp=fake_stdin, environ=environ, encoding=encoding) |
|
48410
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
113 |
|
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
114 result = {} |
|
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
115 for k, v in dict(form).items(): |
|
59671
80dc4d131d85
Merged revisions 79030-79032 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58415
diff
changeset
|
116 result[k] = isinstance(v, list) and form.getlist(k) or v.value |
|
48410
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
117 |
|
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
118 return result |
|
13842
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
119 |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
120 class CgiTests(unittest.TestCase): |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
121 |
|
75582
13922f6d87f2
3.2 - Fix closes Issue14281 - Test for cgi.escape by Brian Landers
Senthil Kumaran <senthil@uthcode.com>
parents:
72989
diff
changeset
|
122 def test_escape(self): |
|
76565
bc91c251a4e9
Silence DeprecationWarning for cgi.escape() usage in test_cgi.
Brett Cannon <brett@python.org>
parents:
75583
diff
changeset
|
123 # cgi.escape() is deprecated. |
|
bc91c251a4e9
Silence DeprecationWarning for cgi.escape() usage in test_cgi.
Brett Cannon <brett@python.org>
parents:
75583
diff
changeset
|
124 with warnings.catch_warnings(): |
|
bc91c251a4e9
Silence DeprecationWarning for cgi.escape() usage in test_cgi.
Brett Cannon <brett@python.org>
parents:
75583
diff
changeset
|
125 warnings.filterwarnings('ignore', 'cgi\.escape', |
|
bc91c251a4e9
Silence DeprecationWarning for cgi.escape() usage in test_cgi.
Brett Cannon <brett@python.org>
parents:
75583
diff
changeset
|
126 DeprecationWarning) |
|
bc91c251a4e9
Silence DeprecationWarning for cgi.escape() usage in test_cgi.
Brett Cannon <brett@python.org>
parents:
75583
diff
changeset
|
127 self.assertEqual("test & string", cgi.escape("test & string")) |
|
bc91c251a4e9
Silence DeprecationWarning for cgi.escape() usage in test_cgi.
Brett Cannon <brett@python.org>
parents:
75583
diff
changeset
|
128 self.assertEqual("<test string>", cgi.escape("<test string>")) |
|
bc91c251a4e9
Silence DeprecationWarning for cgi.escape() usage in test_cgi.
Brett Cannon <brett@python.org>
parents:
75583
diff
changeset
|
129 self.assertEqual(""test string"", cgi.escape('"test string"', True)) |
|
75582
13922f6d87f2
3.2 - Fix closes Issue14281 - Test for cgi.escape by Brian Landers
Senthil Kumaran <senthil@uthcode.com>
parents:
72989
diff
changeset
|
130 |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
131 def test_strict(self): |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
132 for orig, expect in parse_strict_test_cases: |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
133 # Test basic parsing |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
134 d = do_test(orig, "GET") |
|
67590
d864328a74e4
Issue #4953: cgi.FieldStorage and cgi.parse() parse the request as bytes, not
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66530
diff
changeset
|
135 self.assertEqual(d, expect, "Error parsing %s method GET" % repr(orig)) |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
136 d = do_test(orig, "POST") |
|
67590
d864328a74e4
Issue #4953: cgi.FieldStorage and cgi.parse() parse the request as bytes, not
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66530
diff
changeset
|
137 self.assertEqual(d, expect, "Error parsing %s method POST" % repr(orig)) |
|
13842
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
138 |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
139 env = {'QUERY_STRING': orig} |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
140 fs = cgi.FieldStorage(environ=env) |
|
59671
80dc4d131d85
Merged revisions 79030-79032 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58415
diff
changeset
|
141 if isinstance(expect, dict): |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
142 # test dict interface |
|
46915
e94574455d9d
Remove old backwards-compatibility classes from the cgi module.
Georg Brandl <georg@python.org>
parents:
43014
diff
changeset
|
143 self.assertEqual(len(expect), len(fs)) |
|
66530
93cd4de8ee0b
Use assertCountEqual instead of assertItemsEqual
Ezio Melotti <ezio.melotti@gmail.com>
parents:
66310
diff
changeset
|
144 self.assertCountEqual(expect.keys(), fs.keys()) |
|
46915
e94574455d9d
Remove old backwards-compatibility classes from the cgi module.
Georg Brandl <georg@python.org>
parents:
43014
diff
changeset
|
145 ##self.assertEqual(norm(expect.values()), norm(fs.values())) |
|
e94574455d9d
Remove old backwards-compatibility classes from the cgi module.
Georg Brandl <georg@python.org>
parents:
43014
diff
changeset
|
146 ##self.assertEqual(norm(expect.items()), norm(fs.items())) |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
147 self.assertEqual(fs.getvalue("nonexistent field", "default"), "default") |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
148 # test individual fields |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
149 for key in expect.keys(): |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
150 expect_val = expect[key] |
|
58415
f6a626f34840
use assert[Not]In where appropriate
Benjamin Peterson <benjamin@python.org>
parents:
55593
diff
changeset
|
151 self.assertIn(key, fs) |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
152 if len(expect_val) > 1: |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
153 self.assertEqual(fs.getvalue(key), expect_val) |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
154 else: |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
155 self.assertEqual(fs.getvalue(key), expect_val[0]) |
|
13842
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
156 |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
157 def test_log(self): |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
158 cgi.log("Testing") |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
159 |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
160 cgi.logfp = StringIO() |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
161 cgi.initlog("%s", "Testing initlog 1") |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
162 cgi.log("%s", "Testing log 2") |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
163 self.assertEqual(cgi.logfp.getvalue(), "Testing initlog 1\nTesting log 2\n") |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
164 if os.path.exists("/dev/null"): |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
165 cgi.logfp = None |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
166 cgi.logfile = "/dev/null" |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
167 cgi.initlog("%s", "Testing log 3") |
|
71337
66e519792e4c
Add cgi.closelog() function to close the log file
Victor Stinner <victor.stinner@haypocalc.com>
parents:
71324
diff
changeset
|
168 self.addCleanup(cgi.closelog) |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
169 cgi.log("Testing log 4") |
|
13842
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
170 |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
171 def test_fieldstorage_readline(self): |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
172 # FieldStorage uses readline, which has the capacity to read all |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
173 # contents of the input file into memory; we use readline's size argument |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
174 # to prevent that for files that do not contain any newlines in |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
175 # non-GET/HEAD requests |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
176 class TestReadlineFile: |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
177 def __init__(self, file): |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
178 self.file = file |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
179 self.numcalls = 0 |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39575
diff
changeset
|
180 |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
181 def readline(self, size=None): |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
182 self.numcalls += 1 |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
183 if size: |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
184 return self.file.readline(size) |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
185 else: |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
186 return self.file.readline() |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39575
diff
changeset
|
187 |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
188 def __getattr__(self, name): |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
189 file = self.__dict__['file'] |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
190 a = getattr(file, name) |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
191 if not isinstance(a, int): |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
192 setattr(self, name, a) |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
193 return a |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39575
diff
changeset
|
194 |
|
67590
d864328a74e4
Issue #4953: cgi.FieldStorage and cgi.parse() parse the request as bytes, not
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66530
diff
changeset
|
195 f = TestReadlineFile(tempfile.TemporaryFile("wb+")) |
|
65774
24b18cd4d5f3
close files properly
Benjamin Peterson <benjamin@python.org>
parents:
59761
diff
changeset
|
196 self.addCleanup(f.close) |
|
67590
d864328a74e4
Issue #4953: cgi.FieldStorage and cgi.parse() parse the request as bytes, not
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66530
diff
changeset
|
197 f.write(b'x' * 256 * 1024) |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
198 f.seek(0) |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
199 env = {'REQUEST_METHOD':'PUT'} |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
200 fs = cgi.FieldStorage(fp=f, environ=env) |
|
65774
24b18cd4d5f3
close files properly
Benjamin Peterson <benjamin@python.org>
parents:
59761
diff
changeset
|
201 self.addCleanup(fs.file.close) |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
202 # if we're not chunking properly, readline is only called twice |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
203 # (by read_binary); if we are chunking properly, it will be called 5 times |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
204 # as long as the chunksize is 1 << 16. |
|
55593
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49976
diff
changeset
|
205 self.assertTrue(f.numcalls > 2) |
|
67590
d864328a74e4
Issue #4953: cgi.FieldStorage and cgi.parse() parse the request as bytes, not
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66530
diff
changeset
|
206 f.close() |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39575
diff
changeset
|
207 |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
208 def test_fieldstorage_multipart(self): |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
209 #Test basic FieldStorage multipart parsing |
|
68200
1d198518cb87
Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68095
diff
changeset
|
210 env = { |
|
1d198518cb87
Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68095
diff
changeset
|
211 'REQUEST_METHOD': 'POST', |
|
1d198518cb87
Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68095
diff
changeset
|
212 'CONTENT_TYPE': 'multipart/form-data; boundary={}'.format(BOUNDARY), |
|
1d198518cb87
Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68095
diff
changeset
|
213 'CONTENT_LENGTH': '558'} |
|
1d198518cb87
Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68095
diff
changeset
|
214 fp = BytesIO(POSTDATA.encode('latin-1')) |
|
1d198518cb87
Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68095
diff
changeset
|
215 fs = cgi.FieldStorage(fp, environ=env, encoding="latin-1") |
|
66340
2beb25369289
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
55593
diff
changeset
|
216 self.assertEqual(len(fs.list), 4) |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
217 expect = [{'name':'id', 'filename':None, 'value':'1234'}, |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
218 {'name':'title', 'filename':None, 'value':''}, |
|
67590
d864328a74e4
Issue #4953: cgi.FieldStorage and cgi.parse() parse the request as bytes, not
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66530
diff
changeset
|
219 {'name':'file', 'filename':'test.txt', 'value':b'Testing 123.\n'}, |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
220 {'name':'submit', 'filename':None, 'value':' Add '}] |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
221 for x in range(len(fs.list)): |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
222 for k, exp in expect[x].items(): |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
223 got = getattr(fs.list[x], k) |
|
66340
2beb25369289
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
55593
diff
changeset
|
224 self.assertEqual(got, exp) |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39575
diff
changeset
|
225 |
|
68200
1d198518cb87
Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68095
diff
changeset
|
226 def test_fieldstorage_multipart_non_ascii(self): |
|
1d198518cb87
Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68095
diff
changeset
|
227 #Test basic FieldStorage multipart parsing |
|
1d198518cb87
Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68095
diff
changeset
|
228 env = {'REQUEST_METHOD':'POST', |
|
1d198518cb87
Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68095
diff
changeset
|
229 'CONTENT_TYPE': 'multipart/form-data; boundary={}'.format(BOUNDARY), |
|
1d198518cb87
Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68095
diff
changeset
|
230 'CONTENT_LENGTH':'558'} |
|
1d198518cb87
Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68095
diff
changeset
|
231 for encoding in ['iso-8859-1','utf-8']: |
|
1d198518cb87
Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68095
diff
changeset
|
232 fp = BytesIO(POSTDATA_NON_ASCII.encode(encoding)) |
|
1d198518cb87
Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68095
diff
changeset
|
233 fs = cgi.FieldStorage(fp, environ=env,encoding=encoding) |
|
1d198518cb87
Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68095
diff
changeset
|
234 self.assertEqual(len(fs.list), 1) |
|
1d198518cb87
Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68095
diff
changeset
|
235 expect = [{'name':'id', 'filename':None, 'value':'\xe7\xf1\x80'}] |
|
1d198518cb87
Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68095
diff
changeset
|
236 for x in range(len(fs.list)): |
|
1d198518cb87
Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68095
diff
changeset
|
237 for k, exp in expect[x].items(): |
|
1d198518cb87
Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68095
diff
changeset
|
238 got = getattr(fs.list[x], k) |
|
1d198518cb87
Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68095
diff
changeset
|
239 self.assertEqual(got, exp) |
|
1d198518cb87
Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68095
diff
changeset
|
240 |
|
48410
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
241 _qs_result = { |
|
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
242 'key1': 'value1', |
|
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
243 'key2': ['value2x', 'value2y'], |
|
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
244 'key3': 'value3', |
|
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
245 'key4': 'value4' |
|
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
246 } |
|
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
247 def testQSAndUrlEncode(self): |
|
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
248 data = "key2=value2x&key3=value3&key4=value4" |
|
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
249 environ = { |
|
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
250 'CONTENT_LENGTH': str(len(data)), |
|
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
251 'CONTENT_TYPE': 'application/x-www-form-urlencoded', |
|
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
252 'QUERY_STRING': 'key1=value1&key2=value2y', |
|
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
253 'REQUEST_METHOD': 'POST', |
|
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
254 } |
|
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
255 v = gen_result(data, environ) |
|
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
256 self.assertEqual(self._qs_result, v) |
|
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
257 |
|
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
258 def testQSAndFormData(self): |
|
67590
d864328a74e4
Issue #4953: cgi.FieldStorage and cgi.parse() parse the request as bytes, not
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66530
diff
changeset
|
259 data = """---123 |
|
48410
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
260 Content-Disposition: form-data; name="key2" |
|
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
261 |
|
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
262 value2y |
|
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
263 ---123 |
|
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
264 Content-Disposition: form-data; name="key3" |
|
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
265 |
|
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
266 value3 |
|
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
267 ---123 |
|
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
268 Content-Disposition: form-data; name="key4" |
|
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
269 |
|
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
270 value4 |
|
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
271 ---123-- |
|
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
272 """ |
|
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
273 environ = { |
|
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
274 'CONTENT_LENGTH': str(len(data)), |
|
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
275 'CONTENT_TYPE': 'multipart/form-data; boundary=-123', |
|
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
276 'QUERY_STRING': 'key1=value1&key2=value2x', |
|
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
277 'REQUEST_METHOD': 'POST', |
|
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
278 } |
|
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
279 v = gen_result(data, environ) |
|
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
280 self.assertEqual(self._qs_result, v) |
|
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
281 |
|
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
282 def testQSAndFormDataFile(self): |
|
67590
d864328a74e4
Issue #4953: cgi.FieldStorage and cgi.parse() parse the request as bytes, not
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66530
diff
changeset
|
283 data = """---123 |
|
48410
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
284 Content-Disposition: form-data; name="key2" |
|
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
285 |
|
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
286 value2y |
|
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
287 ---123 |
|
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
288 Content-Disposition: form-data; name="key3" |
|
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
289 |
|
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
290 value3 |
|
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
291 ---123 |
|
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
292 Content-Disposition: form-data; name="key4" |
|
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
293 |
|
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
294 value4 |
|
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
295 ---123 |
|
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
296 Content-Disposition: form-data; name="upload"; filename="fake.txt" |
|
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
297 Content-Type: text/plain |
|
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
298 |
|
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
299 this is the content of the fake file |
|
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
300 |
|
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
301 ---123-- |
|
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
302 """ |
|
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
303 environ = { |
|
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
304 'CONTENT_LENGTH': str(len(data)), |
|
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
305 'CONTENT_TYPE': 'multipart/form-data; boundary=-123', |
|
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
306 'QUERY_STRING': 'key1=value1&key2=value2x', |
|
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
307 'REQUEST_METHOD': 'POST', |
|
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
308 } |
|
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
309 result = self._qs_result.copy() |
|
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
310 result.update({ |
|
67590
d864328a74e4
Issue #4953: cgi.FieldStorage and cgi.parse() parse the request as bytes, not
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66530
diff
changeset
|
311 'upload': b'this is the content of the fake file\n' |
|
48410
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
312 }) |
|
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
313 v = gen_result(data, environ) |
|
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
314 self.assertEqual(result, v) |
|
81fd8a8baa9a
Merged revisions 64434-64435,64440-64443,64445,64447-64448,64450,64452,64455,64461,64464,64466,64468 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47632
diff
changeset
|
315 |
|
49081
f085f39a6f4d
Added sanity checks for the deprecated parse_qs() and
Facundo Batista <facundobatista@gmail.com>
parents:
48998
diff
changeset
|
316 def test_deprecated_parse_qs(self): |
|
59671
80dc4d131d85
Merged revisions 79030-79032 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58415
diff
changeset
|
317 # this func is moved to urllib.parse, this is just a sanity check |
|
80dc4d131d85
Merged revisions 79030-79032 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58415
diff
changeset
|
318 with check_warnings(('cgi.parse_qs is deprecated, use urllib.parse.' |
|
80dc4d131d85
Merged revisions 79030-79032 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58415
diff
changeset
|
319 'parse_qs instead', DeprecationWarning)): |
|
49101
c46bcccf2af2
Added a warning filter to don't show the warning during
Facundo Batista <facundobatista@gmail.com>
parents:
49081
diff
changeset
|
320 self.assertEqual({'a': ['A1'], 'B': ['B3'], 'b': ['B2']}, |
|
c46bcccf2af2
Added a warning filter to don't show the warning during
Facundo Batista <facundobatista@gmail.com>
parents:
49081
diff
changeset
|
321 cgi.parse_qs('a=A1&b=B2&B=B3')) |
|
49081
f085f39a6f4d
Added sanity checks for the deprecated parse_qs() and
Facundo Batista <facundobatista@gmail.com>
parents:
48998
diff
changeset
|
322 |
|
f085f39a6f4d
Added sanity checks for the deprecated parse_qs() and
Facundo Batista <facundobatista@gmail.com>
parents:
48998
diff
changeset
|
323 def test_deprecated_parse_qsl(self): |
|
59671
80dc4d131d85
Merged revisions 79030-79032 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58415
diff
changeset
|
324 # this func is moved to urllib.parse, this is just a sanity check |
|
80dc4d131d85
Merged revisions 79030-79032 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58415
diff
changeset
|
325 with check_warnings(('cgi.parse_qsl is deprecated, use urllib.parse.' |
|
80dc4d131d85
Merged revisions 79030-79032 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58415
diff
changeset
|
326 'parse_qsl instead', DeprecationWarning)): |
|
49101
c46bcccf2af2
Added a warning filter to don't show the warning during
Facundo Batista <facundobatista@gmail.com>
parents:
49081
diff
changeset
|
327 self.assertEqual([('a', 'A1'), ('b', 'B2'), ('B', 'B3')], |
|
c46bcccf2af2
Added a warning filter to don't show the warning during
Facundo Batista <facundobatista@gmail.com>
parents:
49081
diff
changeset
|
328 cgi.parse_qsl('a=A1&b=B2&B=B3')) |
|
49081
f085f39a6f4d
Added sanity checks for the deprecated parse_qs() and
Facundo Batista <facundobatista@gmail.com>
parents:
48998
diff
changeset
|
329 |
|
49976
89e738c792c0
Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49101
diff
changeset
|
330 def test_parse_header(self): |
|
89e738c792c0
Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49101
diff
changeset
|
331 self.assertEqual( |
|
89e738c792c0
Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49101
diff
changeset
|
332 cgi.parse_header("text/plain"), |
|
89e738c792c0
Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49101
diff
changeset
|
333 ("text/plain", {})) |
|
89e738c792c0
Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49101
diff
changeset
|
334 self.assertEqual( |
|
89e738c792c0
Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49101
diff
changeset
|
335 cgi.parse_header("text/vnd.just.made.this.up ; "), |
|
89e738c792c0
Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49101
diff
changeset
|
336 ("text/vnd.just.made.this.up", {})) |
|
89e738c792c0
Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49101
diff
changeset
|
337 self.assertEqual( |
|
89e738c792c0
Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49101
diff
changeset
|
338 cgi.parse_header("text/plain;charset=us-ascii"), |
|
89e738c792c0
Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49101
diff
changeset
|
339 ("text/plain", {"charset": "us-ascii"})) |
|
89e738c792c0
Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49101
diff
changeset
|
340 self.assertEqual( |
|
89e738c792c0
Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49101
diff
changeset
|
341 cgi.parse_header('text/plain ; charset="us-ascii"'), |
|
89e738c792c0
Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49101
diff
changeset
|
342 ("text/plain", {"charset": "us-ascii"})) |
|
89e738c792c0
Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49101
diff
changeset
|
343 self.assertEqual( |
|
89e738c792c0
Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49101
diff
changeset
|
344 cgi.parse_header('text/plain ; charset="us-ascii"; another=opt'), |
|
89e738c792c0
Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49101
diff
changeset
|
345 ("text/plain", {"charset": "us-ascii", "another": "opt"})) |
|
89e738c792c0
Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49101
diff
changeset
|
346 self.assertEqual( |
|
89e738c792c0
Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49101
diff
changeset
|
347 cgi.parse_header('attachment; filename="silly.txt"'), |
|
89e738c792c0
Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49101
diff
changeset
|
348 ("attachment", {"filename": "silly.txt"})) |
|
89e738c792c0
Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49101
diff
changeset
|
349 self.assertEqual( |
|
89e738c792c0
Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49101
diff
changeset
|
350 cgi.parse_header('attachment; filename="strange;name"'), |
|
89e738c792c0
Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49101
diff
changeset
|
351 ("attachment", {"filename": "strange;name"})) |
|
89e738c792c0
Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49101
diff
changeset
|
352 self.assertEqual( |
|
89e738c792c0
Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49101
diff
changeset
|
353 cgi.parse_header('attachment; filename="strange;name";size=123;'), |
|
89e738c792c0
Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49101
diff
changeset
|
354 ("attachment", {"filename": "strange;name", "size": "123"})) |
|
72989
f5bd78b11275
3.2 - Fix closes Issue12529 - cgi.parse_header failure on double quotes and
Senthil Kumaran <senthil@uthcode.com>
parents:
71324
diff
changeset
|
355 self.assertEqual( |
|
f5bd78b11275
3.2 - Fix closes Issue12529 - cgi.parse_header failure on double quotes and
Senthil Kumaran <senthil@uthcode.com>
parents:
71324
diff
changeset
|
356 cgi.parse_header('form-data; name="files"; filename="fo\\"o;bar"'), |
|
f5bd78b11275
3.2 - Fix closes Issue12529 - cgi.parse_header failure on double quotes and
Senthil Kumaran <senthil@uthcode.com>
parents:
71324
diff
changeset
|
357 ("form-data", {"name": "files", "filename": 'fo"o;bar'})) |
|
f5bd78b11275
3.2 - Fix closes Issue12529 - cgi.parse_header failure on double quotes and
Senthil Kumaran <senthil@uthcode.com>
parents:
71324
diff
changeset
|
358 |
|
49976
89e738c792c0
Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49101
diff
changeset
|
359 |
|
68200
1d198518cb87
Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68095
diff
changeset
|
360 BOUNDARY = "---------------------------721837373350705526688164684" |
|
1d198518cb87
Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68095
diff
changeset
|
361 |
|
1d198518cb87
Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68095
diff
changeset
|
362 POSTDATA = """-----------------------------721837373350705526688164684 |
|
1d198518cb87
Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68095
diff
changeset
|
363 Content-Disposition: form-data; name="id" |
|
1d198518cb87
Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68095
diff
changeset
|
364 |
|
1d198518cb87
Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68095
diff
changeset
|
365 1234 |
|
1d198518cb87
Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68095
diff
changeset
|
366 -----------------------------721837373350705526688164684 |
|
1d198518cb87
Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68095
diff
changeset
|
367 Content-Disposition: form-data; name="title" |
|
1d198518cb87
Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68095
diff
changeset
|
368 |
|
1d198518cb87
Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68095
diff
changeset
|
369 |
|
1d198518cb87
Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68095
diff
changeset
|
370 -----------------------------721837373350705526688164684 |
|
1d198518cb87
Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68095
diff
changeset
|
371 Content-Disposition: form-data; name="file"; filename="test.txt" |
|
1d198518cb87
Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68095
diff
changeset
|
372 Content-Type: text/plain |
|
1d198518cb87
Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68095
diff
changeset
|
373 |
|
1d198518cb87
Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68095
diff
changeset
|
374 Testing 123. |
|
1d198518cb87
Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68095
diff
changeset
|
375 |
|
1d198518cb87
Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68095
diff
changeset
|
376 -----------------------------721837373350705526688164684 |
|
1d198518cb87
Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68095
diff
changeset
|
377 Content-Disposition: form-data; name="submit" |
|
1d198518cb87
Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68095
diff
changeset
|
378 |
|
1d198518cb87
Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68095
diff
changeset
|
379 Add\x20 |
|
1d198518cb87
Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68095
diff
changeset
|
380 -----------------------------721837373350705526688164684-- |
|
1d198518cb87
Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68095
diff
changeset
|
381 """ |
|
1d198518cb87
Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68095
diff
changeset
|
382 |
|
1d198518cb87
Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68095
diff
changeset
|
383 POSTDATA_NON_ASCII = """-----------------------------721837373350705526688164684 |
|
1d198518cb87
Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68095
diff
changeset
|
384 Content-Disposition: form-data; name="id" |
|
1d198518cb87
Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68095
diff
changeset
|
385 |
|
1d198518cb87
Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68095
diff
changeset
|
386 \xe7\xf1\x80 |
|
1d198518cb87
Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68095
diff
changeset
|
387 -----------------------------721837373350705526688164684 |
|
1d198518cb87
Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68095
diff
changeset
|
388 """ |
|
1d198518cb87
Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68095
diff
changeset
|
389 |
|
49976
89e738c792c0
Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49101
diff
changeset
|
390 |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
391 def test_main(): |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
392 run_unittest(CgiTests) |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
393 |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
394 if __name__ == '__main__': |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
395 test_main() |
