annotate Lib/test/test_cgi.py @ 87690:66c1c9f32567 default tip

Add use_weakref option to functools.lru_cache The use_weakref option makes lru_cache create weak references to the function arguments when creating the cache key, which prevents them from staying in the memory forever even after all other references to them are gone. This is a proof of concept for http://bugs.python.org/issue19859
author Radomir Dopieralski <devel@sheep.art.pl>
date Tue, 03 Dec 2013 16:02:48 +0100
parents 406ce103c170
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
81674
a46a0dafcb7a Issue #12411: Fix to cgi.parse_multipart to correctly use bytes boundaries and
Senthil Kumaran <senthil@uthcode.com>
parents: 75582
diff changeset
8 from collections import namedtuple
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
9 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
10
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
11 class HackedSysModule:
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
12 # 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
13 # 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
14 argv = []
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
15 stdin = sys.stdin
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 cgi.sys = HackedSysModule()
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
18
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
19 class ComparableException:
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
20 def __init__(self, err):
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
21 self.err = err
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
22
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
23 def __str__(self):
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
24 return str(self.err)
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
25
39644
13d5e5f0e993 Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents: 39610
diff changeset
26 def __eq__(self, anExc):
13842
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
27 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
28 return NotImplemented
13d5e5f0e993 Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents: 39610
diff changeset
29 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
30 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
31
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
32 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
33 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
34
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
35 def do_test(buf, method):
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
36 env = {}
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
37 if method == "GET":
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
38 fp = None
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
39 env['REQUEST_METHOD'] = 'GET'
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
40 env['QUERY_STRING'] = buf
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
41 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
42 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
43 env['REQUEST_METHOD'] = 'POST'
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
44 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
45 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
46 else:
43014
9834301a2fd3 Raise statement normalization in Lib/test/.
Collin Winter <collinw@gmail.com>
parents: 42930
diff changeset
47 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
48 try:
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
49 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
50 except Exception as err:
13842
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
51 return ComparableException(err)
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
52
32758
859ea8612eb0 Don't return spurious empty fields if 'keep_empty_values' is True.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 24442
diff changeset
53 parse_strict_test_cases = [
13842
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: ''")),
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
56 ("&&", 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
57 (";", 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
58 (";&;", ValueError("bad query field: ''")),
13842
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
59 # 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
60 ("=", {}),
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
61 ("=&=", {}),
14606
f2fc66a6153b fix bug #110661 (PR#356) -- accept either & or ; as separator for CGI
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14196
diff changeset
62 ("=;=", {}),
13842
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
63 # 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
64 ("=a", {'': ['a']}),
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: ''")),
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
67 ("=&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
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 ("b+=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 ("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
72 ("&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
73 ("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
74 ("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
75 ("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
76 ("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
77 ("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
78 ("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
79 ("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
80 {'Hbc5161168c542333633315dee1182227:key_store_seqid': ['400006'],
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
81 'cuyer': ['r'],
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
82 'expire': ['964546263'],
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
83 'kid': ['130003.300038'],
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
84 'lobale': ['en-US'],
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
85 'order_id': ['0bb2e248638833d48cb7fed300000f1b'],
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
86 'ss': ['env'],
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
87 'view': ['bustomer'],
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
88 }),
15305
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14606
diff changeset
89
13842
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
90 ("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
91 {'SUBMIT': ['Browse'],
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
92 '_assigned_to': ['31392'],
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
93 '_category': ['100'],
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
94 '_status': ['1'],
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
95 'group_id': ['5470'],
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
96 'set': ['custom'],
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 ]
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
99
39644
13d5e5f0e993 Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents: 39610
diff changeset
100 def norm(seq):
40809
f340cb045bf9 - PEP 3106: dict.iterkeys(), .iteritems(), .itervalues() are now gone;
Guido van Rossum <guido@python.org>
parents: 40587
diff changeset
101 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
102
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
103 def first_elts(list):
42142
a53e48be6df9 Merged revisions 56125-56153 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
104 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
105
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
106 def first_second_elts(list):
42142
a53e48be6df9 Merged revisions 56125-56153 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42084
diff changeset
107 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
108
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
109 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
110 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
111 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
112 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
113 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
114
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 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
116 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
117 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
118
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
119 return result
13842
87488c3113f2 test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
120
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39644
diff changeset
121 class CgiTests(unittest.TestCase):
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39644
diff changeset
122
81674
a46a0dafcb7a Issue #12411: Fix to cgi.parse_multipart to correctly use bytes boundaries and
Senthil Kumaran <senthil@uthcode.com>
parents: 75582
diff changeset
123 def test_parse_multipart(self):
a46a0dafcb7a Issue #12411: Fix to cgi.parse_multipart to correctly use bytes boundaries and
Senthil Kumaran <senthil@uthcode.com>
parents: 75582
diff changeset
124 fp = BytesIO(POSTDATA.encode('latin1'))
a46a0dafcb7a Issue #12411: Fix to cgi.parse_multipart to correctly use bytes boundaries and
Senthil Kumaran <senthil@uthcode.com>
parents: 75582
diff changeset
125 env = {'boundary': BOUNDARY.encode('latin1'),
a46a0dafcb7a Issue #12411: Fix to cgi.parse_multipart to correctly use bytes boundaries and
Senthil Kumaran <senthil@uthcode.com>
parents: 75582
diff changeset
126 'CONTENT-LENGTH': '558'}
a46a0dafcb7a Issue #12411: Fix to cgi.parse_multipart to correctly use bytes boundaries and
Senthil Kumaran <senthil@uthcode.com>
parents: 75582
diff changeset
127 result = cgi.parse_multipart(fp, env)
a46a0dafcb7a Issue #12411: Fix to cgi.parse_multipart to correctly use bytes boundaries and
Senthil Kumaran <senthil@uthcode.com>
parents: 75582
diff changeset
128 expected = {'submit': [b' Add '], 'id': [b'1234'],
a46a0dafcb7a Issue #12411: Fix to cgi.parse_multipart to correctly use bytes boundaries and
Senthil Kumaran <senthil@uthcode.com>
parents: 75582
diff changeset
129 'file': [b'Testing 123.\n'], 'title': [b'']}
a46a0dafcb7a Issue #12411: Fix to cgi.parse_multipart to correctly use bytes boundaries and
Senthil Kumaran <senthil@uthcode.com>
parents: 75582
diff changeset
130 self.assertEqual(result, expected)
a46a0dafcb7a Issue #12411: Fix to cgi.parse_multipart to correctly use bytes boundaries and
Senthil Kumaran <senthil@uthcode.com>
parents: 75582
diff changeset
131
a46a0dafcb7a Issue #12411: Fix to cgi.parse_multipart to correctly use bytes boundaries and
Senthil Kumaran <senthil@uthcode.com>
parents: 75582
diff changeset
132 def test_fieldstorage_properties(self):
a46a0dafcb7a Issue #12411: Fix to cgi.parse_multipart to correctly use bytes boundaries and
Senthil Kumaran <senthil@uthcode.com>
parents: 75582
diff changeset
133 fs = cgi.FieldStorage()
a46a0dafcb7a Issue #12411: Fix to cgi.parse_multipart to correctly use bytes boundaries and
Senthil Kumaran <senthil@uthcode.com>
parents: 75582
diff changeset
134 self.assertFalse(fs)
a46a0dafcb7a Issue #12411: Fix to cgi.parse_multipart to correctly use bytes boundaries and
Senthil Kumaran <senthil@uthcode.com>
parents: 75582
diff changeset
135 self.assertIn("FieldStorage", repr(fs))
a46a0dafcb7a Issue #12411: Fix to cgi.parse_multipart to correctly use bytes boundaries and
Senthil Kumaran <senthil@uthcode.com>
parents: 75582
diff changeset
136 self.assertEqual(list(fs), list(fs.keys()))
a46a0dafcb7a Issue #12411: Fix to cgi.parse_multipart to correctly use bytes boundaries and
Senthil Kumaran <senthil@uthcode.com>
parents: 75582
diff changeset
137 fs.list.append(namedtuple('MockFieldStorage', 'name')('fieldvalue'))
a46a0dafcb7a Issue #12411: Fix to cgi.parse_multipart to correctly use bytes boundaries and
Senthil Kumaran <senthil@uthcode.com>
parents: 75582
diff changeset
138 self.assertTrue(fs)
a46a0dafcb7a Issue #12411: Fix to cgi.parse_multipart to correctly use bytes boundaries and
Senthil Kumaran <senthil@uthcode.com>
parents: 75582
diff changeset
139
75582
13922f6d87f2 3.2 - Fix closes Issue14281 - Test for cgi.escape by Brian Landers
Senthil Kumaran <senthil@uthcode.com>
parents: 72989
diff changeset
140 def test_escape(self):
76565
bc91c251a4e9 Silence DeprecationWarning for cgi.escape() usage in test_cgi.
Brett Cannon <brett@python.org>
parents: 75583
diff changeset
141 # cgi.escape() is deprecated.
bc91c251a4e9 Silence DeprecationWarning for cgi.escape() usage in test_cgi.
Brett Cannon <brett@python.org>
parents: 75583
diff changeset
142 with warnings.catch_warnings():
bc91c251a4e9 Silence DeprecationWarning for cgi.escape() usage in test_cgi.
Brett Cannon <brett@python.org>
parents: 75583
diff changeset
143 warnings.filterwarnings('ignore', 'cgi\.escape',
bc91c251a4e9 Silence DeprecationWarning for cgi.escape() usage in test_cgi.
Brett Cannon <brett@python.org>
parents: 75583
diff changeset
144 DeprecationWarning)
bc91c251a4e9 Silence DeprecationWarning for cgi.escape() usage in test_cgi.
Brett Cannon <brett@python.org>
parents: 75583
diff changeset
145 self.assertEqual("test &amp; string", cgi.escape("test & string"))
bc91c251a4e9 Silence DeprecationWarning for cgi.escape() usage in test_cgi.
Brett Cannon <brett@python.org>
parents: 75583
diff changeset
146 self.assertEqual("&lt;test string&gt;", cgi.escape("<test string>"))
bc91c251a4e9 Silence DeprecationWarning for cgi.escape() usage in test_cgi.
Brett Cannon <brett@python.org>
parents: 75583
diff changeset
147 self.assertEqual("&quot;test string&quot;", 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
148
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39644
diff changeset
149 def test_strict(self):
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39644
diff changeset
150 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
151 # Test basic parsing
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39644
diff changeset
152 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
153 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
154 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
155 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
156
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39644
diff changeset
157 env = {'QUERY_STRING': orig}
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39644
diff changeset
158 fs = cgi.FieldStorage(environ=env)
59671
80dc4d131d85 Merged revisions 79030-79032 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents: 58415
diff changeset
159 if isinstance(expect, dict):
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39644
diff changeset
160 # test dict interface
46915
e94574455d9d Remove old backwards-compatibility classes from the cgi module.
Georg Brandl <georg@python.org>
parents: 43014
diff changeset
161 self.assertEqual(len(expect), len(fs))
66530
93cd4de8ee0b Use assertCountEqual instead of assertItemsEqual
Ezio Melotti <ezio.melotti@gmail.com>
parents: 66310
diff changeset
162 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
163 ##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
164 ##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
165 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
166 # test individual fields
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39644
diff changeset
167 for key in expect.keys():
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39644
diff changeset
168 expect_val = expect[key]
58415
f6a626f34840 use assert[Not]In where appropriate
Benjamin Peterson <benjamin@python.org>
parents: 55593
diff changeset
169 self.assertIn(key, fs)
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39644
diff changeset
170 if len(expect_val) > 1:
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39644
diff changeset
171 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
172 else:
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39644
diff changeset
173 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
174
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39644
diff changeset
175 def test_log(self):
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39644
diff changeset
176 cgi.log("Testing")
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39644
diff changeset
177
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39644
diff changeset
178 cgi.logfp = StringIO()
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39644
diff changeset
179 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
180 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
181 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
182 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
183 cgi.logfp = None
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39644
diff changeset
184 cgi.logfile = "/dev/null"
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39644
diff changeset
185 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
186 self.addCleanup(cgi.closelog)
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39644
diff changeset
187 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
188
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39644
diff changeset
189 def test_fieldstorage_readline(self):
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39644
diff changeset
190 # 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
191 # 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
192 # 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
193 # non-GET/HEAD requests
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39644
diff changeset
194 class TestReadlineFile:
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39644
diff changeset
195 def __init__(self, file):
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39644
diff changeset
196 self.file = file
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39644
diff changeset
197 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
198
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39644
diff changeset
199 def readline(self, size=None):
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39644
diff changeset
200 self.numcalls += 1
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39644
diff changeset
201 if size:
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39644
diff changeset
202 return self.file.readline(size)
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39644
diff changeset
203 else:
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39644
diff changeset
204 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
205
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39644
diff changeset
206 def __getattr__(self, name):
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39644
diff changeset
207 file = self.__dict__['file']
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39644
diff changeset
208 a = getattr(file, name)
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39644
diff changeset
209 if not isinstance(a, int):
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39644
diff changeset
210 setattr(self, name, a)
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39644
diff changeset
211 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
212
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
213 f = TestReadlineFile(tempfile.TemporaryFile("wb+"))
65774
24b18cd4d5f3 close files properly
Benjamin Peterson <benjamin@python.org>
parents: 59761
diff changeset
214 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
215 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
216 f.seek(0)
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39644
diff changeset
217 env = {'REQUEST_METHOD':'PUT'}
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39644
diff changeset
218 fs = cgi.FieldStorage(fp=f, environ=env)
65774
24b18cd4d5f3 close files properly
Benjamin Peterson <benjamin@python.org>
parents: 59761
diff changeset
219 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
220 # 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
221 # (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
222 # 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
223 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
224 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
225
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39644
diff changeset
226 def test_fieldstorage_multipart(self):
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39644
diff changeset
227 #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
228 env = {
1d198518cb87 Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68095
diff changeset
229 'REQUEST_METHOD': 'POST',
1d198518cb87 Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68095
diff changeset
230 '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
231 'CONTENT_LENGTH': '558'}
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.encode('latin-1'))
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="latin-1")
66340
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 55593
diff changeset
234 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
235 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
236 {'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
237 {'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
238 {'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
239 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
240 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
241 got = getattr(fs.list[x], k)
66340
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 55593
diff changeset
242 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
243
68200
1d198518cb87 Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68095
diff changeset
244 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
245 #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
246 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
247 '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
248 'CONTENT_LENGTH':'558'}
1d198518cb87 Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68095
diff changeset
249 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
250 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
251 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
252 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
253 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
254 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
255 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
256 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
257 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
258
84182
a48f65bac986 Issue #18167: cgi.FieldStorage no more fails to handle multipart/form-data
Serhiy Storchaka <storchaka@gmail.com>
parents: 81675
diff changeset
259 def test_fieldstorage_multipart_maxline(self):
a48f65bac986 Issue #18167: cgi.FieldStorage no more fails to handle multipart/form-data
Serhiy Storchaka <storchaka@gmail.com>
parents: 81675
diff changeset
260 # Issue #18167
a48f65bac986 Issue #18167: cgi.FieldStorage no more fails to handle multipart/form-data
Serhiy Storchaka <storchaka@gmail.com>
parents: 81675
diff changeset
261 maxline = 1 << 16
a48f65bac986 Issue #18167: cgi.FieldStorage no more fails to handle multipart/form-data
Serhiy Storchaka <storchaka@gmail.com>
parents: 81675
diff changeset
262 self.maxDiff = None
a48f65bac986 Issue #18167: cgi.FieldStorage no more fails to handle multipart/form-data
Serhiy Storchaka <storchaka@gmail.com>
parents: 81675
diff changeset
263 def check(content):
a48f65bac986 Issue #18167: cgi.FieldStorage no more fails to handle multipart/form-data
Serhiy Storchaka <storchaka@gmail.com>
parents: 81675
diff changeset
264 data = """---123
a48f65bac986 Issue #18167: cgi.FieldStorage no more fails to handle multipart/form-data
Serhiy Storchaka <storchaka@gmail.com>
parents: 81675
diff changeset
265 Content-Disposition: form-data; name="upload"; filename="fake.txt"
a48f65bac986 Issue #18167: cgi.FieldStorage no more fails to handle multipart/form-data
Serhiy Storchaka <storchaka@gmail.com>
parents: 81675
diff changeset
266 Content-Type: text/plain
a48f65bac986 Issue #18167: cgi.FieldStorage no more fails to handle multipart/form-data
Serhiy Storchaka <storchaka@gmail.com>
parents: 81675
diff changeset
267
a48f65bac986 Issue #18167: cgi.FieldStorage no more fails to handle multipart/form-data
Serhiy Storchaka <storchaka@gmail.com>
parents: 81675
diff changeset
268 %s
a48f65bac986 Issue #18167: cgi.FieldStorage no more fails to handle multipart/form-data
Serhiy Storchaka <storchaka@gmail.com>
parents: 81675
diff changeset
269 ---123--
a48f65bac986 Issue #18167: cgi.FieldStorage no more fails to handle multipart/form-data
Serhiy Storchaka <storchaka@gmail.com>
parents: 81675
diff changeset
270 """.replace('\n', '\r\n') % content
a48f65bac986 Issue #18167: cgi.FieldStorage no more fails to handle multipart/form-data
Serhiy Storchaka <storchaka@gmail.com>
parents: 81675
diff changeset
271 environ = {
a48f65bac986 Issue #18167: cgi.FieldStorage no more fails to handle multipart/form-data
Serhiy Storchaka <storchaka@gmail.com>
parents: 81675
diff changeset
272 'CONTENT_LENGTH': str(len(data)),
a48f65bac986 Issue #18167: cgi.FieldStorage no more fails to handle multipart/form-data
Serhiy Storchaka <storchaka@gmail.com>
parents: 81675
diff changeset
273 'CONTENT_TYPE': 'multipart/form-data; boundary=-123',
a48f65bac986 Issue #18167: cgi.FieldStorage no more fails to handle multipart/form-data
Serhiy Storchaka <storchaka@gmail.com>
parents: 81675
diff changeset
274 'REQUEST_METHOD': 'POST',
a48f65bac986 Issue #18167: cgi.FieldStorage no more fails to handle multipart/form-data
Serhiy Storchaka <storchaka@gmail.com>
parents: 81675
diff changeset
275 }
a48f65bac986 Issue #18167: cgi.FieldStorage no more fails to handle multipart/form-data
Serhiy Storchaka <storchaka@gmail.com>
parents: 81675
diff changeset
276 self.assertEqual(gen_result(data, environ),
a48f65bac986 Issue #18167: cgi.FieldStorage no more fails to handle multipart/form-data
Serhiy Storchaka <storchaka@gmail.com>
parents: 81675
diff changeset
277 {'upload': content.encode('latin1')})
a48f65bac986 Issue #18167: cgi.FieldStorage no more fails to handle multipart/form-data
Serhiy Storchaka <storchaka@gmail.com>
parents: 81675
diff changeset
278 check('x' * (maxline - 1))
a48f65bac986 Issue #18167: cgi.FieldStorage no more fails to handle multipart/form-data
Serhiy Storchaka <storchaka@gmail.com>
parents: 81675
diff changeset
279 check('x' * (maxline - 1) + '\r')
a48f65bac986 Issue #18167: cgi.FieldStorage no more fails to handle multipart/form-data
Serhiy Storchaka <storchaka@gmail.com>
parents: 81675
diff changeset
280 check('x' * (maxline - 1) + '\r' + 'y' * (maxline - 1))
a48f65bac986 Issue #18167: cgi.FieldStorage no more fails to handle multipart/form-data
Serhiy Storchaka <storchaka@gmail.com>
parents: 81675
diff changeset
281
84482
406ce103c170 Issue #18013: Fix cgi.FieldStorage to parse the W3C sample form.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 84182
diff changeset
282 def test_fieldstorage_multipart_w3c(self):
406ce103c170 Issue #18013: Fix cgi.FieldStorage to parse the W3C sample form.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 84182
diff changeset
283 # Test basic FieldStorage multipart parsing (W3C sample)
406ce103c170 Issue #18013: Fix cgi.FieldStorage to parse the W3C sample form.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 84182
diff changeset
284 env = {
406ce103c170 Issue #18013: Fix cgi.FieldStorage to parse the W3C sample form.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 84182
diff changeset
285 'REQUEST_METHOD': 'POST',
406ce103c170 Issue #18013: Fix cgi.FieldStorage to parse the W3C sample form.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 84182
diff changeset
286 'CONTENT_TYPE': 'multipart/form-data; boundary={}'.format(BOUNDARY_W3),
406ce103c170 Issue #18013: Fix cgi.FieldStorage to parse the W3C sample form.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 84182
diff changeset
287 'CONTENT_LENGTH': str(len(POSTDATA_W3))}
406ce103c170 Issue #18013: Fix cgi.FieldStorage to parse the W3C sample form.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 84182
diff changeset
288 fp = BytesIO(POSTDATA_W3.encode('latin-1'))
406ce103c170 Issue #18013: Fix cgi.FieldStorage to parse the W3C sample form.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 84182
diff changeset
289 fs = cgi.FieldStorage(fp, environ=env, encoding="latin-1")
406ce103c170 Issue #18013: Fix cgi.FieldStorage to parse the W3C sample form.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 84182
diff changeset
290 self.assertEqual(len(fs.list), 2)
406ce103c170 Issue #18013: Fix cgi.FieldStorage to parse the W3C sample form.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 84182
diff changeset
291 self.assertEqual(fs.list[0].name, 'submit-name')
406ce103c170 Issue #18013: Fix cgi.FieldStorage to parse the W3C sample form.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 84182
diff changeset
292 self.assertEqual(fs.list[0].value, 'Larry')
406ce103c170 Issue #18013: Fix cgi.FieldStorage to parse the W3C sample form.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 84182
diff changeset
293 self.assertEqual(fs.list[1].name, 'files')
406ce103c170 Issue #18013: Fix cgi.FieldStorage to parse the W3C sample form.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 84182
diff changeset
294 files = fs.list[1].value
406ce103c170 Issue #18013: Fix cgi.FieldStorage to parse the W3C sample form.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 84182
diff changeset
295 self.assertEqual(len(files), 2)
406ce103c170 Issue #18013: Fix cgi.FieldStorage to parse the W3C sample form.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 84182
diff changeset
296 expect = [{'name': None, 'filename': 'file1.txt', 'value': b'... contents of file1.txt ...'},
406ce103c170 Issue #18013: Fix cgi.FieldStorage to parse the W3C sample form.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 84182
diff changeset
297 {'name': None, 'filename': 'file2.gif', 'value': b'...contents of file2.gif...'}]
406ce103c170 Issue #18013: Fix cgi.FieldStorage to parse the W3C sample form.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 84182
diff changeset
298 for x in range(len(files)):
406ce103c170 Issue #18013: Fix cgi.FieldStorage to parse the W3C sample form.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 84182
diff changeset
299 for k, exp in expect[x].items():
406ce103c170 Issue #18013: Fix cgi.FieldStorage to parse the W3C sample form.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 84182
diff changeset
300 got = getattr(files[x], k)
406ce103c170 Issue #18013: Fix cgi.FieldStorage to parse the W3C sample form.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 84182
diff changeset
301 self.assertEqual(got, exp)
406ce103c170 Issue #18013: Fix cgi.FieldStorage to parse the W3C sample form.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 84182
diff changeset
302
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
303 _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
304 '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
305 '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
306 '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
307 '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
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 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
310 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
311 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
312 '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
313 '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
314 '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
315 '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
316 }
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
317 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
318 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
319
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
320 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
321 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
322 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
323
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
324 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
325 ---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
326 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
327
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
328 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
329 ---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
330 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
331
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
332 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
333 ---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
334 """
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
335 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
336 '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
337 '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
338 '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
339 '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
340 }
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
341 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
342 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
343
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
344 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
345 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
346 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
347
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
348 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
349 ---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
350 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
351
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
352 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
353 ---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
354 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
355
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
356 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
357 ---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
358 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
359 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
360
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
361 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
362
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
363 ---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
364 """
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
365 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
366 '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
367 '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
368 '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
369 '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
370 }
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
371 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
372 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
373 '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
374 })
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
375 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
376 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
377
49081
f085f39a6f4d Added sanity checks for the deprecated parse_qs() and
Facundo Batista <facundobatista@gmail.com>
parents: 48998
diff changeset
378 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
379 # 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
380 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
381 '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
382 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
383 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
384
f085f39a6f4d Added sanity checks for the deprecated parse_qs() and
Facundo Batista <facundobatista@gmail.com>
parents: 48998
diff changeset
385 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
386 # 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
387 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
388 '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
389 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
390 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
391
49976
89e738c792c0 Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents: 49101
diff changeset
392 def test_parse_header(self):
89e738c792c0 Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents: 49101
diff changeset
393 self.assertEqual(
89e738c792c0 Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents: 49101
diff changeset
394 cgi.parse_header("text/plain"),
89e738c792c0 Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents: 49101
diff changeset
395 ("text/plain", {}))
89e738c792c0 Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents: 49101
diff changeset
396 self.assertEqual(
89e738c792c0 Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents: 49101
diff changeset
397 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
398 ("text/vnd.just.made.this.up", {}))
89e738c792c0 Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents: 49101
diff changeset
399 self.assertEqual(
89e738c792c0 Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents: 49101
diff changeset
400 cgi.parse_header("text/plain;charset=us-ascii"),
89e738c792c0 Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents: 49101
diff changeset
401 ("text/plain", {"charset": "us-ascii"}))
89e738c792c0 Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents: 49101
diff changeset
402 self.assertEqual(
89e738c792c0 Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents: 49101
diff changeset
403 cgi.parse_header('text/plain ; charset="us-ascii"'),
89e738c792c0 Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents: 49101
diff changeset
404 ("text/plain", {"charset": "us-ascii"}))
89e738c792c0 Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents: 49101
diff changeset
405 self.assertEqual(
89e738c792c0 Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents: 49101
diff changeset
406 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
407 ("text/plain", {"charset": "us-ascii", "another": "opt"}))
89e738c792c0 Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents: 49101
diff changeset
408 self.assertEqual(
89e738c792c0 Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents: 49101
diff changeset
409 cgi.parse_header('attachment; filename="silly.txt"'),
89e738c792c0 Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents: 49101
diff changeset
410 ("attachment", {"filename": "silly.txt"}))
89e738c792c0 Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents: 49101
diff changeset
411 self.assertEqual(
89e738c792c0 Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents: 49101
diff changeset
412 cgi.parse_header('attachment; filename="strange;name"'),
89e738c792c0 Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents: 49101
diff changeset
413 ("attachment", {"filename": "strange;name"}))
89e738c792c0 Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents: 49101
diff changeset
414 self.assertEqual(
89e738c792c0 Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents: 49101
diff changeset
415 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
416 ("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
417 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
418 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
419 ("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
420
49976
89e738c792c0 Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents: 49101
diff changeset
421
68200
1d198518cb87 Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68095
diff changeset
422 BOUNDARY = "---------------------------721837373350705526688164684"
1d198518cb87 Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68095
diff changeset
423
1d198518cb87 Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68095
diff changeset
424 POSTDATA = """-----------------------------721837373350705526688164684
1d198518cb87 Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68095
diff changeset
425 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
426
1d198518cb87 Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68095
diff changeset
427 1234
1d198518cb87 Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68095
diff changeset
428 -----------------------------721837373350705526688164684
1d198518cb87 Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68095
diff changeset
429 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
430
1d198518cb87 Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68095
diff changeset
431
1d198518cb87 Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68095
diff changeset
432 -----------------------------721837373350705526688164684
1d198518cb87 Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68095
diff changeset
433 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
434 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
435
1d198518cb87 Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68095
diff changeset
436 Testing 123.
1d198518cb87 Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68095
diff changeset
437
1d198518cb87 Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68095
diff changeset
438 -----------------------------721837373350705526688164684
1d198518cb87 Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68095
diff changeset
439 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
440
1d198518cb87 Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68095
diff changeset
441 Add\x20
1d198518cb87 Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68095
diff changeset
442 -----------------------------721837373350705526688164684--
1d198518cb87 Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68095
diff changeset
443 """
1d198518cb87 Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68095
diff changeset
444
1d198518cb87 Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68095
diff changeset
445 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
446 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
447
1d198518cb87 Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68095
diff changeset
448 \xe7\xf1\x80
1d198518cb87 Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68095
diff changeset
449 -----------------------------721837373350705526688164684
1d198518cb87 Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68095
diff changeset
450 """
1d198518cb87 Issue #10911: Add tests on CGI with non-ASCII characters
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68095
diff changeset
451
84482
406ce103c170 Issue #18013: Fix cgi.FieldStorage to parse the W3C sample form.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 84182
diff changeset
452 # http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4
406ce103c170 Issue #18013: Fix cgi.FieldStorage to parse the W3C sample form.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 84182
diff changeset
453 BOUNDARY_W3 = "AaB03x"
406ce103c170 Issue #18013: Fix cgi.FieldStorage to parse the W3C sample form.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 84182
diff changeset
454 POSTDATA_W3 = """--AaB03x
406ce103c170 Issue #18013: Fix cgi.FieldStorage to parse the W3C sample form.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 84182
diff changeset
455 Content-Disposition: form-data; name="submit-name"
406ce103c170 Issue #18013: Fix cgi.FieldStorage to parse the W3C sample form.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 84182
diff changeset
456
406ce103c170 Issue #18013: Fix cgi.FieldStorage to parse the W3C sample form.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 84182
diff changeset
457 Larry
406ce103c170 Issue #18013: Fix cgi.FieldStorage to parse the W3C sample form.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 84182
diff changeset
458 --AaB03x
406ce103c170 Issue #18013: Fix cgi.FieldStorage to parse the W3C sample form.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 84182
diff changeset
459 Content-Disposition: form-data; name="files"
406ce103c170 Issue #18013: Fix cgi.FieldStorage to parse the W3C sample form.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 84182
diff changeset
460 Content-Type: multipart/mixed; boundary=BbC04y
406ce103c170 Issue #18013: Fix cgi.FieldStorage to parse the W3C sample form.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 84182
diff changeset
461
406ce103c170 Issue #18013: Fix cgi.FieldStorage to parse the W3C sample form.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 84182
diff changeset
462 --BbC04y
406ce103c170 Issue #18013: Fix cgi.FieldStorage to parse the W3C sample form.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 84182
diff changeset
463 Content-Disposition: file; filename="file1.txt"
406ce103c170 Issue #18013: Fix cgi.FieldStorage to parse the W3C sample form.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 84182
diff changeset
464 Content-Type: text/plain
406ce103c170 Issue #18013: Fix cgi.FieldStorage to parse the W3C sample form.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 84182
diff changeset
465
406ce103c170 Issue #18013: Fix cgi.FieldStorage to parse the W3C sample form.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 84182
diff changeset
466 ... contents of file1.txt ...
406ce103c170 Issue #18013: Fix cgi.FieldStorage to parse the W3C sample form.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 84182
diff changeset
467 --BbC04y
406ce103c170 Issue #18013: Fix cgi.FieldStorage to parse the W3C sample form.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 84182
diff changeset
468 Content-Disposition: file; filename="file2.gif"
406ce103c170 Issue #18013: Fix cgi.FieldStorage to parse the W3C sample form.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 84182
diff changeset
469 Content-Type: image/gif
406ce103c170 Issue #18013: Fix cgi.FieldStorage to parse the W3C sample form.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 84182
diff changeset
470 Content-Transfer-Encoding: binary
406ce103c170 Issue #18013: Fix cgi.FieldStorage to parse the W3C sample form.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 84182
diff changeset
471
406ce103c170 Issue #18013: Fix cgi.FieldStorage to parse the W3C sample form.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 84182
diff changeset
472 ...contents of file2.gif...
406ce103c170 Issue #18013: Fix cgi.FieldStorage to parse the W3C sample form.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 84182
diff changeset
473 --BbC04y--
406ce103c170 Issue #18013: Fix cgi.FieldStorage to parse the W3C sample form.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 84182
diff changeset
474 --AaB03x--
406ce103c170 Issue #18013: Fix cgi.FieldStorage to parse the W3C sample form.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 84182
diff changeset
475 """
406ce103c170 Issue #18013: Fix cgi.FieldStorage to parse the W3C sample form.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 84182
diff changeset
476
49976
89e738c792c0 Merged revisions 67534 via svnmerge from
Fred Drake <fdrake@acm.org>
parents: 49101
diff changeset
477
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39644
diff changeset
478 def test_main():
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39644
diff changeset
479 run_unittest(CgiTests)
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39644
diff changeset
480
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39644
diff changeset
481 if __name__ == '__main__':
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39644
diff changeset
482 test_main()