def CgiDictFromParsedUrl(url):
"""Extract CGI variables from a parsed url into a dict.
Returns a dict containing the following CGI variables for the provided url:
SERVER_PORT, QUERY_STRING, SERVER_NAME and PATH_INFO.
Args:
url: An instance of urlparse.SplitResult.
Returns:
A dict containing the CGI variables derived from url.
"""
environ = {}
if url.port is not None:
environ['SERVER_PORT'] = str(url.port)
elif url.scheme == 'https':
environ['SERVER_PORT'] = '443'
elif url.scheme == 'http':
environ['SERVER_PORT'] = '80'
environ['QUERY_STRING'] = url.query
environ['SERVER_NAME'] = url.hostname
if url.path:
environ['PATH_INFO'] = urlparse.unquote(url.path)
else:
environ['PATH_INFO'] = '/'
return environ
评论列表
文章目录