/usr/lib/python2.7/dist-packages/cachetools/rr.py is in python-cachetools 1.1.5-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 | import random
from .cache import Cache
class RRCache(Cache):
"""Random Replacement (RR) cache implementation."""
def __init__(self, maxsize, choice=random.choice, missing=None,
getsizeof=None):
Cache.__init__(self, maxsize, missing, getsizeof)
self.__choice = choice
def popitem(self):
"""Remove and return a random `(key, value)` pair."""
try:
key = self.__choice(list(self))
except IndexError:
raise KeyError('cache is empty')
return (key, self.pop(key))
@property
def choice(self):
"""The `choice` function used by the cache."""
return self.__choice
|