From: eitani Date: Thu, 13 Dec 2007 05:44:46 +0000 (+0000) Subject: * accessible.py (_getAndCache): Cleaned up: Fixed indent width and X-Git-Tag: AT_SPI2_ATK_2_12_0~788 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1657f7d822343aac460b0435ad50e44e3e9dcbdd;p=platform%2Fcore%2Fuifw%2Fat-spi2-atk.git * accessible.py (_getAndCache): Cleaned up: Fixed indent width and added epydoc string. git-svn-id: http://svn.gnome.org/svn/at-spi/trunk@975 e2bd861d-eb25-0410-b326-f6ed22b6b98c --- diff --git a/pyatspi/ChangeLog b/pyatspi/ChangeLog index 450c5d4..4971361 100644 --- a/pyatspi/ChangeLog +++ b/pyatspi/ChangeLog @@ -1,3 +1,8 @@ +2007-12-13 Eitan Isaacson + + * accessible.py (_getAndCache): Cleaned up: Fixed indent width and + added epydoc string. + 2007-11-15 Eitan Isaacson * accessible.py: Added new caching (bug #495077). Put in a mixin diff --git a/pyatspi/accessible.py b/pyatspi/accessible.py index 3766985..4413b3b 100644 --- a/pyatspi/accessible.py +++ b/pyatspi/accessible.py @@ -120,31 +120,44 @@ def _updateCache(event): return def _getAndCache(acc, value_name, get_method): - if _CACHE_LEVEL != constants.CACHE_PROPERTIES: - return get_method() + ''' + If property caching is enabled, use the cached proprty, or get the + property and cache it. If property caching is disabled, simply get the + property. + + @param value_name: The name of the value, like 'role' or 'description'. + @type value_name: string + @param get_method: Method used to get the property, should not have any + arguments. + @type get_method: callable + @return: Value of property we are retrieving. + @rtype: object + ''' + if _CACHE_LEVEL != constants.CACHE_PROPERTIES: + return get_method() - cache = _ACCESSIBLE_CACHE - h = hash(acc) + cache = _ACCESSIBLE_CACHE + h = hash(acc) + try: + pc = acc._property_cache + except AttributeError: try: - pc = acc._property_cache - except AttributeError: - try: - pc = cache[h] - except KeyError: - # no cached info for this accessible yet - pc = _PropertyCache() - cache[h] = pc - acc._property_cache = pc + pc = cache[h] + except KeyError: + # no cached info for this accessible yet + pc = _PropertyCache() + cache[h] = pc + acc._property_cache = pc - try: - value = getattr(pc, value_name) - except AttributeError: - # no cached property of this type - value = get_method() - setattr(pc, value_name, value) + try: + value = getattr(pc, value_name) + except AttributeError: + # no cached property of this type + value = get_method() + setattr(pc, value_name, value) - return value + return value def _makeQuery(interface):