[pyatspi2] Fix for BGO#645644: Throw LookupError rather than RUntimeError



commit 056651e43788353382069e5cd6942f1dcc1cd0bf
Author: Mike Gorse <mgorse novell com>
Date:   Mon Apr 25 18:26:00 2011 -0500

    Fix for BGO#645644: Throw LookupError rather than RUntimeError
    
    Pyatspi-CORBA threw LookupError for most IPC exceptions, but pyatspi2 has
    generally been throwing RuntimeError, as is pygi's behavior.  Added a wrapper
    function that can be used to catch these errors and throw LookupError instead,
    and generally use for method calls.

 pyatspi/Accessibility.py |  182 ++++++++++++++++++++++++---------------------
 pyatspi/document.py      |    7 +-
 pyatspi/editabletext.py  |   13 ++--
 pyatspi/text.py          |   50 ++++++------
 pyatspi/utils.py         |    8 ++
 5 files changed, 141 insertions(+), 119 deletions(-)
---
diff --git a/pyatspi/Accessibility.py b/pyatspi/Accessibility.py
index 7704df7..154e6d1 100644
--- a/pyatspi/Accessibility.py
+++ b/pyatspi/Accessibility.py
@@ -137,54 +137,66 @@ def Event_str(self):
                (self.type, self.detail1, self.detail2, self.any_data,
                 self.source, self.host_application)
   
+def exwrap(func, *args):
+	try:
+                return func(*args)
+        except RuntimeError as e:
+                try:
+                        domain = e.domain
+                except:
+                        raise e
+                if domain == "atspi_error":
+                        raise LookupError
+                else:
+                        raise e
 
 ### Accessible ###
 Accessible = Atspi.Accessible
-Atspi.Accessible.getChildAtIndex = Atspi.Accessible.get_child_at_index
-Atspi.Accessible.getAttributes = Atspi.Accessible.get_attributes_as_array
-Atspi.Accessible.getApplication = Atspi.Accessible.get_application
-Atspi.Accessible.__getitem__ = Accessible_getitem
-Atspi.Accessible.__len__ = Atspi.Accessible.get_child_count
+Atspi.Accessible.getChildAtIndex = lambda *args: exwrap(Atspi.Accessible.get_child_at_index, *args)
+Atspi.Accessible.getAttributes = lambda *args: exwrap(Atspi.Accessible.get_attributes_as_array, *args)
+Atspi.Accessible.getApplication = lambda *args: exwrap(Atspi.Accessible.get_application, *args)
+Atspi.Accessible.__getitem__ = lambda *args: exwrap(Accessible_getitem, *args)
+Atspi.Accessible.__len__ = lambda *args: exwrap(Atspi.Accessible.get_child_count, *args)
 Atspi.Accessible.__nonzero__ = lambda x: True
 Atspi.Accessible.__str__ = Accessible_str
-Atspi.Accessible.childCount = property(fget=Atspi.Accessible.get_child_count)
-Atspi.Accessible.getChildCount = Atspi.Accessible.get_child_count
-Atspi.Accessible.getIndexInParent = Atspi.Accessible.get_index_in_parent
-Atspi.Accessible.getLocalizedRoleName = Atspi.Accessible.get_localized_role_name
-Atspi.Accessible.getRelationSet = Atspi.Accessible.get_relation_set
-Atspi.Accessible.getRole = Atspi.Accessible.get_role
-Atspi.Accessible.getRoleName = Atspi.Accessible.get_role_name
-Atspi.Accessible.getState = Atspi.Accessible.get_state_set
+Atspi.Accessible.childCount = property(fget=lambda x: exwrap(Atspi.Accessible.get_child_count, x))
+Atspi.Accessible.getChildCount = lambda *args: exwrap(Atspi.Accessible.get_child_count, *args)
+Atspi.Accessible.getIndexInParent = lambda *args: exwrap(Atspi.Accessible.get_index_in_parent, *args)
+Atspi.Accessible.getLocalizedRoleName = lambda *args: exwrap(Atspi.Accessible.get_localized_role_name, *args)
+Atspi.Accessible.getRelationSet = lambda *args: exwrap(Atspi.Accessible.get_relation_set, *args)
+Atspi.Accessible.getRole = lambda *args: exwrap(Atspi.Accessible.get_role, *args)
+Atspi.Accessible.getRoleName = lambda *args: exwrap(Atspi.Accessible.get_role_name, *args)
+Atspi.Accessible.getState = lambda *args: exwrap(Atspi.Accessible.get_state_set, *args)
 del Atspi.Accessible.children
