#NEWLINE# def get_host( environ ) : #NEWLINE# #INDENT# 'Return the real host for the given WSGI environment.  This takes care\n    of the `X-Forwarded-Host` header.\n\n    :param environ: the WSGI environment to get the host of.\n    ' #NEWLINE# scheme = environ . get ( 'wsgi.url_scheme' ) #NEWLINE# if ( 'HTTP_X_FORWARDED_HOST' in environ ) : #NEWLINE# #INDENT# result = environ [ 'HTTP_X_FORWARDED_HOST' ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( 'HTTP_HOST' in environ ) : #NEWLINE# #INDENT# result = environ [ 'HTTP_HOST' ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# result = environ [ 'SERVER_NAME' ] #NEWLINE# if ( ( scheme , str ( environ [ 'SERVER_PORT' ] ) ) not in ( ( 'https' , '443' ) , ( 'http' , '80' ) ) ) : #NEWLINE# #INDENT# result += ( ':' + environ [ 'SERVER_PORT' ] ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( result . endswith ( ':80' ) and ( scheme == 'http' ) ) : #NEWLINE# #INDENT# result = result [ : ( - 3 ) ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( result . endswith ( ':443' ) and ( scheme == 'https' ) ) : #NEWLINE# #INDENT# result = result [ : ( - 4 ) ] #NEWLINE# #UNINDENT# #UNINDENT# return result