MCPcopy
hub / github.com/cherrypy/cherrypy / recode_path_qs

Method recode_path_qs

cherrypy/_cpwsgi.py:348–371  ·  view source on GitHub ↗
(self, path, qs)

Source from the content-addressed store, hash-verified

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."""

Callers 1

runMethod · 0.95

Calls 3

find_configMethod · 0.80
encodeMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected