home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.6)
-
- '''Provides debug utilities for Orca. Debugging is managed by a debug
- level, which is held in the debugLevel field. All other methods take
- a debug level, which is compared to the current debug level to
- determine if the content should be output.'''
- __id__ = '$Id: debug.py 3882 2008-05-07 18:22:10Z richb $'
- __version__ = '$Revision: 3882 $'
- __date__ = '$Date: 2008-05-07 14:22:10 -0400 (Wed, 07 May 2008) $'
- __copyright__ = 'Copyright (c) 2005-2008 Sun Microsystems Inc.'
- __license__ = 'LGPL'
- import traceback
- import pyatspi
- LEVEL_OFF = 10000
- LEVEL_SEVERE = 1000
- LEVEL_WARNING = 900
- LEVEL_INFO = 800
- LEVEL_CONFIGURATION = 700
- LEVEL_FINE = 600
- LEVEL_FINER = 500
- LEVEL_FINEST = 400
- LEVEL_ALL = 0
- debugLevel = LEVEL_SEVERE
- debugFile = None
- eventDebugLevel = LEVEL_FINEST
- eventDebugFilter = None
-
- def printException(level):
- '''Prints out information regarding the current exception.
-
- Arguments:
- - level: the accepted debug level
- '''
- if level >= debugLevel:
- println(level)
- traceback.print_exc(100, debugFile)
- println(level)
-
-
-
- def printStack(level):
- '''Prints out the current stack.
-
- Arguments:
- - level: the accepted debug level
- '''
- if level >= debugLevel:
- println(level)
- traceback.print_stack(None, 100, debugFile)
- println(level)
-
-
-
- def println(level, text = ''):
- '''Prints the text to stdout if debug is enabled.
-
- Arguments:
- - level: the accepted debug level
- - text: the text to print (default is a blank line)
- '''
- if level >= debugLevel:
- if debugFile:
- debugFile.writelines([
- text,
- '\n'])
- else:
- print text
-
-
-
- def printObjectEvent(level, event, sourceInfo = None):
- '''Prints out an Python Event object. The given level may be
- overridden if the eventDebugLevel is greater. Furthermore, only
- events with event types matching the eventDebugFilter regular
- expression will be printed.
-
- Arguments:
- - level: the accepted debug level
- - event: the Python Event to print
- - sourceInfo: additional string to print out
- '''
- if eventDebugFilter and not eventDebugFilter.match(event.type):
- return None
- level = max(level, eventDebugLevel)
- text = 'OBJECT EVENT: %-40s detail=(%d,%d)' % (event.type, event.detail1, event.detail2)
- println(level, text)
- if sourceInfo:
- println(level, ' %s' % sourceInfo)
-
-
-
- def printInputEvent(level, string):
- '''Prints out an input event. The given level may be overridden
- if the eventDebugLevel (see setEventDebugLevel) is greater.
-
- Arguments:
- - level: the accepted debug level
- - string: the string representing the input event
- '''
- println(max(level, eventDebugLevel), string)
-
-
- def printDetails(level, indent, accessible, includeApp = True):
- '''Lists the details of the given accessible with the given
- indentation.
-
- Arguments:
- - level: the accepted debug level
- - indent: a string containing spaces for indentation
- - accessible: the accessible whose details are to be listed
- - includeApp: if True, include information about the app
- '''
- if level >= debugLevel and accessible:
- println(level, getAccessibleDetails(accessible, indent, includeApp))
-
-
-
- def getAccessibleDetails(acc, indent = '', includeApp = True):
- '''Returns a string, suitable for printing, that describes the
- given accessible.
-
- Arguments:
- - indent: A string to prefix the output with
- - includeApp: If True, include information about the app
- for this accessible.
- '''
- if includeApp:
- app = acc.getApplication()
- if app:
- string = indent + "app.name='%s' " % app.name
- else:
- string = indent + 'app=None '
- else:
- string = indent
- stateSet = acc.getState()
- states = stateSet.getStates()
- state_strings = []
- for state in states:
- state_strings.append(pyatspi.stateToString(state))
-
- state_string = ' '.join(state_strings)
- relations = acc.getRelationSet()
- if relations:
- relation_strings = []
- for relation in relations:
- relation_strings.append(pyatspi.relationToString(relation.getRelationType()))
-
- rel_string = ' '.join(relation_strings)
- else:
- rel_string = ''
- if not acc.name:
- pass
- string += "name='%s' role='%s' state='%s' relations='%s'" % ('None', acc.getRoleName(), state_string, rel_string)
- return string
-
- import linecache
-
- def traceit(frame, event, arg):
- """Line tracing utility to output all lines as they are executed by
- the interpreter. This is to be used by sys.settrace and is for
- debugging purposes.
-
- Arguments:
- - frame: is the current stack frame
- - event: 'call', 'line', 'return', 'exception', 'c_call', 'c_return',
- or 'c_exception'
- - arg: depends on the event type (see docs for sys.settrace)
- """
- if event == 'line':
- lineno = frame.f_lineno
- filename = frame.f_globals['__file__']
- if filename.endswith('.pyc') or filename.endswith('.pyo'):
- filename = filename[:-1]
-
- name = frame.f_globals['__name__']
- if name == 'gettext' and name == 'locale' and name == 'posixpath' or name == 'UserDict':
- return traceit
- line = linecache.getline(filename, lineno)
- println(LEVEL_ALL, 'TRACE %s:%s: %s' % (name, lineno, line.rstrip()))
-
- return traceit
-
-