Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(211)

Side by Side Diff: third_party/google-endpoints/cachetools/rr.py

Issue 2666783008: Add google-endpoints to third_party/. (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 import random
2
3 from .cache import Cache
4
5
6 class RRCache(Cache):
7 """Random Replacement (RR) cache implementation."""
8
9 def __init__(self, maxsize, choice=random.choice, missing=None,
10 getsizeof=None):
11 Cache.__init__(self, maxsize, missing, getsizeof)
12 self.__choice = choice
13
14 @property
15 def choice(self):
16 """The `choice` function used by the cache."""
17 return self.__choice
18
19 def popitem(self):
20 """Remove and return a random `(key, value)` pair."""
21 try:
22 key = self.__choice(list(self))
23 except IndexError:
24 raise KeyError('%s is empty' % self.__class__.__name__)
25 else:
26 return (key, self.pop(key))
OLDNEW
« no previous file with comments | « third_party/google-endpoints/cachetools/lru.py ('k') | third_party/google-endpoints/cachetools/ttl.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698