MCPcopy Index your code
hub / github.com/cherrypy/cherrypy / test_decode_tool

Method test_decode_tool

cherrypy/test/test_encoding.py:200–236  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

198 "were attempted: ['utf-8']")
199
200 def test_decode_tool(self):
201 # An extra charset should be tried first, and succeed if it matches.
202 # Here, we add utf-16 as a charset and pass a utf-16 body.
203 body = b'\xff\xfeq\x00=\xff\xfe\xa3\x00'
204 self.getPage('/decode/extra_charset', method='POST',
205 headers=[(
206 'Content-Type', 'application/x-www-form-urlencoded'),
207 ('Content-Length', str(len(body))),
208 ],
209 body=body),
210 self.assertBody(b'q: \xc2\xa3')
211
212 # An extra charset should be tried first, and continue to other default
213 # charsets if it doesn't match.
214 # Here, we add utf-16 as a charset but still pass a utf-8 body.
215 body = b'q=\xc2\xa3'
216 self.getPage('/decode/extra_charset', method='POST',
217 headers=[(
218 'Content-Type', 'application/x-www-form-urlencoded'),
219 ('Content-Length', str(len(body))),
220 ],
221 body=body),
222 self.assertBody(b'q: \xc2\xa3')
223
224 # An extra charset should error if force is True and it doesn't match.
225 # Here, we force utf-16 as a charset but still pass a utf-8 body.
226 body = b'q=\xc2\xa3'
227 self.getPage('/decode/force_charset', method='POST',
228 headers=[(
229 'Content-Type', 'application/x-www-form-urlencoded'),
230 ('Content-Length', str(len(body))),
231 ],
232 body=body),
233 self.assertErrorPage(
234 400,
235 'The request entity could not be decoded. The following charsets '
236 "were attempted: ['utf-16']")
237
238 def test_multipart_decoding(self):
239 # Test the decoding of a multipart entity when the charset (utf16) is

Callers

nothing calls this directly

Calls 2

getPageMethod · 0.80
assertErrorPageMethod · 0.80

Tested by

no test coverage detected