Exemple #1
0
 def write(self, data):
     """write data to some file like object only writes happen if debug was
        specified during instantiation.
     """
     if hasattr(self.fd, 'write') and hasattr(self.fd.write, '__call__') \
             and self.debug: #only write on debug true
         try:
             self.fd.write(str(data)+'\n')
         except:
             failure = Failure()
             if self.verbose: failure.printDetailedTraceback(sys.stderr)
             else: failure.printTraceback(sys.stderr)
Exemple #2
0
 def write(self, data):
     """write data to some file like object only writes happen if debug was
        specified during instantiation.
     """
     if hasattr(self.fd, 'write') and hasattr(self.fd.write, '__call__') \
             and self.debug: #only write on debug true
         try:
             self.fd.write(str(data) + '\n')
         except:
             failure = Failure()
             if self.verbose: failure.printDetailedTraceback(sys.stderr)
             else: failure.printTraceback(sys.stderr)
Exemple #3
0
    def display_result(self, result):
        """display the result in debug mode, always display tracebacks
           on failure. this is callback safe. 

           @param result (object)
           @return (param -> result)
        """
        if isinstance(result, Failure):
            if hasattr(result.value, "__class__"):
                eName = result.value.__class__.__name__
            else:  # guess in event failure doesn't make sense
                try:  # preload and reset later
                    eName = sys.exc_info()[0].__name__
                except AttributeError:
                    eName = "Unknown"  # fail
                except:
                    failure = Failure()
                    self.write("Something bad has happened")
                    fd = self.fd
                    if not fd:
                        self.fd = sys.stderr
                    if self.verbose:
                        failure.printDetailedTraceback(self.fd)
                    else:
                        failure.printTraceback(self.fd)
                    # restore the previous fd object
                    self.fd = fd
                    return result
            self.write(">>> %s call raised %s" % (self.function.func_name, eName))
            # make sure the fd is valid for tracebacks
            fd = self.fd
            if not fd:
                self.fd = sys.stderr
            if self.verbose:
                result.printDetailedTraceback(self.fd)
            else:
                result.printTraceback(self.fd)
            # restore the previous fd object
            self.fd = fd
            self.write(">>>")
        else:
            self.write(">>> Returning %s -> %s" % (self.function.func_name, str(result)))
        return result
Exemple #4
0
    def display_result(self, result):
        """display the result in debug mode, always display tracebacks
           on failure. this is callback safe. 

           @param result (object)
           @return (param -> result)
        """
        if isinstance(result, Failure):
            if hasattr(result.value, '__class__'):
                eName = result.value.__class__.__name__
            else:  #guess in event failure doesn't make sense
                try:  #preload and reset later
                    eName = sys.exc_info()[0].__name__
                except AttributeError:
                    eName = 'Unknown'  #fail
                except:
                    failure = Failure()
                    self.write('Something bad has happened')
                    fd = self.fd
                    if not fd: self.fd = sys.stderr
                    if self.verbose: failure.printDetailedTraceback(self.fd)
                    else: failure.printTraceback(self.fd)
                    #restore the previous fd object
                    self.fd = fd
                    return result
            self.write(">>> %s call raised %s" % \
                    (self.function.func_name, eName))
            #make sure the fd is valid for tracebacks
            fd = self.fd
            if not fd: self.fd = sys.stderr
            if self.verbose: result.printDetailedTraceback(self.fd)
            else: result.printTraceback(self.fd)
            #restore the previous fd object
            self.fd = fd
            self.write(">>>")
        else:
            self.write(">>> Returning %s -> %s" % \
                    (self.function.func_name,str(result)))
        return result