celery.utils.functional
celery.utils.functional
Utilities for functions.
class celery.utils.functional.LRUCache(limit=None)[源代码]
LRU Cache implementation using a doubly linked list to track access.
参数: | limit – The maximum number of keys to keep in the cache. When a new key is inserted and the limit has been exceeded, the Least Recently Used key will be discarded from the cache. |
---|
incr(key, delta=1)[源代码]
items()[源代码]
iteritems()
iterkeys()
itervalues()
keys()[源代码]
update(\args, **kwargs*)
values()[源代码]
celery.utils.functional.is_list(l, scalars=(<class ‘_abcoll.Mapping’>, <type ‘basestring’>), iters=(<class ‘_abcoll.Iterable’>, ))[源代码]
Return true if the object is iterable (but not if object is a mapping or string).
celery.utils.functional.maybe_list(l, scalars=(<class ‘_abcoll.Mapping’>, <type ‘basestring’>))[源代码]
Return list of one element if l is a scalar.
celery.utils.functional.memoize(maxsize=None, Cache=<class celery.utils.functional.LRUCache at 0xaf68c8c>)[源代码]
class celery.utils.functional.mlazy(fun, \args, **kwargs*)
Memoized lazy evaluation.
The function is only evaluated once, every subsequent access will return the same value.
evaluated
Set to to True after the object has been evaluated.
evaluate()
evaluated = False
celery.utils.functional.noop(\args, **kwargs*)[源代码]
No operation.
Takes any arguments/keyword arguments and does nothing.
celery.utils.functional.first(predicate, it)[源代码]
Return the first element in iterable that predicate Gives a True value for.
If predicate is None it will return the first item that is not None.
celery.utils.functional.firstmethod(method)[源代码]
Return a function that with a list of instances, finds the first instance that gives a value for the given method.
The list can also contain lazy instances (lazy.)
celery.utils.functional.chunks(it, n)[源代码]
Split an iterator into chunks with n elements each.
Examples
# n == 2 >>> x = chunks(iter([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), 2) >>> list(x) [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9], [10]]
# n == 3 >>> x = chunks(iter([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), 3) >>> list(x) [[0, 1, 2], [3, 4, 5], [6, 7, 8], [9, 10]]
celery.utils.functional.padlist(container, size, default=None)[源代码]
Pad list with default elements.
Examples:
>>> first, last, city = padlist(['George', 'Costanza', 'NYC'], 3)
('George', 'Costanza', 'NYC')
>>> first, last, city = padlist(['George', 'Costanza'], 3)
('George', 'Costanza', None)
>>> first, last, city, planet = padlist(
... ['George', 'Costanza', 'NYC'], 4, default='Earth',
... )
('George', 'Costanza', 'NYC', 'Earth')
celery.utils.functional.mattrgetter(\attrs*)[源代码]
Like operator.itemgetter() but return None on missing attributes instead of raising AttributeError.
celery.utils.functional.uniq(it)[源代码]
Return all unique elements in it, preserving order.
celery.utils.functional.regen(it)[源代码]
Regen takes any iterable, and if the object is an generator it will cache the evaluated list on first access, so that the generator can be “consumed” multiple times.
celery.utils.functional.dictfilter(d=None, \*kw*)
Remove all keys from dict d whose value is None
class celery.utils.functional.lazy(fun, \args, **kwargs*)
Holds lazy evaluation.
Evaluated when called or if the evaluate() method is called. The function is re-evaluated on every call.
Overloaded operations that will evaluate the promise:
__str__(), __repr__(), __cmp__().
evaluate()
celery.utils.functional.maybe_evaluate(value)
Evaluates if the value is a lazy instance.