api (version $Rev$)
index
c:\python25\lib\site-packages\api.py

$Id$
 
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', '__author__', '__builtins__', '__contributors__', '__doc__', '__file__', '__license__', '__name__', '__version__', 'simplejson', 'string', 'sys', 'time']
    >>> da = da.DaApi()
    >>> tree = da.getTreeFromFile('DeviceAtlas.json')
    >>> da.getTreeRevision(tree)
    2347
    >>> ua = 'SonyEricssonW850i/R1GB Browser/NetFront/3.3 Profile/MIDP-2.0 Configuration/CLDC-1.1'
    >>> da.getProperties(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.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'gprs': 'boolean', u'memoryLimitDownload': 'integer', u'mpeg4': 'boolean', u'drmOmaForwardLock': 'boolean', u'memoryLimitEmbeddedMedia': 'integer', u'umts': 'boolean', u'displayWidth': 'integer', u'mp3': 'boolean', u'markup.xhtmlMp11': 'boolean', u'markup.xhtmlMp10': 'boolean', u'cookieSupport': 'boolean', u'markup.xhtmlMp12': 'boolean', u'id': 'integer', u'image.Gif89a': 'boolean', u'midiPolyphonic': 'boolean', u'image.Gif87': 'boolean', u'isChecker': 'boolean', u'csd': 'boolean', u'3gpp': 'boolean', u'qcelp': 'boolean', u'wmv': 'boolean', u'drmOmaSeparateDelivery': 'boolean', u'isSpam': 'boolean', u'markup.xhtmlBasic10': 'boolean', u'aacLtpInVideo': 'boolean', u'version': 'string', u'amrInVideo': 'boolean', u'qcelpInVideo': 'boolean', u'https': 'boolean', u'stylesheetSupport': 'string', u'memoryLimitMarkup': 'integer', u'3gpp2': 'boolean', u'hscsd': 'boolean', u'midiMonophonic': 'boolean', u'image.Png': 'boolean', u'displayColorDepth': 'integer', u'vendor': 'string', u'image.Jpg': 'boolean', u'uriSchemeTel': 'boolean', u'isRobot': 'boolean', u'mobileDevice': 'boolean', u'isBrowser': 'boolean', u'isFilter': 'boolean', u'isDownloader': 'boolean', u'hsdpa': 'boolean', u'amr': 'boolean', u'displayHeight': 'integer', u'h263Type3InVideo': 'boolean', u'drmOmaCombinedDelivery': 'boolean', u'aac': 'boolean', u'scriptSupport': 'string', u'mpeg4InVideo': 'boolean', u'awbInVideo': 'boolean', u'edge': 'boolean', u'h263Type0InVideo': 'boolean', u'model': 'string', u'aacInVideo': '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.

 
Modules
       
simplejson
string
sys
time

 
Classes
       
DaApi

 
class DaApi
     Methods defined here:
getApiRevision(self)
Returns revision number of the API
tree is a previously generated tree
getProperties(self, tree, userAgent)
Returns an array of known properties (as strings) for the UA
 
tree is previously generated tree
userAgent is string from devices User-Agent header
getPropertiesAsTyped(self, tree, userAgent)
Returns an array of known properties (as typed) for the UA
 
tree is previously generated tre
userAgent is string from devices User-Agent header
getProperty(self, tree, userAgent, property)
Returns a value for the named property of this user agent
 
tree is previously generated tree
userAgent is string from devices User-Agent header
property is the name of the property to return
getPropertyAsBoolean(self, tree, userAgent, property)
Strongly-typed property accessor. Returns boolean property. 
Throws exception of property is actually a different type
 
tree is previously generated tree
userAgent is string from devices User-Agent header
property is the name of the property to return
getPropertyAsDate(self, tree, userAgent, property)
Strongly-typed property accessor. Returns date property. 
Throws exception of property is actually a different type
 
tree is previously generated tree
userAgent is string from devices User-Agent header
property is the name of the property to return
getPropertyAsInteger(self, tree, userAgent, property)
Strongly-typed property accessor. Returns integer property. 
Throws exception of property is actually a different type
 
tree is previously generated tree
userAgent is string from devices User-Agent header
property is the name of the property to return
getPropertyAsString(self, tree, userAgent, property)
Strongly-typed property accessor. Returns string property. 
Throws exception of property is actually a different type
 
tree is previously generated tree
userAgent is string from devices User-Agent header
property is the name of the property to return
getTreeFromFile(self, file)
Returns a tree from a JSON file
file is the location of the file to read
getTreeFromString(self, json)
Returns a tree from a JSON string return array tree
json is a string of json data.
Throws RunTimeError
getTreeRevision(self, tree)
Returns revision number of the tree
tree is a previously generated tree
listProperties(self, tree)
Returns array of known property names. Returns all properties
available for all user agents in this tree, with their data type
names
tree is previously generated tree
listToDictionary(self, tree)
Recursively changes lists in passed tree to dictionaries

 
Data
        __author__ = 'Ronan Cremin <http://dev.mobi/>'
__contributors__ = ['Adrian Hope-Balie <http://dev.mobi/>', 'James Pearce <http://dev.mobi/>']
__license__ = 'Copyright (c) 2008, mTLD (dotMobi), All rights r...Staeding.\nPortions copyright (c) 2008 by Zandan.\n'
__url__ = 'http://deviceatlas.com'
__version__ = '$Rev$'

 
Author
        Ronan Cremin <http://dev.mobi/>