def get_environ(self): """Return a new environ dict targeting the given wsgi.version""" req = self.req env_10 = WSGIGateway_10.get_environ(self) if py3k: env = env_10.copy() else: env = dict([(k.decode('ISO-8859-1'), v) for k, v in env_10.iteritems()]) env[ntou('wsgi.version')] = ('u', 0) # Request-URI env.setdefault(ntou('wsgi.url_encoding'), ntou('utf-8')) try: if py3k: for key in ["PATH_INFO", "SCRIPT_NAME", "QUERY_STRING"]: # Re-encode since our "decoded" string is just # bytes masquerading as unicode via Latin-1 val = env_10[key].encode('ISO-8859-1') # ...now decode according to the configured encoding env[key] = val.decode(env['wsgi.url_encoding']) else: # SCRIPT_NAME is the empty string, who cares what encoding it is? env["PATH_INFO"] = req.path.decode(env['wsgi.url_encoding']) env["QUERY_STRING"] = req.qs.decode(env['wsgi.url_encoding']) except UnicodeDecodeError: # Fall back to latin 1 so apps can transcode if needed. env[ntou('wsgi.url_encoding')] = ntou('ISO-8859-1') for key in [ ntou("PATH_INFO"), ntou("SCRIPT_NAME"), ntou("QUERY_STRING") ]: if py3k: env[key] = env_10[key] else: env[key] = env_10[str(key)].decode( env['wsgi.url_encoding']) if not py3k: for k, v in env.items(): if isinstance(v, str) and k not in ('REQUEST_URI', 'wsgi.input'): env[k] = ntou(v) return env
def get_environ(self): """Return a new environ dict targeting the given wsgi.version""" req = self.req env_10 = WSGIGateway_10.get_environ(self) if py3k: env = env_10.copy() else: env = dict([(k.decode('ISO-8859-1'), v) for k, v in env_10.iteritems()]) env[ntou('wsgi.version')] = ('u', 0) # Request-URI env.setdefault(ntou('wsgi.url_encoding'), ntou('utf-8')) try: if py3k: for key in ["PATH_INFO", "SCRIPT_NAME", "QUERY_STRING"]: # Re-encode since our "decoded" string is just # bytes masquerading as unicode via Latin-1 val = env_10[key].encode('ISO-8859-1') # ...now decode according to the configured encoding env[key] = val.decode(env['wsgi.url_encoding']) else: # SCRIPT_NAME is the empty string, who cares what encoding it is? env["PATH_INFO"] = req.path.decode(env['wsgi.url_encoding']) env["QUERY_STRING"] = req.qs.decode(env['wsgi.url_encoding']) except UnicodeDecodeError: # Fall back to latin 1 so apps can transcode if needed. env[ntou('wsgi.url_encoding')] = ntou('ISO-8859-1') for key in [ntou("PATH_INFO"), ntou("SCRIPT_NAME"), ntou("QUERY_STRING")]: if py3k: env[key] = env_10[key] else: env[key] = env_10[str(key)].decode(env['wsgi.url_encoding']) if not py3k: for k, v in env.items(): if isinstance(v, str) and k not in ('REQUEST_URI', 'wsgi.input'): env[k] = ntou(v) return env
def test_ntou_escape(): """Check that ntou supports escape-encoding under Python 2.""" expected = u'' actual = ntou('hi'.encode('ISO-8859-1'), encoding='escape') assert actual == expected
def test_ntou_escape(): """Check that ntou supports escape-encoding under Python 2.""" expected = u'hišřії' actual = ntou('hi\u0161\u0159\u0456\u0457', encoding='escape') assert actual == expected
def test_ntou_escape(): """Check that ntou supports escape-encoding under Python 2.""" expected = u'hišřії' actual = ntou('hi\u0161\u0159\u0456\u0457', encoding='escape') assert actual == expected