exceptions.py 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. """Exception classes used by Pexpect"""
  2. import traceback
  3. import sys
  4. class ExceptionPexpect(Exception):
  5. '''Base class for all exceptions raised by this module.
  6. '''
  7. def __init__(self, value):
  8. super(ExceptionPexpect, self).__init__(value)
  9. self.value = value
  10. def __str__(self):
  11. return str(self.value)
  12. def get_trace(self):
  13. '''This returns an abbreviated stack trace with lines that only concern
  14. the caller. In other words, the stack trace inside the Pexpect module
  15. is not included. '''
  16. tblist = traceback.extract_tb(sys.exc_info()[2])
  17. tblist = [item for item in tblist if ('pexpect/__init__' not in item[0])
  18. and ('pexpect/expect' not in item[0])]
  19. tblist = traceback.format_list(tblist)
  20. return ''.join(tblist)
  21. class EOF(ExceptionPexpect):
  22. '''Raised when EOF is read from a child.
  23. This usually means the child has exited.'''
  24. class TIMEOUT(ExceptionPexpect):
  25. '''Raised when a read time exceeds the timeout. '''