1 # -*- test-case-name: buildbot.test.test_util -*-
3 from twisted
.internet
.defer
import Deferred
4 from twisted
.spread
import pb
8 #return int(time.time())
11 def earlier(old
, new
):
12 # minimum of two things, but "None" counts as +infinity
20 # maximum of two things, but "None" counts as -infinity
27 class CancelableDeferred(Deferred
):
28 """I am a version of Deferred that can be canceled by calling my
29 .cancel() method. After being canceled, no callbacks or errbacks will be
33 Deferred
.__init
__(self
)
37 def _runCallbacks(self
):
41 Deferred
._runCallbacks
(self
)
43 def ignoreStaleRefs(failure
):
44 """d.addErrback(util.ignoreStaleRefs)"""
45 r
= failure
.trap(pb
.DeadReferenceError
, pb
.PBConnectionLost
)
51 class ComparableMixin
:
52 """Specify a list of attributes that are 'important'. These will be used
53 for all comparison operations."""
58 alist
= [self
.__class
__] + \
59 [getattr(self
, name
, _None
) for name
in self
.compare_attrs
]
60 return hash(tuple(alist
))
62 def __cmp__(self
, them
):
63 if cmp(type(self
), type(them
)):
64 return cmp(type(self
), type(them
))
65 if cmp(self
.__class
__, them
.__class
__):
66 return cmp(self
.__class
__, them
.__class
__)
67 assert self
.compare_attrs
== them
.compare_attrs
68 self_list
= [getattr(self
, name
, _None
) for name
in self
.compare_attrs
]
69 them_list
= [getattr(them
, name
, _None
) for name
in self
.compare_attrs
]
70 return cmp(self_list
, them_list
)