-Atspi.Accessible.description = property(fget=Atspi.Accessible.get_description)
-Atspi.Accessible.name = property(fget=Atspi.Accessible.get_name)
+Atspi.Accessible.description = property(fget=lambda x: exwrap(Atspi.Accessible.get_description, x))
+Atspi.Accessible.name = property(fget=lambda x: exwrap(Atspi.Accessible.get_name, x))
 Atspi.Accessible.isEqual = lambda a,b: a == b
 Atspi.Accessible.parent = property(fget=Atspi.Accessible.get_parent)
 Atspi.Accessible.setCacheMask = Atspi.Accessible.set_cache_mask
 
-Atspi.Accessible.id = property(fget=Atspi.Accessible.get_id)
-Atspi.Accessible.toolkitName = property(fget=Atspi.Accessible.get_toolkit_name)
-Atspi.Accessible.toolkitVersion = property(fget=Atspi.Accessible.get_toolkit_version)
+Atspi.Accessible.id = property(fget=lambda x: exwrap(Atspi.Accessible.get_id, x))
+Atspi.Accessible.toolkitName = property(fget=lambda x: exwrap(Atspi.Accessible.get_toolkit_name, x))
+Atspi.Accessible.toolkitVersion = property(fget=lambda x: exwrap(Atspi.Accessible.get_toolkit_version, x))
 
 ### action ###
-Action = Atspi.Action
+Action = lambda *args: exwrap(Atspi.Action, *args)
 Atspi.Accessible.queryAction = lambda x: getInterface(Atspi.Accessible.get_action, x)
-Atspi.Action.doAction = Atspi.Action.do_action
-Atspi.Action.getDescription = Atspi.Action.get_description
-Atspi.Action.getKeyBinding = Atspi.Action.get_key_binding
-Atspi.Action.getName = Atspi.Action.get_name
-Atspi.Action.nActions = property(fget=Atspi.Action.get_n_actions)
+Atspi.Action.doAction = lambda *args: exwrap(Atspi.Action.do_action, *args)
+Atspi.Action.getDescription = lambda *args: exwrap(Atspi.Action.get_description, *args)
+Atspi.Action.getKeyBinding = lambda *args: exwrap(Atspi.Action.get_key_binding, *args)
+Atspi.Action.getName = lambda *args: exwrap(Atspi.Action.get_name, *args)
+Atspi.Action.nActions = property(fget=lambda x: exwrap(Atspi.Action.get_n_actions, x))
 
 ### collection ###
-Collection = Atspi.Collection
+Collection = lambda *args: exwrap(Atspi.Collection, *args)
 Atspi.Accessible.queryCollection = lambda x: getInterface(Atspi.Accessible.get_collection, x)
-Atspi.Collection.isAncesterOf = Atspi.Collection.is_ancestor_of
+Atspi.Collection.isAncesterOf = lambda *args: exwrap(Atspi.Collection.is_ancestor_of, *args)
 Atspi.Collection.createMatchRule = lambda x, s, smt, a, amt, r, rmt, i, imt, inv: Atspi.MatchRule.new (s, smt, attributeListToHash(a), amt, r, rmt, i, imt, inv)
 Atspi.Collection.freeMatchRule = lambda self, x: None
-Atspi.Collection.getMatches = Atspi.Collection.get_matches
-Atspi.Collection.getMatchesFrom = Atspi.Collection.get_matches_from
-Atspi.Collection.getMatchesTo = Atspi.Collection.get_matches_to
-Atspi.Collection.getActiveDescendant = Atspi.Collection.get_active_descendant
+Atspi.Collection.getMatches = lambda *args: exwrap(Atspi.Collection.get_matches, *args)
+Atspi.Collection.getMatchesFrom = lambda *args: exwrap(Atspi.Collection.get_matches_from, *args)
+Atspi.Collection.getMatchesTo = lambda *args: exwrap(Atspi.Collection.get_matches_to, *args)
+Atspi.Collection.getActiveDescendant = lambda *args: exwrap(Atspi.Collection.get_active_descendant, *args)
 
 Atspi.Collection.MATCH_INVALID = Atspi.CollectionMatchType.INVALID
 Atspi.Collection.MATCH_ALL = Atspi.CollectionMatchType.ALL
@@ -207,17 +219,17 @@ Atspi.Collection.TREE_INORDER = Atspi.CollectionTreeTraversalType.INORDER
 ### component ###
 Component = Atspi.Component
 Atspi.Accessible.queryComponent = lambda x: getInterface(Atspi.Accessible.get_component, x)
