def __call__(self, environ, start_response): """Pre-initialize WSGI env and call WSGI-callable.""" # If you're calling this, then you're probably setting SCRIPT_NAME # to '' (some WSGI servers always set SCRIPT_NAME to ''). # Try to look up the app using the full path. env1x = environ if six.PY2 and environ.get(ntou('wsgi.version')) == (ntou('u'), 0): env1x = _cpwsgi.downgrade_wsgi_ux_to_1x(environ) path = httputil.urljoin(env1x.get('SCRIPT_NAME', ''), env1x.get('PATH_INFO', '')) sn = self.script_name(path or '/') if sn is None: start_response('404 Not Found', []) return [] app = self.apps[sn] # Correct the SCRIPT_NAME and PATH_INFO environ entries. environ = environ.copy() if six.PY2 and environ.get(ntou('wsgi.version')) == (ntou('u'), 0): # Python 2/WSGI u.0: all strings MUST be of type unicode enc = environ[ntou('wsgi.url_encoding')] environ[ntou('SCRIPT_NAME')] = sn.decode(enc) environ[ntou('PATH_INFO')] = path[len(sn.rstrip('/')):].decode(enc) else: environ['SCRIPT_NAME'] = sn environ['PATH_INFO'] = path[len(sn.rstrip('/')):] return app(environ, start_response)
def __call__(self, environ, start_response): # If you're calling this, then you're probably setting SCRIPT_NAME # to '' (some WSGI servers always set SCRIPT_NAME to ''). # Try to look up the app using the full path. env1x = environ if environ.get(ntou('wsgi.version')) == (ntou('u'), 0): env1x = _cpwsgi.downgrade_wsgi_ux_to_1x(environ) path = httputil.urljoin(env1x.get('SCRIPT_NAME', ''), env1x.get('PATH_INFO', '')) sn = self.script_name(path or "/") if sn is None: start_response('404 Not Found', []) return [] app = self.apps[sn] # Correct the SCRIPT_NAME and PATH_INFO environ entries. environ = environ.copy() if not py3k: if environ.get(ntou('wsgi.version')) == (ntou('u'), 0): # Python 2/WSGI u.0: all strings MUST be of type unicode enc = environ[ntou('wsgi.url_encoding')] environ[ntou('SCRIPT_NAME')] = sn.decode(enc) environ[ntou('PATH_INFO')] = path[len(sn.rstrip("/")):].decode(enc) else: # Python 2/WSGI 1.x: all strings MUST be of type str environ['SCRIPT_NAME'] = sn environ['PATH_INFO'] = path[len(sn.rstrip("/")):] else: if environ.get(ntou('wsgi.version')) == (ntou('u'), 0): # Python 3/WSGI u.0: all strings MUST be full unicode environ['SCRIPT_NAME'] = sn environ['PATH_INFO'] = path[len(sn.rstrip("/")):] # for the wsgi 1.0 the environment is already encoded by the Gateway. return app(environ, start_response)
def __call__(self, environ, start_response): # If you're calling this, then you're probably setting SCRIPT_NAME # to '' (some WSGI servers always set SCRIPT_NAME to ''). # Try to look up the app using the full path. env1x = environ if environ.get(ntou('wsgi.version')) == (ntou('u'), 0): env1x = _cpwsgi.downgrade_wsgi_ux_to_1x(environ) path = httputil.urljoin(env1x.get('SCRIPT_NAME', ''), env1x.get('PATH_INFO', '')) sn = self.script_name(path or "/") if sn is None: start_response('404 Not Found', []) return [] app = self.apps[sn] # Correct the SCRIPT_NAME and PATH_INFO environ entries. environ = environ.copy() if environ.get('wsgi.version') == ('u', 0): # Python 3/WSGI u.0: all strings MUST be full unicode environ['SCRIPT_NAME'] = sn environ['PATH_INFO'] = path[len(sn.rstrip("/")):] else: # Python 3/WSGI 1.x: all strings MUST be ISO-8859-1 str environ['SCRIPT_NAME'] = sn.encode('utf-8').decode('ISO-8859-1') environ['PATH_INFO'] = path[len(sn.rstrip("/")):].encode( 'utf-8').decode('ISO-8859-1') return app(environ, start_response)
def __call__(self, environ, start_response): # If you're calling this, then you're probably setting SCRIPT_NAME # to '' (some WSGI servers always set SCRIPT_NAME to ''). # Try to look up the app using the full path. env1x = environ if environ.get(ntou('wsgi.version')) == (ntou('u'), 0): env1x = _cpwsgi.downgrade_wsgi_ux_to_1x(environ) path = httputil.urljoin(env1x.get('SCRIPT_NAME', ''), env1x.get('PATH_INFO', '')) sn = self.script_name(path or "/") if sn is None: start_response('404 Not Found', []) return [] app = self.apps[sn] # Correct the SCRIPT_NAME and PATH_INFO environ entries. environ = environ.copy() if environ.get('wsgi.version') == ('u', 0): # Python 3/WSGI u.0: all strings MUST be full unicode environ['SCRIPT_NAME'] = sn environ['PATH_INFO'] = path[len(sn.rstrip("/")):] else: # Python 3/WSGI 1.x: all strings MUST be ISO-8859-1 str environ['SCRIPT_NAME'] = sn.encode('utf-8').decode('ISO-8859-1') environ['PATH_INFO'] = path[len(sn.rstrip("/")):].encode('utf-8').decode('ISO-8859-1') return app(environ, start_response)
def __call__(self, environ, start_response): env1x = environ if environ.get(ntou('wsgi.version')) == (ntou('u'), 0): env1x = _cpwsgi.downgrade_wsgi_ux_to_1x(environ) path = httputil.urljoin(env1x.get('SCRIPT_NAME', ''), env1x.get('PATH_INFO', '')) sn = self.script_name(path or '/') if sn is None: start_response('404 Not Found', []) return [] app = self.apps[sn] environ = environ.copy() if environ.get(u'wsgi.version') == (u'u', 0): enc = environ[u'wsgi.url_encoding'] environ[u'SCRIPT_NAME'] = sn.decode(enc) environ[u'PATH_INFO'] = path[len(sn.rstrip('/')):].decode(enc) else: environ['SCRIPT_NAME'] = sn environ['PATH_INFO'] = path[len(sn.rstrip('/')):] return app(environ, start_response)
def __call__(self, environ, start_response): # If you're calling this, then you're probably setting SCRIPT_NAME # to '' (some WSGI servers always set SCRIPT_NAME to ''). # Try to look up the app using the full path. env1x = environ if environ.get(ntou('wsgi.version')) == (ntou('u'), 0): env1x = _cpwsgi.downgrade_wsgi_ux_to_1x(environ) path = httputil.urljoin(env1x.get('SCRIPT_NAME', ''), env1x.get('PATH_INFO', '')) sn = self.script_name(path or "/") if sn is None: start_response('404 Not Found', []) return [] app = self.apps[sn] # Correct the SCRIPT_NAME and PATH_INFO environ entries. environ = environ.copy() if not py3k: if environ.get(ntou('wsgi.version')) == (ntou('u'), 0): # Python 2/WSGI u.0: all strings MUST be of type unicode enc = environ[ntou('wsgi.url_encoding')] environ[ntou('SCRIPT_NAME')] = sn.decode(enc) environ[ntou('PATH_INFO')] = path[len(sn.rstrip("/")):].decode( enc) else: # Python 2/WSGI 1.x: all strings MUST be of type str environ['SCRIPT_NAME'] = sn environ['PATH_INFO'] = path[len(sn.rstrip("/")):] else: if environ.get(ntou('wsgi.version')) == (ntou('u'), 0): # Python 3/WSGI u.0: all strings MUST be full unicode environ['SCRIPT_NAME'] = sn environ['PATH_INFO'] = path[len(sn.rstrip("/")):] # for the wsgi 1.0 the environment is already encoded by the Gateway. return app(environ, start_response)