#NEWLINE# def location( request ) : #NEWLINE# #INDENT# '\n    Transform an IP address into an approximate location.\n    ' #NEWLINE# ip = utils . resolve ( app_settings . IP_RESOLVER , request ) #NEWLINE# try : #NEWLINE# #INDENT# location = ( GeoIP ( ) and GeoIP ( ) . city ( ip ) ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# return ugettext ( 'unknown' ) #NEWLINE# #UNINDENT# if ( location and location [ 'country_name' ] ) : #NEWLINE# #INDENT# if location [ 'city' ] : #NEWLINE# #INDENT# return ( '%s, %s' % ( location [ 'city' ] , location [ 'country_name' ] ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return location [ 'country_name' ] #NEWLINE# #UNINDENT# #UNINDENT# return ugettext ( 'unknown' )