-Atspi.Component.getAccessibleAtPoint = Atspi.Component.get_accessible_at_point
-Atspi.Component.getAlpha = Atspi.Component.get_alpha
+Atspi.Component.getAccessibleAtPoint = lambda *args: exwrap(Atspi.Component.get_accessible_at_point, *args)
+Atspi.Component.getAlpha = lambda *args: exwrap(Atspi.Component.get_alpha, *args)
 Atspi.Component.getExtents = lambda x,c: getBoundingBox(Atspi.Component.get_extents(x,c))
-Atspi.Component.getLayer = Atspi.Component.get_layer
-Atspi.Component.getMDIZOrder = Atspi.Component.get_mdi_z_order
+Atspi.Component.getLayer = lambda *args: exwrap(Atspi.Component.get_layer, *args)
+Atspi.Component.getMDIZOrder = lambda *args: exwrap(Atspi.Component.get_mdi_z_order, *args)
 Atspi.Component.getPosition = lambda x,p: pointToList(Atspi.Component.get_position(x,p))
 Atspi.Component.getSize = lambda x: pointToList(Atspi.Component.get_size(x))
-Atspi.Component.grabFocus = Atspi.Component.grab_focus
-Atspi.Component.setExtents = Atspi.Component.set_extents
-Atspi.Component.setPosition = Atspi.Component.set_position
-Atspi.Component.setSize = Atspi.Component.set_size
+Atspi.Component.grabFocus = lambda *args: exwrap(Atspi.Component.grab_focus, *args)
+Atspi.Component.setExtents = lambda *args: exwrap(Atspi.Component.set_extents, *args)
+Atspi.Component.setPosition = lambda *args: exwrap(Atspi.Component.set_position, *args)
+Atspi.Component.setSize = lambda *args: exwrap(Atspi.Component.set_size, *args)
 
 ### document ###
 Atspi.Accessible.queryDocument = lambda x: Document(getInterface(Atspi.Accessible.get_document, x))
