diff options
author | Robert Brewer <fumanchu@aminus.org> | 2009-08-10 01:30:03 +0000 |
---|---|---|
committer | Robert Brewer <fumanchu@aminus.org> | 2009-08-10 01:30:03 +0000 |
commit | 31243d3cf4ab925ce5fced25d77a83c881242108 (patch) | |
tree | 085b6fbc28791c6654ed6749a8b3ef2b349afa16 /cherrypy/lib/encoding.py | |
parent | cc79bd3a4c3ddd8933d035cbbe1933e4bc12822b (diff) | |
download | cherrypy-git-31243d3cf4ab925ce5fced25d77a83c881242108.tar.gz |
Fix for #946 (Problem with encoded text in multipart/form-data). Reworked the structure for attempting various charsets when decoding request entities. New 'decode' Tool which is backward-compatible with the one in 3.1.
Diffstat (limited to 'cherrypy/lib/encoding.py')
-rw-r--r-- | cherrypy/lib/encoding.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/cherrypy/lib/encoding.py b/cherrypy/lib/encoding.py index 3bee739b..25a1bda6 100644 --- a/cherrypy/lib/encoding.py +++ b/cherrypy/lib/encoding.py @@ -15,6 +15,30 @@ from cherrypy.lib import file_generator from cherrypy.lib import set_vary_header +def decode(encoding=None, default_encoding='utf-8'): + """Replace or extend the list of charsets used to decode a request entity. + + Either argument may be a single string or a list of strings. + + encoding: If not None, restricts the set of charsets attempted while decoding + a request entity to the given set (even if a different charset is given in + the Content-Type request header). + + default_encoding: Only in effect if the 'encoding' argument is not given. + If given, the set of charsets attempted while decoding a request entity is + *extended* with the given value(s). + """ + body = cherrypy.request.body + if encoding is not None: + if not isinstance(encoding, list): + encoding = [encoding] + body.attempt_charsets = encoding + elif default_encoding: + if not isinstance(default_encoding, list): + default_encoding = [default_encoding] + body.attempt_charsets = body.attempt_charsets + default_encoding + + class ResponseEncoder: default_encoding = 'utf-8' |