| 11 | | enc = cherrypy.config.get('decoding_filter.encoding', 'utf-8') |
|---|
| | 13 | enc = conf('decoding_filter.encoding', None) |
|---|
| | 14 | if not enc: |
|---|
| | 15 | ct = cherrypy.request.headers.elements("Content-Type") |
|---|
| | 16 | if ct is not None: |
|---|
| | 17 | ct = ct[0] |
|---|
| | 18 | enc = ct.params.get("charset", None) |
|---|
| | 19 | if (not enc) and ct.value.lower().startswith("text/"): |
|---|
| | 20 | # http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.7.1 |
|---|
| | 21 | # When no explicit charset parameter is provided by the |
|---|
| | 22 | # sender, media subtypes of the "text" type are defined |
|---|
| | 23 | # to have a default charset value of "ISO-8859-1" when |
|---|
| | 24 | # received via HTTP. |
|---|
| | 25 | enc = "ISO-8859-1" |
|---|
| | 26 | |
|---|
| | 27 | if not enc: |
|---|
| | 28 | enc = conf('decoding_filter.default_encoding', "utf-8") |
|---|
| | 29 | |
|---|
| | 30 | try: |
|---|
| | 31 | self.decode(enc) |
|---|
| | 32 | except UnicodeDecodeError: |
|---|
| | 33 | # IE and Firefox don't supply a charset when submitting form |
|---|
| | 34 | # params with a CT of application/x-www-form-urlencoded. |
|---|
| | 35 | # So after all our guessing, it could *still* be wrong. |
|---|
| | 36 | # Start over with ISO-8859-1, since that seems to be preferred. |
|---|
| | 37 | self.decode("ISO-8859-1") |
|---|
| | 38 | |
|---|
| | 39 | def decode(self, enc): |
|---|
| | 40 | decodedParams = {} |
|---|