Example #1
0
def test():
    import wurfl_classify
    devices = get_stable()
    total = len(devices)
    failures = 0
    for user_agent, type in devices.items():
        classified = wurfl_classify.device_type(user_agent)
        if classified != type:
            print 'user_agent: "' + user_agent + '"'
            print 'correct type=' + type
            print 'classified=' + classified
            print ' '
            failures += 1
    print 'success %i/%i' % (total-failures, total)
    devices.close()
Example #2
0
def mobile_detect(user_agent, device_cache):

    wurfl_obj = None
    if stable_db.has_key(user_agent):
        return stable_db[user_agent]
    try:
        device = device_cache.find(user_agent)
    except device_cache.NotFound:
        try:
            device_cache.reset()
            device = device_cache.find(user_agent)
        except device_cache.NotFound:
            import wurfl_classify
            device = wurfl_classify.device_type(user_agent)
            device_cache.add_device(user_agent, device)

    return device