@@ -227,20 +239,20 @@ Atspi.Accessible.queryEditableText = lambda x: EditableText(getInterface(Atspi.A
 
 ### hyperlink ###
 Hyperlink = Atspi.Hyperlink
-Atspi.Hyperlink.getObject = Atspi.Hyperlink.get_object
-Atspi.Hyperlink.getURI = Atspi.Hyperlink.get_uri
-Atspi.Hyperlink.isValid = Atspi.Hyperlink.is_valid
-Atspi.Hyperlink.endIndex = property(fget=Atspi.Hyperlink.get_end_index)
-Atspi.Hyperlink.nAnchors = property(fget=Atspi.Hyperlink.get_n_anchors)
-Atspi.Hyperlink.startIndex = property(fget=Atspi.Hyperlink.get_start_index)
+Atspi.Hyperlink.getObject = lambda *args: exwrap(Atspi.Hyperlink.get_object, *args)
+Atspi.Hyperlink.getURI = lambda *args: exwrap(Atspi.Hyperlink.get_uri, *args)
+Atspi.Hyperlink.isValid = lambda *args: exwrap(Atspi.Hyperlink.is_valid, *args)
+Atspi.Hyperlink.endIndex = property(fget=lambda x: exwrap(Atspi.Hyperlink.get_end_index, x))
+Atspi.Hyperlink.nAnchors = property(fget=lambda x: exwrap(Atspi.Hyperlink.get_n_anchors, x))
+Atspi.Hyperlink.startIndex = property(fget=lambda x: exwrap(Atspi.Hyperlink.get_start_index, x))
 
 ### hypertext ###
 Hypertext = Atspi.Hypertext
 Atspi.Accessible.queryHyperlink = lambda x: getInterface(Atspi.Accessible.get_hyperlink, x)
 Atspi.Accessible.queryHypertext = lambda x: getInterface(Atspi.Accessible.get_hypertext, x)
-Atspi.Hypertext.getLink = Atspi.Hypertext.get_link
-Atspi.Hypertext.getLinkIndex = Atspi.Hypertext.get_link_index
-Atspi.Hypertext.getNLinks = Atspi.Hypertext.get_n_links
+Atspi.Hypertext.getLink = lambda *args: exwrap(Atspi.Hypertext.get_link, *args)
+Atspi.Hypertext.getLinkIndex = lambda *args: exwrap(Atspi.Hypertext.get_link_index, *args)
+Atspi.Hypertext.getNLinks = lambda *args: exwrap(Atspi.Hypertext.get_n_links, *args)
 
 ### image ###
 Image = Atspi.Image
@@ -248,48 +260,48 @@ Atspi.Accessible.queryImage = lambda x: getInterface(Atspi.Accessible.get_image,
 Atspi.Image.getImageExtents = lambda x,c: getBoundingBox(Atspi.Image.get_image_extents(x,c))
 Atspi.Image.getImagePosition = lambda x,p: pointToList(Atspi.Image.get_image_position(x,p))
 Atspi.Image.getImageSize = lambda x: pointToList(Atspi.Image.get_image_size(x))
-Atspi.Image.imageDescription = property(fget=Atspi.Image.get_image_description)
-Atspi.Image.imageLocale = property(fget=Atspi.Image.get_image_locale)
+Atspi.Image.imageDescription = property(fget=lambda x: exwrap(Atspi.Image.get_image_description, x))
+Atspi.Image.imageLocale = property(fget=lambda x: exwrap(Atspi.Image.get_image_locale, x))
 
 ### selection ###
 Selection = Atspi.Selection
 Atspi.Accessible.querySelection = lambda x: getInterface(Atspi.Accessible.get_selection, x)
-Atspi.Selection.clearSelection = Atspi.Selection.clear_selection
-Atspi.Selection.deselectChild = Atspi.Selection.deselect_child
-Atspi.Selection.deselectSelectedChild = Atspi.Selection.deselect_selected_child
-Atspi.Selection.getSelectedChild = Atspi.Selection.get_selected_child
-Atspi.Selection.isChildSelected = Atspi.Selection.is_child_selected
-Atspi.Selection.selectAll = Atspi.Selection.select_all
-Atspi.Selection.selectChild = Atspi.Selection.select_child
-Atspi.Selection.nSelectedChildren = property(fget=Atspi.Selection.get_n_selected_children)
+Atspi.Selection.clearSelection = lambda *args: exwrap(Atspi.Selection.clear_selection, *args)
+Atspi.Selection.deselectChild = lambda *args: exwrap(Atspi.Selection.deselect_child, *args)
+Atspi.Selection.deselectSelectedChild = lambda *args: exwrap(Atspi.Selection.deselect_selected_child, *args)
+Atspi.Selection.getSelectedChild = lambda *args: exwrap(Atspi.Selection.get_selected_child, *args)
+Atspi.Selection.isChildSelected = lambda *args: exwrap(Atspi.Selection.is_child_selected, *args)
+Atspi.Selection.selectAll = lambda *args: exwrap(Atspi.Selection.select_all, *args)
+Atspi.Selection.selectChild = lambda *args: exwrap(Atspi.Selection.select_child, *args)
+Atspi.Selection.nSelectedChildren = property(fget=lambda x: exwrap(Atspi.Selection.get_n_selected_children, x))
 
 ### table ###
 Table = Atspi.Table
 Atspi.Accessible.queryTable = lambda x: getInterface(Atspi.Accessible.get_table, x)
-Atspi.Table.addColumnSelection = Atspi.Table.add_column_selection
-Atspi.Table.addRowSelection = Atspi.Table.add_row_selection
-Atspi.Table.getAccessibleAt = Atspi.Table.get_accessible_at
-Atspi.Table.getColumnAtIndex = Atspi.Table.get_column_at_index
-Atspi.Table.getColumnDescription = Atspi.Table.get_column_description
-Atspi.Table.getColumnExtentAt = Atspi.Table.get_column_extent_at
-Atspi.Table.getColumnHeader = Atspi.Table.get_column_header
-Atspi.Table.getIndexAt = Atspi.Table.get_index_at
-Atspi.Table.getRowAtIndex = Atspi.Table.get_row_at_index
-Atspi.Table.getRowColumnExtents = Atspi.Table.get_row_column_extents_at_index
-Atspi.Table.getRowDescription = Atspi.Table.get_row_description
-Atspi.Table.getRowExtentAt = Atspi.Table.get_row_extent_at
-Atspi.Table.getRowHeader = Atspi.Table.get_row_header
-Atspi.Table.getSelectedColumns = Atspi.Table.get_selected_columns
-Atspi.Table.getSelectedRows = Atspi.Table.get_selected_rows
-Atspi.Table.isColumnSelected = Atspi.Table.is_column_selected
-Atspi.Table.isRowSelected = Atspi.Table.is_row_selected
-Atspi.Table.isSelected = Atspi.Table.is_selected
-Atspi.Table.removeColumnSelection = Atspi.Table.remove_column_selection
-Atspi.Table.removeRowSelection = Atspi.Table.remove_row_selection
-Atspi.Table.nColumns = property(fget=Atspi.Table.get_n_columns)
-Atspi.Table.nRows = property(fget=Atspi.Table.get_n_rows)
-Atspi.Table.get_nSelectedColumns = Atspi.Table.get_n_selected_columns
-Atspi.Table.get_nSelectedRows = Atspi.Table.get_n_selected_rows
+Atspi.Table.addColumnSelection = lambda *args: exwrap(Atspi.Table.add_column_selection, *args)
+Atspi.Table.addRowSelection = lambda *args: exwrap(Atspi.Table.add_row_selection, *args)
+Atspi.Table.getAccessibleAt = lambda *args: exwrap(Atspi.Table.get_accessible_at, *args)
+Atspi.Table.getColumnAtIndex = lambda *args: exwrap(Atspi.Table.get_column_at_index, *args)
+Atspi.Table.getColumnDescription = lambda *args: exwrap(Atspi.Table.get_column_description, *args)
+Atspi.Table.getColumnExtentAt = lambda *args: exwrap(Atspi.Table.get_column_extent_at, *args)
+Atspi.Table.getColumnHeader = lambda *args: exwrap(Atspi.Table.get_column_header, *args)
+Atspi.Table.getIndexAt = lambda *args: exwrap(Atspi.Table.get_index_at, *args)
+Atspi.Table.getRowAtIndex = lambda *args: exwrap(Atspi.Table.get_row_at_index, *args)
+Atspi.Table.getRowColumnExtents = lambda *args: exwrap(Atspi.Table.get_row_column_extents_at_index, *args)
+Atspi.Table.getRowDescription = lambda *args: exwrap(Atspi.Table.get_row_description, *args)
+Atspi.Table.getRowExtentAt = lambda *args: exwrap(Atspi.Table.get_row_extent_at, *args)
+Atspi.Table.getRowHeader = lambda *args: exwrap(Atspi.Table.get_row_header, *args)
+Atspi.Table.getSelectedColumns = lambda *args: exwrap(Atspi.Table.get_selected_columns, *args)
+Atspi.Table.getSelectedRows = lambda *args: exwrap(Atspi.Table.get_selected_rows, *args)
+Atspi.Table.isColumnSelected = lambda *args: exwrap(Atspi.Table.is_column_selected, *args)
+Atspi.Table.isRowSelected = lambda *args: exwrap(Atspi.Table.is_row_selected, *args)
+Atspi.Table.isSelected = lambda *args: exwrap(Atspi.Table.is_selected, *args)
+Atspi.Table.removeColumnSelection = lambda *args: exwrap(Atspi.Table.remove_column_selection, *args)
+Atspi.Table.removeRowSelection = lambda *args: exwrap(Atspi.Table.remove_row_selection, *args)
+Atspi.Table.nColumns = property(fget=lambda x: exwrap(Atspi.Table.get_n_columns, x))
+Atspi.Table.nRows = property(fget=lambda x: exwrap(Atspi.Table.get_n_rows, x))
+Atspi.Table.get_nSelectedColumns = lambda *args: exwrap(Atspi.Table.get_n_selected_columns, *args)
+Atspi.Table.get_nSelectedRows = lambda *args: exwrap(Atspi.Table.get_n_selected_rows, *args)
 
 ### text ###
 Atspi.Accessible.queryText = lambda x: Text(getInterface(Atspi.Accessible.get_text, x))
@@ -310,10 +322,10 @@ TEXT_CLIP_BOTH= Atspi.TextClipType.BOTH
 ### value ###
 Value = Atspi.Value
 Atspi.Accessible.queryValue = lambda x: getInterface(Atspi.Accessible.get_value, x)
-Atspi.Value.currentValue = property(fget=Atspi.Value.get_current_value, fset=Atspi.Value.set_current_value)
-Atspi.Value.maximumValue = property(fget=Atspi.Value.get_maximum_value)
-Atspi.Value.minimumIncrement = property(fget=Atspi.Value.get_minimum_increment)
-Atspi.Value.minimumValue = property(fget=Atspi.Value.get_minimum_value)
+Atspi.Value.currentValue = property(fget=lambda x: exwrap(Atspi.Value.get_current_value, x), fset=Atspi.Value.set_current_value)
+Atspi.Value.maximumValue = property(fget=lambda x: exwrap(Atspi.Value.get_maximum_value, x))
+Atspi.Value.minimumIncrement = property(fget=lambda x: exwrap(Atspi.Value.get_minimum_increment, x))
+Atspi.Value.minimumValue = property(fget=lambda x: exwrap(Atspi.Value.get_minimum_value, x))
 
 ### DeviceEvent ###
 Atspi.DeviceEvent.__str__ = DeviceEvent_str
diff --git a/pyatspi/document.py b/pyatspi/document.py
index 36284ce..610c2a0 100644
--- a/pyatspi/document.py
+++ b/pyatspi/document.py
@@ -14,6 +14,7 @@
 #Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
 from gi.repository import Atspi
+import utils
 
 __all__ = [
            "Document",
@@ -46,7 +47,7 @@ class Document:
                 attribute, or an empty string if the attribute is unspecified
                 for the object.
                 """
-                return Atspi.Document.get_attribute_value(self.obj, key)
+                return exwrap(Atspi.Document.get_attribute_value, self.obj, key)
 
         def getAttributes(self):
                 """
@@ -56,7 +57,7 @@ class Document:
                 @return an AttributeSet containing the attributes of the document,
                 as name-value pairs.
                 """
-                ret = Atspi.Document.get_attributes(self.obj)
+                ret = exwrap(Atspi.Document.get_attributes, self.obj)
                 return [key + ':' + value for key, value in ret.iteritems()]
 
         def getLocale(self):
@@ -66,6 +67,6 @@ class Document:
                 @return a string compliant with the POSIX standard for locale
                 description.
                 """
-                return Atspi.Document.get_locale(self.obj)
+                return exwrap(Atspi.Document.get_locale, self.obj)
 
 #END----------------------------------------------------------------------------
diff --git a/pyatspi/editabletext.py b/pyatspi/editabletext.py
index ead32a4..f863b33 100644
--- a/pyatspi/editabletext.py
+++ b/pyatspi/editabletext.py
@@ -15,6 +15,7 @@
 from interfaces import *
 from text import *
 from gi.repository import Atspi
+from utils import *
 
 __all__ = [
            "EditableText",
@@ -40,7 +41,7 @@ class EditableText(Text):
                 the offset of the first character past the end of the range of
                 text being copied.
                 """
-                return Atspi.EditableText.copy_text(self.obj, start, end)
+                return exwrap(Atspi.EditableText.copy_text, self.obj, start, end)
 
         def cutText(self, start, end):
                 """
@@ -54,7 +55,7 @@ class EditableText(Text):
                 text being cut. 
                 @return True if the text was successfully cut, False otherwise.
                 """
-                return Atspi.EditableText.cut_text(self.obj, start, end)
+                return exwrap(Atspi.EditableText.cut_text, self.obj, start, end)
 
         def deleteText(self, start, end):
                 """
@@ -68,7 +69,7 @@ class EditableText(Text):
                 text being deleted. 
                 @return True if the text was successfully deleted, False otherwise.
                 """
-                return Atspi.EditableText.delete_text(self.obj, start, end)
+                return exwrap(Atspi.EditableText.delete_text, self.obj, start, end)
 
         def insertText(self, position, text, length):
                 """
@@ -87,7 +88,7 @@ class EditableText(Text):
                 @return True if the text content was successfully inserted, False
                 otherwise.
                 """
-                return Atspi.EditableText.insert_text(self.obj, position, text, length)
+                return exwrap(Atspi.EditableText.insert_text, self.obj, position, text, length)
 
         def pasteText(self, position):
                 """
@@ -98,7 +99,7 @@ class EditableText(Text):
                 @return True if the text was successfully pasted into the Text
                 object, False otherwise.
                 """
-                return Atspi.EditableText.paste_text(self.obj, position)
+                return exwrap(Atspi.EditableText.paste_text, self.obj, position)
 
         def setTextContents(self, contents):
                 """
@@ -110,6 +111,6 @@ class EditableText(Text):
                 @return True if the text content was successfully changed, False
                 otherwise.
                 """
-                return Atspi.EditableText.set_text_contents(self.obj, contents)
+                return exwrap(Atspi.EditableText.set_text_contents, self.obj, contents)
 
 #END----------------------------------------------------------------------------
diff --git a/pyatspi/text.py b/pyatspi/text.py
index acbd2bd..e59e943 100644
--- a/pyatspi/text.py
+++ b/pyatspi/text.py
@@ -15,7 +15,7 @@
 
 from gi.repository import Atspi
 from enum import *
-import utils
+from utils import *
 
 
 __all__ = [
@@ -115,7 +115,7 @@ class Text:
                 other reasons (for instance if the user does not have permission
                 to copy the text into the relevant selection buffer).
                 """
-                return Atspi.Text.add_selection(self.obj, index)
+                return exwrap(Atspi.Text.add_selection, self.obj, index)
 
         def getAttributeRun(self, offset, includeDefaults=True):
                 """
@@ -166,7 +166,7 @@ class Text:
                 @return the AttributeSet defined at offset, optionally including
                 the 'default' attributes.
                 """
-                [attrs, startOffset, endOffset] = Atspi.Text.get_attribute_run(self.obj, offset, includeDefaults)
+                [attrs, startOffset, endOffset] = exwrap(Atspi.Text.get_attribute_run, self.obj, offset, includeDefaults)
                 dict = [key + ':' + value for key, value in attrs.items()]
                 return [dict, startOffset, endOffset]
 
@@ -192,7 +192,7 @@ class Text:
                 @return the value of attribute (name-value pair) corresponding
                 to "name", if defined.
                 """
-                return Atspi.Text.get_attribute_value(self.obj, offset, attributeName)
+                return exwrap(Atspi.Text.get_attribute_value, self.obj, offset, attributeName)
 
         def getAttributes(self, offset):
                 """
@@ -200,7 +200,7 @@ class Text:
                 @return the attributes at offset, as a semicolon-delimited set
                 of colon-delimited name-value pairs.
                 """
-                [attrs, startOffset, endOffset] = Atspi.Text.get_attributes(self.obj, offset)
+                [attrs, startOffset, endOffset] = exwrap(Atspi.Text.get_attributes, self.obj, offset)
                 arr = [key + ':' + value for key, value in attrs.items()]
 		str = ';'.join (arr)
                 return [str, startOffset, endOffset]
@@ -233,7 +233,7 @@ class Text:
                 determines whether text which intersects the bounding box in
                 the y direction is included.
                 """
-                return Atspi.Text.get_bounded_ranges(self.obj, x, y, width, height, coordType, xClipType, yClipType)
+                return exwrap(Atspi.Text.get_bounded_ranges, self.obj, x, y, width, height, coordType, xClipType, yClipType)
 
         def getCharacterAtOffset(self, offset):
                 """
@@ -243,7 +243,7 @@ class Text:
                 UCS-4 representation of the character at the specified text offset,
                 or 0 if offset is out of range.
                 """
-                return Atspi.Text.get_character_offset(self.obj, offset)
+                return exwrap(Atspi.Text.get_character_offset, self.obj, offset)
 
         def getCharacterExtents(self, offset, coordType):
                 """
@@ -264,8 +264,8 @@ class Text:
                 window, with the x axis pointing right and the y axis pointing
                 down.
                 """
-                ret = Atspi.Text.get_character_extents(self.obj, offset, coordType)
-                return utils.rectToList(ret)
+                ret = exwrap(Atspi.Text.get_character_extents, self.obj, offset, coordType)
+                return rectToList(ret)
 
         def getDefaultAttributeSet(self):
                 """
@@ -278,7 +278,7 @@ class Text:
                 whereas an object whose text weight is inspecified may report
                 the default or implied text weight in the default AttributeSet.
                 """
-                ret = Atspi.Text.get_default_attribute_set(self.obj)
+                ret = exwrap(Atspi.Text.get_default_attribute_set, self.obj)
                 return [key + ':' + value for key, value in ret.values()]
 
         def getDefaultAttributes(self):
@@ -287,7 +287,7 @@ class Text:
                 @return the attributes which apply to the entire text content,
                 but which were not explicitly specified by the content creator.
                 """
-                ret = Atspi.Text.get_default_attributes(self.obj)
+                ret = exwrap(Atspi.Text.get_default_attributes, self.obj)
                 return ';'.join([key + ':' + value for key, value in ret.iteritems()])
 
         def getNSelections(self):
@@ -302,7 +302,7 @@ class Text:
                 @return the number of contiguous selections in the current Text
                 object.
                 """
-                return Atspi.Text.get_n_selections(self.obj)
+                return exwrap(Atspi.Text.get_n_selections, self.obj)
 
         def getOffsetAtPoint(self, x, y, coordType):
                 """
@@ -319,7 +319,7 @@ class Text:
                 of the glyph whose onscreen bounds contain the point x,y, or
                 -1 if the point is outside the bounds of any glyph.
                 """
-                return Atspi.Text.get_offset_at_point(self.obj, x, y, UInt32(coordType))
+                return exwrap(Atspi.Text.get_offset_at_point, self.obj, x, y, UInt32(coordType))
 
         def getRangeExtents(self, startOffset, endOffset, coordType):
                 """
@@ -349,8 +349,8 @@ class Text:
                 corner of the screen; if 1, the coordinates are reported relative
                 to the corner of the containing toplevel window.
                 """
-                ret = Atspi.Text.get_range_extents(self.obj, startOffset, endOffset, coordType)
-                return utils.rectToList(ret)
+                ret = exwrap(Atspi.Text.get_range_extents, self.obj, startOffset, endOffset, coordType)
+                return rectToList(ret)
 
         def getSelection(self, selectionNum):
                 """
@@ -366,7 +366,7 @@ class Text:
                 back-filled with the offset of the character immediately following
                 the resulting substring, if one exists. 
                 """
-                ret = Atspi.Text.get_selection(self.obj, selectionNum)
+                ret = exwrap(Atspi.Text.get_selection, self.obj, selectionNum)
                 return rangeToList(ret)
 
         def getText(self, startOffset, endOffset):
@@ -386,7 +386,7 @@ class Text:
                 """
                 if not endOffset:
                         endOffset = -1
-                return Atspi.Text.get_text(self.obj, startOffset, endOffset)
+                return exwrap(Atspi.Text.get_text, self.obj, startOffset, endOffset)
 
         def getTextAfterOffset(self, offset, type):
                 """
@@ -413,7 +413,7 @@ class Text:
                 @return a string which is a substring of the text content of
                 the object, delimited by the specified boundary condition.
                 """
-                ret = Atspi.Text.get_text_after_offset(self.obj, offset, type)
+                ret = exwrap(Atspi.Text.get_text_after_offset, self.obj, offset, type)
                 return textRangeToList(ret)
 
         def getTextAtOffset(self, offset, type):
@@ -440,7 +440,7 @@ class Text:
                 @return a string which is a substring of the text content of
                 the object, delimited by the specified boundary condition.
                 """
-                ret = Atspi.Text.get_text_at_offset(self.obj, offset, type)
+                ret = exwrap(Atspi.Text.get_text_at_offset, self.obj, offset, type)
                 return textRangeToList(ret)
 
         def getTextBeforeOffset(self, offset, type):
@@ -468,7 +468,7 @@ class Text:
                 the object, delimited by the specified boundary condition.
                 """
                 func = self.get_dbus_method("GetTextBeforeOffset", dbus_interface=ATSPI_TEXT)
-                ret = Atspi.Text.get_text_before_offset(self.obj, offset, type)
+                ret = exwrap(Atspi.Text.get_text_before_offset, self.obj, offset, type)
                 return textRangeToList(ret)
 
         def removeSelection(self, selectionNum):
@@ -481,7 +481,7 @@ class Text:
                 @return True if the selection was successfully removed, False
                 otherwise.
                 """
-                return Atspi.Text.remove_selection(self.obj, index)
+                return exwrap(Atspi.Text.remove_selection, self.obj, index)
 
         def setCaretOffset(self, offset):
                 """
@@ -494,7 +494,7 @@ class Text:
                 @return TRUE if the request was carried out, or FALSE if the
                 caret could not be moved to the requested position.
                 """
-                return Atspi.Text.set_caret_offset(self.obj, offset)
+                return exwrap(Atspi.Text.set_caret_offset, self.obj, offset)
 
         def setSelection(self, selectionNum, startOffset, endOffset):
                 """
@@ -512,10 +512,10 @@ class Text:
                 @return True if the selection corresponding to selectionNum is
                 successfully modified, False otherwise.
                 """
-                return Atspi.Text.set_selection(self.obj, selectionNum, startOffset, endOffset)
+                return exwrap(Atspi.Text.set_selection, self.obj, selectionNum, startOffset, endOffset)
 
         def get_caretOffset(self):
-                return Atspi.Text.get_caret_offset(self.obj)
+                return exwrap(Atspi.Text.get_caret_offset, self.obj)
         _caretOffsetDoc = \
                 """
                 The current offset of the text caret in the Text object. This
@@ -528,7 +528,7 @@ class Text:
         caretOffset = property(fget=get_caretOffset, doc=_caretOffsetDoc)
 
         def get_characterCount(self):
-                return Atspi.Text.get_character_count(self.obj)
+                return exwrap(Atspi.Text.get_character_count, self.obj)
         _characterCountDoc = \
                 """
                 The total current number of characters in the Text object, including
diff --git a/pyatspi/utils.py b/pyatspi/utils.py
index f53908b..59fa75a 100644
--- a/pyatspi/utils.py
+++ b/pyatspi/utils.py
@@ -42,6 +42,8 @@ __all__ = [
                 "findAllDescendants",
                 "findAncestor",
                 "getPath",
+                "rectToList",
+                "exwrap"
          ]
 
 def setCacheLevel(level):
@@ -329,3 +331,9 @@ def pointToList(point):
 
 def rectToList(rect):
 	return (rect.x, rect.y, rect.width, rect.height)
+
+def exwrap(func, *args):
+	try:
+		return func(*args)
+        except RuntimeError:
+                raise LookupError



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]