def device_from_request(request):
 from mezzanine.conf import settings
 try:
  for (device, _) in settings.DEVICE_USER_AGENTS:
   if (device == request.COOKIES[u'mezzanine-device']):
    return device
 except KeyError:
  try:
   user_agent = request.META[u'HTTP_USER_AGENT'].lower()
  except KeyError:
   pass
  else:
   try:
    user_agent = user_agent.decode(u'utf-8')
    for (device, ua_strings) in settings.DEVICE_USER_AGENTS:
     for ua_string in ua_strings:
      if (ua_string.lower() in user_agent):
       return device
   except (AttributeError, UnicodeDecodeError, UnicodeEncodeError):
    pass
 return u''

def device_from_request ( request ) : from mezzanine . conf import settings try : for ( device , _ ) in settings . DEVICE_USER_AGENTS : if ( device == request . COOKIES [ u'mezzanine-device' ] ) : return device except KeyError : try : user_agent = request . META [ u'HTTP_USER_AGENT' ] . lower ( ) except KeyError : pass else : try : user_agent = user_agent . decode ( u'utf-8' ) for ( device , ua_strings ) in settings . DEVICE_USER_AGENTS : for ua_string in ua_strings : if ( ua_string . lower ( ) in user_agent ) : return device except ( AttributeError , UnicodeDecodeError , UnicodeEncodeError ) : pass return u''
determines the device name from the request by first looking for an overridding cookie .