Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_cgi.py @ 70817:dd775b1561ba
Fix markup.
| author | Georg Brandl <georg@python.org> |
|---|---|
| date | Tue, 14 Jun 2011 21:09:55 +0200 |
| parents | 3c9232a684ae |
| children | 530ba6c7e578 |
| 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 |
|
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
|
7 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
|
8 |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
9 class HackedSysModule: |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
10 # 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
|
11 # 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
|
12 argv = [] |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
13 stdin = sys.stdin |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
14 |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
15 cgi.sys = HackedSysModule() |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
16 |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
17 class ComparableException: |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
18 def __init__(self, err): |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
19 self.err = err |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
20 |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
21 def __str__(self): |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
22 return str(self.err) |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
23 |
|
39644
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39610
diff
changeset
|
24 def __eq__(self, anExc): |
|
13842
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
25 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
|
26 return NotImplemented |
|
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39610
diff
changeset
|
27 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
|
28 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
|
29 |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
30 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
|
31 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
|
32 |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
33 def do_test(buf, method): |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
34 env = {} |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
35 if method == "GET": |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
36 fp = None |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
37 env['REQUEST_METHOD'] = 'GET' |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
38 env['QUERY_STRING'] = buf |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
39 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
|
40 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
|
41 env['REQUEST_METHOD'] = 'POST' |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
42 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
|
43 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
|
44 else: |
|
43014
9834301a2fd3
Raise statement normalization in Lib/test/.
Collin Winter <collinw@gmail.com>
parents:
42930
diff
changeset
|
45 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
|
46 try: |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
47 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
|
48 except Exception as err: |
|
13842
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
49 return ComparableException(err) |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
50 |
|
32758
859ea8612eb0
Don't return spurious empty fields if 'keep_empty_values' is True.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
24442
diff
changeset
|
51 parse_strict_test_cases = [ |
|
13842
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
52 ("", ValueError("bad query field: ''")), |
|
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: ''")), |
|
14606
f2fc66a6153b
fix bug #110661 (PR#356) -- accept either & or ; as separator for CGI
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14196
diff
changeset
|
55 (";", 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
|
56 (";&;", ValueError("bad query field: ''")), |
|
13842
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
57 # 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
|
58 ("=", {}), |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
59 ("=&=", {}), |
|
14606
f2fc66a6153b
fix bug #110661 (PR#356) -- accept either & or ; as separator for CGI
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14196
diff
changeset
|
60 ("=;=", {}), |
|
13842
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
61 # 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
|
62 ("=a", {'': ['a']}), |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
63 ("&=a", ValueError("bad query field: ''")), |
|
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: 'a'")), |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
66 ("b=a", {'b': ['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 ("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
|
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 ("&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
|
71 ("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
|
72 ("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
|
73 ("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
|
74 ("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
|
75 ("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
|
76 ("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
|
77 ("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
|
78 {'Hbc5161168c542333633315dee1182227:key_store_seqid': ['400006'], |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
79 'cuyer': ['r'], |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
80 'expire': ['964546263'], |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
81 'kid': ['130003.300038'], |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
82 'lobale': ['en-US'], |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
83 'order_id': ['0bb2e248638833d48cb7fed300000f1b'], |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
84 'ss': ['env'], |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
85 'view': ['bustomer'], |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
86 }), |
|
15305
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14606
diff
changeset
|
87 |
|
13842
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
88 ("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
|
89 {'SUBMIT': ['Browse'], |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
90 '_assigned_to': ['31392'], |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
91 '_category': ['100'], |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
92 '_status': ['1'], |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
93 'group_id': ['5470'], |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
94 'set': ['custom'], |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
95 }) |
|
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 |
|
39644
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39610
diff
changeset
|
98 def norm(seq): |
|
40809
f340cb045bf9
- PEP 3106: dict.iterkeys(), .iteritems(), .itervalues() are now gone;
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
99 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
|
100 |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
101 def first_elts(list): |
|
42142
a53e48be6df9
Merged revisions 56125-56153 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42084
diff
changeset
|
102 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
|
103 |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
104 def first_second_elts(list): |
|
42142
a53e48be6df9
Merged revisions 56125-56153 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
42084
diff
changeset
|
105 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
|
106 |
|
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
|
107 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
|
108 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
|
109 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
|
110 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
|
111 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
|
112 |
|
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 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
|
114 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
|
115 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
|
116 |
|
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 return result |
|
13842
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
118 |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
119 class CgiTests(unittest.TestCase): |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
120 |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
121 def test_strict(self): |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
122 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
|
123 # Test basic parsing |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
124 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
|
125 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
|
126 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
|
127 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
|
128 |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
129 env = {'QUERY_STRING': orig} |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
130 fs = cgi.FieldStorage(environ=env) |
|
59671
80dc4d131d85
Merged revisions 79030-79032 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58415
diff
changeset
|
131 if isinstance(expect, dict): |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
132 # test dict interface |
|
46915
e94574455d9d
Remove old backwards-compatibility classes from the cgi module.
Georg Brandl <georg@python.org>
parents:
43014
diff
changeset
|
133 self.assertEqual(len(expect), len(fs)) |
|
66530
93cd4de8ee0b
Use assertCountEqual instead of assertItemsEqual
Ezio Melotti <ezio.melotti@gmail.com>
parents:
66310
diff
changeset
|
134 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
|
135 ##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
|
136 ##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
|
137 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
|
138 # test individual fields |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
139 for key in expect.keys(): |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
140 expect_val = expect[key] |
|
58415
f6a626f34840
use assert[Not]In where appropriate
Benjamin Peterson <benjamin@python.org>
parents:
55593
diff
changeset
|
141 self.assertIn(key, fs) |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
142 if len(expect_val) > 1: |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
143 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
|
144 else: |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
145 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
|
146 |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
147 def test_log(self): |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
148 cgi.log("Testing") |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
149 |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
150 cgi.logfp = StringIO() |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
151 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
|
152 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
|
153 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
|
154 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
|
155 cgi.logfp = None |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
156 cgi.logfile = "/dev/null" |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
157 cgi.initlog("%s", "Testing log 3") |
|
68095
ae186b3b2c55
Issue #10512: close the log file in cgi when running tests.
Brett Cannon <bcannon@gmail.com>
parents:
67590
diff
changeset
|
158 self.addCleanup(cgi.logfp.close) |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
159 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
|
160 |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
161 def test_fieldstorage_readline(self): |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
162 # 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
|
163 # 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
|
164 # 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
|
165 # non-GET/HEAD requests |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
166 class TestReadlineFile: |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
167 def __init__(self, file): |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
168 self.file = file |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
169 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
|
170 |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
171 def readline(self, size=None): |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
172 self.numcalls += 1 |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
173 if size: |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
174 return self.file.readline(size) |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
175 else: |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
176 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
|
177 |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
178 def __getattr__(self, name): |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
179 file = self.__dict__['file'] |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
180 a = getattr(file, name) |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
181 if not isinstance(a, int): |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
182 setattr(self, name, a) |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
183 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
|
184 |
|
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
|
185 f = TestReadlineFile(tempfile.TemporaryFile("wb+")) |
|
65774
24b18cd4d5f3
close files properly
Benjamin Peterson <benjamin@python.org>
parents:
59761
diff
changeset
|
186 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
|
187 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
|
188 f.seek(0) |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
189 env = {'REQUEST_METHOD':'PUT'} |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
190 fs = cgi.FieldStorage(fp=f, environ=env) |
|
65774
24b18cd4d5f3
close files properly
Benjamin Peterson <benjamin@python.org>
parents:
59761
diff
changeset
|
191 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
|
192 # 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
|
193 # (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
|
194 # 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
|
195 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
|
196 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
|
197 |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
198 def test_fieldstorage_multipart(self): |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
199 #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
|
200 env = { |
|
1d198518cb87
Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68095
diff
changeset
|
201 'REQUEST_METHOD': 'POST', |
|
1d198518cb87
Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68095
diff
changeset
|
202 '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
|
203 'CONTENT_LENGTH': '558'} |
|
1d198518cb87
Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68095
diff
changeset
|
204 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
|
205 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
|
206 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
|
207 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
|
208 {'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
|
209 {'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
|
210 {'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
|
211 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
|
212 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
|
213 got = getattr(fs.list[x], k) |
|
66340
2beb25369289
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
55593
diff
changeset
|
214 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
|
215 |
|
68200
1d198518cb87
Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68095
diff
changeset
|
216 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
|
217 #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
|
218 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
|
219 '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
|
220 'CONTENT_LENGTH':'558'} |
|
1d198518cb87
Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68095
diff
changeset
|
221 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
|
222 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
|
223 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
|
224 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
|
225 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
|
226 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
|
227 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
|
228 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
|
229 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
|
230 |
|
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
|
231 _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
|
232 '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
|
233 '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
|
234 '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
|
235 '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
|
236 } |
|
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
|
237 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
|
238 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
|
239 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
|
240 '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
|
241 '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
|
242 '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
|
243 '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
|
244 } |
|
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 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
|
246 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
|
247 |
|
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 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
|
249 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
|
250 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
|
251 |
|
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 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 ---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
|
254 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
|
255 |
|
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 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
|
257 ---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
|
258 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
|
259 |
|
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 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
|
261 ---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
|
262 """ |
|
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 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
|
264 '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
|
265 '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
|
266 '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
|
267 '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
|
268 } |
|
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 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
|
270 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
|
271 |
|
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 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
|
273 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
|
274 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
|
275 |
|
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 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
|
277 ---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
|
278 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
|
279 |
|
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 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
|
281 ---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
|
282 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
|
283 |
|
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 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
|
285 ---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
|
286 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
|
287 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
|
288 |
|
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 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
|
290 |
|
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 """ |
|
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 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
|
294 '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
|
295 '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
|
296 '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
|
297 '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
|
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 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
|
300 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
|
301 '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
|
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 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
|
304 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
|
305 |
|
49081
f085f39a6f4d
Added sanity checks for the deprecated parse_qs() and
Facundo Batista <facundobatista@gmail.com>
parents:
48998
diff
changeset
|
306 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
|
307 # 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
|
308 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
|
309 '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
|
310 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
|
311 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
|
312 |
|
f085f39a6f4d
Added sanity checks for the deprecated parse_qs() and
Facundo Batista <facundobatista@gmail.com>
parents:
48998
diff
changeset
|
313 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
|
314 # 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
|
315 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
|
316 '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
|
317 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
|
318 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
|
319 |
|
49976
89e738c792c0
Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49101
diff
changeset
|
320 def test_parse_header(self): |
|
89e738c792c0
Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49101
diff
changeset
|
321 self.assertEqual( |
|
89e738c792c0
Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49101
diff
changeset
|
322 cgi.parse_header("text/plain"), |
|
89e738c792c0
Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49101
diff
changeset
|
323 ("text/plain", {})) |
|
89e738c792c0
Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49101
diff
changeset
|
324 self.assertEqual( |
|
89e738c792c0
Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49101
diff
changeset
|
325 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
|
326 ("text/vnd.just.made.this.up", {})) |
|
89e738c792c0
Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49101
diff
changeset
|
327 self.assertEqual( |
|
89e738c792c0
Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49101
diff
changeset
|
328 cgi.parse_header("text/plain;charset=us-ascii"), |
|
89e738c792c0
Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49101
diff
changeset
|
329 ("text/plain", {"charset": "us-ascii"})) |
|
89e738c792c0
Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49101
diff
changeset
|
330 self.assertEqual( |
|
89e738c792c0
Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49101
diff
changeset
|
331 cgi.parse_header('text/plain ; charset="us-ascii"'), |
|
89e738c792c0
Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49101
diff
changeset
|
332 ("text/plain", {"charset": "us-ascii"})) |
|
89e738c792c0
Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49101
diff
changeset
|
333 self.assertEqual( |
|
89e738c792c0
Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49101
diff
changeset
|
334 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
|
335 ("text/plain", {"charset": "us-ascii", "another": "opt"})) |
|
89e738c792c0
Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49101
diff
changeset
|
336 self.assertEqual( |
|
89e738c792c0
Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49101
diff
changeset
|
337 cgi.parse_header('attachment; filename="silly.txt"'), |
|
89e738c792c0
Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49101
diff
changeset
|
338 ("attachment", {"filename": "silly.txt"})) |
|
89e738c792c0
Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49101
diff
changeset
|
339 self.assertEqual( |
|
89e738c792c0
Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49101
diff
changeset
|
340 cgi.parse_header('attachment; filename="strange;name"'), |
|
89e738c792c0
Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49101
diff
changeset
|
341 ("attachment", {"filename": "strange;name"})) |
|
89e738c792c0
Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49101
diff
changeset
|
342 self.assertEqual( |
|
89e738c792c0
Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49101
diff
changeset
|
343 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
|
344 ("attachment", {"filename": "strange;name", "size": "123"})) |
|
89e738c792c0
Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49101
diff
changeset
|
345 |
|
68200
1d198518cb87
Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68095
diff
changeset
|
346 BOUNDARY = "---------------------------721837373350705526688164684" |
|
1d198518cb87
Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68095
diff
changeset
|
347 |
|
1d198518cb87
Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68095
diff
changeset
|
348 POSTDATA = """-----------------------------721837373350705526688164684 |
|
1d198518cb87
Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68095
diff
changeset
|
349 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
|
350 |
|
1d198518cb87
Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68095
diff
changeset
|
351 1234 |
|
1d198518cb87
Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68095
diff
changeset
|
352 -----------------------------721837373350705526688164684 |
|
1d198518cb87
Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68095
diff
changeset
|
353 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
|
354 |
|
1d198518cb87
Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68095
diff
changeset
|
355 |
|
1d198518cb87
Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68095
diff
changeset
|
356 -----------------------------721837373350705526688164684 |
|
1d198518cb87
Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68095
diff
changeset
|
357 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
|
358 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
|
359 |
|
1d198518cb87
Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68095
diff
changeset
|
360 Testing 123. |
|
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 -----------------------------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="submit" |
|
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 Add\x20 |
|
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 """ |
|
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 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
|
370 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
|
371 |
|
1d198518cb87
Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68095
diff
changeset
|
372 \xe7\xf1\x80 |
|
1d198518cb87
Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68095
diff
changeset
|
373 -----------------------------721837373350705526688164684 |
|
1d198518cb87
Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68095
diff
changeset
|
374 """ |
|
1d198518cb87
Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68095
diff
changeset
|
375 |
|
49976
89e738c792c0
Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49101
diff
changeset
|
376 |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
377 def test_main(): |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
378 run_unittest(CgiTests) |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
379 |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
380 if __name__ == '__main__': |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39644
diff
changeset
|
381 test_main() |
