def __str__(self): if self._str is not None: return self._str if hasattr(self, 'func'): if hasattr(self.func, 'func_name'): func = self.func.func_name if hasattr(self.func, 'im_class'): func = self.func.im_class.__name__ + '.' + func else: func = reflect.safe_repr(self.func) else: func = None now = self.seconds() L = ["<DelayedCall 0x%x [%ss] called=%s cancelled=%s" % ( unsignedID(self), self.time - now, self.called, self.cancelled)] if func is not None: L.extend((" ", func, "(")) if self.args: L.append(", ".join([reflect.safe_repr(e) for e in self.args])) if self.kw: L.append(", ") if self.kw: L.append(", ".join(['%s=%s' % (k, reflect.safe_repr(v)) for (k, v) in self.kw.iteritems()])) L.append(")") if self.debug: L.append("\n\ntraceback at creation: \n\n%s" % (' '.join(self.creator))) L.append('>') return "".join(L)
def _determineClassName(x): c = _determineClass(x) try: return c.__name__ except: try: return str(c) except: return '<BROKEN CLASS AT 0x%x>' % unsignedID(c)
def test_unsignedID(self): """ L{util.unsignedID} uses the function passed to L{util.setIDFunction} to determine the unique integer id of an object and then adjusts it to be positive if necessary. """ foo = object() bar = object() # A fake object identity mapping objects = {foo: 17, bar: -73} def fakeId(obj): return objects[obj] util.setIDFunction(fakeId) self.assertEquals(util.unsignedID(foo), 17) self.assertEquals(util.unsignedID(bar), (sys.maxint + 1) * 2 - 73)
def _determineClassName(x): c = _determineClass(x) try: return c.__name__ except: try: return str(c) except: return '<BROKEN CLASS AT 0x%x>' % unsignedID(c)
def test_defaultIDFunction(self): """ L{util.unsignedID} uses the built in L{id} by default. """ obj = object() idValue = id(obj) if idValue < 0: idValue += (sys.maxint + 1) * 2 self.assertEquals(util.unsignedID(obj), idValue)
def test_unsignedID(self): """ L{util.unsignedID} uses the function passed to L{util.setIDFunction} to determine the unique integer id of an object and then adjusts it to be positive if necessary. """ foo = object() bar = object() # A fake object identity mapping objects = {foo: 17, bar: -73} def fakeId(obj): return objects[obj] util.setIDFunction(fakeId) self.assertEquals(util.unsignedID(foo), 17) self.assertEquals(util.unsignedID(bar), (sys.maxint + 1) * 2 - 73)
def test_defaultIDFunction(self): """ L{util.unsignedID} uses the built in L{id} by default. """ obj = object() idValue = id(obj) if idValue < 0: idValue += (sys.maxint + 1) * 2 self.assertEquals(util.unsignedID(obj), idValue)
def _safeFormat(formatter, o): """ Helper function for L{safe_repr} and L{safe_str}. """ try: return formatter(o) except: io = StringIO() traceback.print_exc(file=io) className = _determineClassName(o) tbValue = io.getvalue() return "<%s instance at 0x%x with %s error:\n %s>" % ( className, unsignedID(o), formatter.__name__, tbValue)
def _safeFormat(formatter, o): """ Helper function for L{safe_repr} and L{safe_str}. """ try: return formatter(o) except: io = StringIO() traceback.print_exc(file=io) className = _determineClassName(o) tbValue = io.getvalue() return "<%s instance at 0x%x with %s error:\n %s>" % ( className, unsignedID(o), formatter.__name__, tbValue)
def __str__(self): if self._str is not None: return self._str if hasattr(self, 'func'): if hasattr(self.func, 'func_name'): func = self.func.func_name if hasattr(self.func, 'im_class'): func = self.func.im_class.__name__ + '.' + func else: func = reflect.safe_repr(self.func) else: func = None now = self.seconds() L = [ "<DelayedCall 0x%x [%ss] called=%s cancelled=%s" % (unsignedID(self), self.time - now, self.called, self.cancelled) ] if func is not None: L.extend((" ", func, "(")) if self.args: L.append(", ".join([reflect.safe_repr(e) for e in self.args])) if self.kw: L.append(", ") if self.kw: L.append(", ".join([ '%s=%s' % (k, reflect.safe_repr(v)) for (k, v) in self.kw.iteritems() ])) L.append(")") if self.debug: L.append("\n\ntraceback at creation: \n\n%s" % (' '.join(self.creator))) L.append('>') return "".join(L)
def __repr__(self): s = '<%s to %s at %x>' % (self.__class__, self.addr, unsignedID(self)) return s
def __str__(self): cname = self.__class__.__name__ if hasattr(self, 'result'): return "<%s at %s current result: %r>" % ( cname, hex(unsignedID(self)), self.result) return "<%s at %s>" % (cname, hex(unsignedID(self)))
def __str__(self): cname = self.__class__.__name__ if hasattr(self, 'result'): return "<%s at %s current result: %r>" % (cname, hex(unsignedID(self)), self.result) return "<%s at %s>" % (cname, hex(unsignedID(self)))
def __repr__(self): s = '<%s to %s at %x>' % (self.__class__, self.addr, unsignedID(self)) return s