/usr/share/pyshared/kombu/utils/functional.py is in python-kombu 2.1.8-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | class promise(object):
"""A promise.
Evaluated when called or if the :meth:`evaluate` method is called.
The function is evaluated on every access, so the value is not
memoized (see :class:`mpromise`).
Overloaded operations that will evaluate the promise:
:meth:`__str__`, :meth:`__repr__`, :meth:`__cmp__`.
"""
def __init__(self, fun, *args, **kwargs):
self._fun = fun
self._args = args
self._kwargs = kwargs
def __call__(self):
return self.evaluate()
def evaluate(self):
return self._fun(*self._args, **self._kwargs)
def __str__(self):
return str(self())
def __repr__(self):
return repr(self())
def __cmp__(self, rhs):
if isinstance(rhs, self.__class__):
return -cmp(rhs, self())
return cmp(self(), rhs)
def __eq__(self, rhs):
return self() == rhs
def __deepcopy__(self, memo):
memo[id(self)] = self
return self
def __reduce__(self):
return (self.__class__, (self._fun, ), {"_args": self._args,
"_kwargs": self._kwargs})
def maybe_promise(value):
"""Evaluates if the value is a promise."""
if isinstance(value, promise):
return value.evaluate()
return value
|