def get_request_location(request, context):
 if (context.location != ''):
  return context.location
 context.location = None
 if getattr(request, 'via_cdn', False):
  g.stats.simple_event('geoip.cdn_request')
  cdn_geoinfo = g.cdn_provider.get_client_location(request.environ)
  if cdn_geoinfo:
   context.location = cdn_geoinfo
 elif getattr(request, 'ip', None):
  g.stats.simple_event('geoip.non_cdn_request')
  timer = g.stats.get_timer('providers.geoip.location_by_ips')
  timer.start()
  location = location_by_ips(request.ip)
  if location:
   context.location = location.get('country_code', None)
  timer.stop()
 return context.location

def get_request_location ( request , context ) : if ( context . location != '' ) : return context . location context . location = None if getattr ( request , 'via_cdn' , False ) : g . stats . simple_event ( 'geoip.cdn_request' ) cdn_geoinfo = g . cdn_provider . get_client_location ( request . environ ) if cdn_geoinfo : context . location = cdn_geoinfo elif getattr ( request , 'ip' , None ) : g . stats . simple_event ( 'geoip.non_cdn_request' ) timer = g . stats . get_timer ( 'providers.geoip.location_by_ips' ) timer . start ( ) location = location_by_ips ( request . ip ) if location : context . location = location . get ( 'country_code' , None ) timer . stop ( ) return context . location
determine country of origin of the request for the given context this is done by: * checking the cdn headers for country of origin if set * falling back on geocoding request .