def _reconstruct_url(environ, protocol=True, server_name=True, path=True, query_string=True): """Rebuilds the calling url from values found in the environment. This algorithm was found via PEP 333, the wsgi spec and contributed by Ian Bicking. """ url = '' if protocol: url = environ['wsgi.url_scheme'] + '://' if server_name: if environ.get('HTTP_HOST'): url += environ['HTTP_HOST'] else: url += environ['SERVER_NAME'] if environ['wsgi.url_scheme'] == 'https': if environ['SERVER_PORT'] != '443': url += ':' + environ['SERVER_PORT'] else: if environ['SERVER_PORT'] != '80': url += ':' + environ['SERVER_PORT'] if path: if (quote(environ.get('SCRIPT_NAME', '')) == '/' and quote(environ.get('PATH_INFO', ''))[0] == '/'): #skip this if it is only a slash pass elif quote(environ.get('SCRIPT_NAME', ''))[0:2] == '//': url += quote(environ.get('SCRIPT_NAME', ''))[1:] else: url += quote(environ.get('SCRIPT_NAME', '')) url += quote(environ.get('PATH_INFO', '')) if query_string: if environ.get('QUERY_STRING'): url += '?' + environ['QUERY_STRING'] return url
def get_path_and_qs(self): retval = quote(self.req_env.get('PATH_INFO', '')) qs = self.req_env.get('QUERY_STRING', None) if qs is not None: retval += '?' + qs return retval