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