#NEWLINE# def default_services_region( service_catalog , request = None ) : #NEWLINE# #INDENT# 'Returns the first endpoint region for first non-identity service.\n\n    Extracted from the service catalog.\n    ' #NEWLINE# if service_catalog : #NEWLINE# #INDENT# available_regions = [ get_endpoint_region ( endpoint ) for service in service_catalog for endpoint in service . get ( 'endpoints' , [ ] ) if ( ( service . get ( 'type' ) is not None ) and ( service . get ( 'type' ) != 'identity' ) ) ] #NEWLINE# if ( not available_regions ) : #NEWLINE# #INDENT# LOG . warning ( 'No regions could be found excluding identity.' ) #NEWLINE# available_regions = [ get_endpoint_region ( service_catalog ) for service in service_catalog for endpoint in service . get ( 'endpoints' , [ ] ) ] #NEWLINE# if ( not available_regions ) : #NEWLINE# #INDENT# LOG . error ( 'No regions can be found in the service catalog.' ) #NEWLINE# return None #NEWLINE# #UNINDENT# #UNINDENT# selected_region = None #NEWLINE# if request : #NEWLINE# #INDENT# selected_region = request . COOKIES . get ( 'services_region' , available_regions [ 0 ] ) #NEWLINE# #UNINDENT# if ( selected_region not in available_regions ) : #NEWLINE# #INDENT# selected_region = available_regions [ 0 ] #NEWLINE# #UNINDENT# return selected_region #NEWLINE# #UNINDENT# return None