def geturl(environ, query=True, path=True, use_server_name=False):
 url = [(environ['wsgi.url_scheme'] + '://')]
 if use_server_name:
  url.append(environ['SERVER_NAME'])
  if (environ['wsgi.url_scheme'] == 'https'):
   if (environ['SERVER_PORT'] != '443'):
    url.append((':' + environ['SERVER_PORT']))
  elif (environ['SERVER_PORT'] != '80'):
   url.append((':' + environ['SERVER_PORT']))
 else:
  url.append(environ['HTTP_HOST'])
 if path:
  url.append(getpath(environ))
 if (query and environ.get('QUERY_STRING')):
  url.append(('?' + environ['QUERY_STRING']))
 return ''.join(url)

def geturl ( environ , query = True , path = True , use_server_name = False ) : url = [ ( environ [ 'wsgi.url_scheme' ] + '://' ) ] if use_server_name : url . append ( environ [ 'SERVER_NAME' ] ) if ( environ [ 'wsgi.url_scheme' ] == 'https' ) : if ( environ [ 'SERVER_PORT' ] != '443' ) : url . append ( ( ':' + environ [ 'SERVER_PORT' ] ) ) elif ( environ [ 'SERVER_PORT' ] != '80' ) : url . append ( ( ':' + environ [ 'SERVER_PORT' ] ) ) else : url . append ( environ [ 'HTTP_HOST' ] ) if path : url . append ( getpath ( environ ) ) if ( query and environ . get ( 'QUERY_STRING' ) ) : url . append ( ( '?' + environ [ 'QUERY_STRING' ] ) ) return '' . join ( url )
rebuilds a request url .