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