[issue22264] Add wsgiref.util.fix_decoding

Nick Coghlan report at bugs.python.org
Sun Aug 24 17:23:04 CEST 2014


Nick Coghlan added the comment:

Current cryptic incantation that requires deep knowledge of the encoding system to follow:

    data = data.encode("latin-1").decode("utf-8", "surrogateescape")

Replacement that is not only more self-documenting, but also gives you something specific to look up in order to learn more:

    data = wsgiref.util.fix_encoding(data, "utf-8")

As a WSGI server, the standard library code mostly does this in the other direction, converting data from its original web server provided encoding *to* latin-1.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue22264>
_______________________________________


More information about the Python-bugs-list mailing list