Module api
source code
$Id: api.py 27734 2013-03-13 16:30:16Z dcarlier $
Used to load the recognition tree and perform lookups of all properties, or
individual properties. Typical usage is as follows:
>>> import api
>>> dir(api)
['DaApi', 'IncorrectPropertyTypeException', 'InvalidPropertyException', 'JsonException', 'Mobi_Mtld_DA_UaProps', 'UnkownPropertyException', '__author__', '__builtins__', '__contributors__', '__doc__', '__file__', '__license__', '__name__', '__package__', '__url__', '__version__', 're', 'simplejson', 'string', 'sys', 'time', 'utilities']
>>> da = api.DaApi()
>>> tree = da.getTreeFromFile('DeviceAtlas.json')
>>> da.getTreeRevision(tree)
18251
>>> ua = 'SonyEricssonW850i/R1GB Browser/NetFront/3.3 Profile/MIDP-2.0 Configuration/CLDC-1.1'
>>> da.getProperties(tree, ua)
{u'drmOmaForwardLock': 1, u'umts': 1, u'displayWidth': 240, u'3gp.aac.lc': 1, u'mp3': 1, u'3gp.amr.wb': 1, u'cookieSupport': 1, u'midiPolyphonic': 1, u'image.Gif87': 1, u'3gp.h264.level10b': 1, u'wmv': 1, u'jsr118': 1, u'markup.xhtmlBasic10': 1, u'mp4.h264.level13': 0, u'mp4.h264.level11': 1, u'jqm': 0, u'vendor': u'Sony Ericsson', u'uriSchemeTel': 1, u'3gp.amr.nb': 1, u'amr': 1, u'stream.3gp.h264.level12': 0, u'stream.3gp.aac.lc': 1, u'stream.3gp.h264.level10': 1, u'stream.3gp.h264.level11': 0, u'osOsx': 0, u'midiMonophonic': 1, u'mp4.aac.lc': 1, u'gprs': 1, u'jsr30': 1, u'stream.3gp.h263': 1, u'usableDisplayHeight': 262, u'markup.xhtmlMp10': 1, u'markup.xhtmlMp12': 0, u'osAndroid': 0, u'qcelp': 0, u'osWindowsMobile': 0, u'3gpp2': 0, u'osSymbian': 0, u'mobileDevice': 1, '_unmatched': 'R1GB Browser/NetFront/3.3 Profile/MIDP-2.0 Configuration/CLDC-1.1', u'stream.mp4.h264.level13': 0, u'stream.mp4.h264.level11': 0, u'developerPlatformVersion': 7, u'osBada': 0, u'yearReleased': 2002, '_matched': 'SonyEricssonW850i/', u'midp': u'2.0', u'uriSchemeSmsTo': 0, u'developerPlatform': u'JavaPlatform', u'markup.wml1': 1, u'memoryLimitMarkup': 45000, u'cldc': u'1.1', u'amrInVideo': 1, u'qcelpInVideo': 0, u'https': 1, u'hscsd': 1, u'drmOmaSeparateDelivery': 1, u'image.Jpg': 1, u'uriSchemeSms': 1, u'stream.3gp.h264.level10b': 1, u'drmOmaCombinedDelivery': 1, u'vCardDownload': 1, u'aac': 1, u'osWindowsPhone': 0, u'mpeg4InVideo': 1, u'stream.mp4.aac.lc': 0, u'displayHeight': 320, u'mpeg4': 1, u'jsr37': 1, u'isTablet': 0, u'isEReader': 0, u'displayColorDepth': 18, u'3gp.h264.level13': 0, u'3gp.h264.level12': 0, u'3gp.h264.level11': 0, u'3gp.h264.level10': 1, u'id': 205009, u'image.Gif89a': 1, u'touchScreen': 0, u'csd': 1, u'3gpp': 1, u'jsr139': 1, u'aacInVideo': 1, u'image.Png': 1, u'markup.xhtmlMp11': 1, u'stream.3gp.amr.wb': 1, u'stream.3gp.amr.nb': 1, u'osWindows': 0, u'stream.3gp.h264.level13': 0, u'isMobilePhone': 1, u'3gp.h263': 1, u'osiOs': 0, u'hsdpa': 0, u'edge': 0, u'usableDisplayWidth': 230, u'h263Type0InVideo': 1, u'model': u'W850i', u'osWebOs': 0, u'isGamesConsole': 0}
>>>
>>> da.getProperty(tree, ua, 'displayWidth')
240
>>> da.getProperty(tree, ua, 'displayHeight')
320
>>> da.getPropertiesAsTyped(tree, ua)
{u'gprs': True, u'mpeg4': True, u'drmOmaForwardLock': True, u'umts': False, u'displayWidth': 240, u'mp3': True, u'markup.xhtmlMp11': True, u'markup.xhtmlMp10': True, u'markup.xhtmlMp12': False, u'id': 205009, u'memoryLimitMarkup': 45000, u'midiPolyphonic': True, u'image.Gif87': True, u'csd': True, u'3gpp': True, u'qcelp': False, u'wmv': True, u'markup.xhtmlBasic10': True, u'https': True, u'image.Gif89a': False, u'3gpp2': False, u'hscsd': False, u'midiMonophonic': True, u'drmOmaSeparateDelivery': True, u'displayColorDepth': 18, u'vendor': 'Sony Ericsson', u'image.Jpg': True, u'uriSchemeTel': True, u'mobileDevice': True, '_unmatched': 'R1GB Browser/NetFront/3.3 Profile/MIDP-2.0 Configuration/CLDC-1.1', u'hsdpa': False, u'amr': True, u'model': 'W850i', u'drmOmaCombinedDelivery': True, u'aac': False, u'mpeg4InVideo': True, u'image.Png': True, u'edge': False, u'h263Type0InVideo': True, u'displayHeight': 320, u'aacInVideo': True, '_matched': 'SonyEricssonW850i/'}
>>> da.getApiRevision()
2426
>>> da.listProperties(tree)
{u'drmOmaForwardLock': 'boolean', u'umts': 'boolean', u'displayWidth': 'integer', u'3gp.aac.lc': 'boolean', u'mp3': 'boolean', u'3gp.amr.wb': 'boolean', u'cookieSupport': 'boolean', u'osRim': 'boolean', u'midiPolyphonic': 'boolean', u'image.Gif87': 'boolean', u'3gp.h264.level10b': 'boolean', u'wmv': 'boolean', u'jsr118': 'boolean', u'markup.xhtmlBasic10': 'boolean', u'mp4.h264.level13': 'boolean', u'mp4.h264.level11': 'boolean', u'stylesheetSupport': 'string', u'httpDirectDownload': 'boolean', u'jqm': 'boolean', u'vendor': 'string', u'uriSchemeTel': 'boolean', u'isBrowser': 'boolean', u'3gp.amr.nb': 'boolean', u'browserName': 'string', u'amr': 'boolean', u'stream.3gp.h264.level12': 'boolean', u'stream.3gp.h264.level13': 'boolean', u'stream.3gp.h264.level10': 'boolean', u'stream.3gp.h264.level11': 'boolean', u'osLinux': 'boolean', u'osOsx': 'boolean', u'aacInVideo': 'boolean', u'mp4.aac.lc': 'boolean', u'gprs': 'boolean', u'memoryLimitEmbeddedMedia': 'integer', u'osWindowsMobile': 'boolean', u'jsr30': 'boolean', u'jsr37': 'boolean', u'markup.xhtmlMp11': 'boolean', u'markup.xhtmlMp10': 'boolean', u'markup.xhtmlMp12': 'boolean', u'osAndroid': 'boolean', u'qcelp': 'boolean', u'version': 'string', u'isFeedReader': 'boolean', u'osProprietary': 'string', u'3gpp2': 'boolean', u'oma': 'boolean', u'osSymbian': 'boolean', u'mobileDevice': 'boolean', u'stream.mp4.h264.level13': 'boolean', u'stream.mp4.h264.level11': 'boolean', u'isFilter': 'boolean', u'developerPlatformVersion': 'string', u'osBada': 'boolean', u'yearReleased': 'integer', u'awbInVideo': 'boolean', u'midp': 'string', u'uriSchemeSmsTo': 'boolean', u'memoryLimitDownload': 'integer', u'developerPlatform': 'string', u'markup.wml1': 'boolean', u'isSpam': 'boolean', u'memoryLimitMarkup': 'integer', u'cldc': 'string', u'inputDevices': 'string', u'amrInVideo': 'boolean', u'qcelpInVideo': 'boolean', u'https': 'boolean', u'markupSupport': 'string', u'hscsd': 'boolean', u'drmOmaSeparateDelivery': 'boolean', u'image.Jpg': 'boolean', u'uriSchemeSms': 'boolean', u'isRobot': 'boolean', u'stream.3gp.h264.level10b': 'boolean', u'drmOmaCombinedDelivery': 'boolean', u'vCardDownload': 'boolean', u'aac': 'boolean', u'isEReader': 'boolean', u'mpeg4InVideo': 'boolean', u'osWindowsPhone': 'boolean', u'stream.mp4.aac.lc': 'boolean', u'isDownloader': 'boolean', u'displayHeight': 'integer', u'mpeg4': 'boolean', u'stream.3gp.h263': 'boolean', u'imageFormatSupport': 'string', u'marketingName': 'string', u'isTablet': 'boolean', u'usableDisplayHeight': 'integer', u'displayColorDepth': 'integer', u'3gp.h264.level13': 'boolean', u'3gp.h264.level12': 'boolean', u'3gp.h264.level11': 'boolean', u'3gp.h264.level10': 'boolean', u'id': 'integer', u'stream.3gp.aac.lc': 'boolean', u'image.Gif89a': 'boolean', u'h263Type3InVideo': 'boolean', u'touchScreen': 'boolean', u'isChecker': 'boolean', u'jqm_alpha': 'boolean', u'csd': 'boolean', u'3gpp': 'boolean', u'aacLtpInVideo': 'boolean', u'jsr139': 'boolean', u'midiMonophonic': 'boolean', u'image.Png': 'boolean', u'stream.3gp.amr.wb': 'boolean', u'stream.3gp.amr.nb': 'boolean', u'osWindows': 'boolean', u'isMobilePhone': 'boolean', u'3gp.h263': 'boolean', u'osiOs': 'boolean', u'hsdpa': 'boolean', u'osVersion': 'string', u'browserVersion': 'string', u'inputModeSupport': 'string', u'scriptSupport': 'string', u'edge': 'boolean', u'usableDisplayWidth': 'integer', u'h263Type0InVideo': 'boolean', u'model': 'string', u'osWebOs': 'boolean', u'isGamesConsole': 'boolean'}
>>> da.getPropertiesAsTyped(tree, ua)['mobileDevice']
True
>>> da.getPropertiesAsTyped(tree, ua)['vendor']
'Sony Ericsson'
>>> da.getPropertiesAsTyped(tree, ua)['model']
'W850i'
>>> len(da.getPropertiesAsTyped(tree, ua))
4
In some contexts, the user-agent you want to recognise may have been provided
in a different header. Opera's mobile browser, for example, makes requests via
an HTTP proxy, which rewrites the headers. in that case, the original device's
user-agent is in the HTTP_X_OPERAMINI_PHONE_UA header.
Version:
1.6 Build $Rev: 27734 $
Author:
Ronan Cremin <http://deviceatlas.com/>
License:
Copyright (c) 2008, mTLD (dotMobi), All rights reserved.
Portions copyright (c) 2008 by Argo Interactive Limited.
Portions copyright (c) 2008 by Nokia Inc.
Portions copyright (c) 2008 by Telecom Italia Mobile S.p.A.
Portions copyright (c) 2008 by Volantis Systems Limited.
Portions copyright (c) 2002-2008 by Andreas Staeding.
Portions copyright (c) 2008 by Zandan.
|
__contributors__ = [ ' Adrian Hope-Balie <http://mobiforge.com/> ...
|
|
__package__ = None
|
|
__url__ = ' http://deviceatlas.com '
|
__contributors__
- Value:
[ ' Adrian Hope-Balie <http://mobiforge.com/> ' ,
' James Pearce <http://mobiforge.com/> ' ,
' Hamish Graham <http://deviceatlas.com> ' ,
' David Carlier <http://deviceatlas.com> ' ]
|
|