Exemple #1
0
    def printTraceback(self,
                       file=None,
                       elideFrameworkCode=False,
                       detail='default'):
        """
		Emulate Python's standard error reporting mechanism.

		@param file: If specified, a file-like object to which to write the
			traceback.

		@param elideFrameworkCode: A flag indicating whether to attempt to
			remove uninteresting frames from within Twisted itself from the
			output.

		@param detail: A string indicating how much information to include
			in the traceback.  Must be one of C{'brief'}, C{'default'}, or
			C{'verbose'}.
		"""
        if file is None:
            file = log.logerr
        w = file.write

        # Preamble
        if detail == 'verbose':
            w('*--- Failure #%d%s---\n' %
              (self.count, (self.pickled and ' (pickled) ') or ' '))
        elif detail == 'brief':
            if self.frames:
                hasFrames = 'Traceback'
            else:
                hasFrames = 'Traceback (failure with no frames)'
            w("%s: %s: %s\n" % (hasFrames, reflect.safe_str(
                self.type), reflect.safe_str(self.value)))
        else:
            w('Traceback (most recent call last):\n')

        # Frames, formatted in appropriate style
        if self.frames:
            if not elideFrameworkCode:
                format_frames(self.stack[-traceupLength:], w, detail)
                w("%s\n" % (EXCEPTION_CAUGHT_HERE, ))
            format_frames(self.frames, w, detail)
        elif not detail == 'brief':
            # Yeah, it's not really a traceback, despite looking like one...
            w("Failure: ")

        # postamble, if any
        if not detail == 'brief':
            # Unfortunately, self.type will not be a class object if this
            # Failure was created implicitly from a string exception.
            # qual() doesn't make any sense on a string, so check for this
            # case here and just write out the string if that's what we
            # have.
            if isinstance(self.type, (str, unicode)):
                w(self.type + "\n")
            else:
                w("%s: %s\n" %
                  (reflect.qual(self.type), reflect.safe_str(self.value)))
        # chaining
        if isinstance(self.value, Failure):
            # TODO: indentation for chained failures?
            file.write(" (chained Failure)\n")
            self.value.printTraceback(file, elideFrameworkCode, detail)
        if detail == 'verbose':
            w('*--- End of Failure #%d ---\n' % self.count)
Exemple #2
0
	def printTraceback(self, file=None, elideFrameworkCode=False, detail='default'):
		"""
		Emulate Python's standard error reporting mechanism.

		@param file: If specified, a file-like object to which to write the
			traceback.

		@param elideFrameworkCode: A flag indicating whether to attempt to
			remove uninteresting frames from within Twisted itself from the
			output.

		@param detail: A string indicating how much information to include
			in the traceback.  Must be one of C{'brief'}, C{'default'}, or
			C{'verbose'}.
		"""
		if file is None:
			file = log.logerr
		w = file.write

		# Preamble
		if detail == 'verbose':
			w( '*--- Failure #%d%s---\n' %
			   (self.count,
				(self.pickled and ' (pickled) ') or ' '))
		elif detail == 'brief':
			if self.frames:
				hasFrames = 'Traceback'
			else:
				hasFrames = 'Traceback (failure with no frames)'
			w("%s: %s: %s\n" % (
					hasFrames,
					reflect.safe_str(self.type),
					reflect.safe_str(self.value)))
		else:
			w( 'Traceback (most recent call last):\n')

		# Frames, formatted in appropriate style
		if self.frames:
			if not elideFrameworkCode:
				format_frames(self.stack[-traceupLength:], w, detail)
				w("%s\n" % (EXCEPTION_CAUGHT_HERE,))
			format_frames(self.frames, w, detail)
		elif not detail == 'brief':
			# Yeah, it's not really a traceback, despite looking like one...
			w("Failure: ")

		# postamble, if any
		if not detail == 'brief':
			# Unfortunately, self.type will not be a class object if this
			# Failure was created implicitly from a string exception.
			# qual() doesn't make any sense on a string, so check for this
			# case here and just write out the string if that's what we
			# have.
			if isinstance(self.type, (str, unicode)):
				w(self.type + "\n")
			else:
				w("%s: %s\n" % (reflect.qual(self.type),
								reflect.safe_str(self.value)))
		# chaining
		if isinstance(self.value, Failure):
			# TODO: indentation for chained failures?
			file.write(" (chained Failure)\n")
			self.value.printTraceback(file, elideFrameworkCode, detail)
		if detail == 'verbose':
			w('*--- End of Failure #%d ---\n' % self.count)
Exemple #3
0
 def getErrorMessage(self):
     """Get a string of the exception which caused this Failure."""
     if isinstance(self.value, Failure):
         return self.value.getErrorMessage()
     return reflect.safe_str(self.value)
Exemple #4
0
	def getErrorMessage(self):
		"""Get a string of the exception which caused this Failure."""
		if isinstance(self.value, Failure):
			return self.value.getErrorMessage()
		return reflect.safe_str(self.value)