(self, path, qs)
| 346 | } |
| 347 | |
| 348 | def recode_path_qs(self, path, qs): |
| 349 | # This isn't perfect; if the given PATH_INFO is in the |
| 350 | # wrong encoding, it may fail to match the appropriate config |
| 351 | # section URI. But meh. |
| 352 | old_enc = self.environ.get('wsgi.url_encoding', 'ISO-8859-1') |
| 353 | new_enc = self.cpapp.find_config( |
| 354 | self.environ.get('PATH_INFO', ''), |
| 355 | 'request.uri_encoding', 'utf-8', |
| 356 | ) |
| 357 | if new_enc.lower() == old_enc.lower(): |
| 358 | return |
| 359 | |
| 360 | # Even though the path and qs are unicode, the WSGI server |
| 361 | # is required by PEP 3333 to coerce them to ISO-8859-1 |
| 362 | # masquerading as unicode. So we have to encode back to |
| 363 | # bytes and then decode again using the "correct" encoding. |
| 364 | try: |
| 365 | return ( |
| 366 | path.encode(old_enc).decode(new_enc), |
| 367 | qs.encode(old_enc).decode(new_enc), |
| 368 | ) |
| 369 | except (UnicodeEncodeError, UnicodeDecodeError): |
| 370 | # Just pass them through without transcoding and hope. |
| 371 | pass |
| 372 | |
| 373 | def translate_headers(self, environ): |
| 374 | """Translate CGI-environ header names to HTTP header names.""" |
no test coverage detected