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

Side by Side Diff: third_party/google-endpoints/cachetools/keys.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 __all__ = ('hashkey', 'typedkey')
2
3
4 class _HashedTuple(tuple):
5
6 __hashvalue = None
7
8 def __hash__(self, hash=tuple.__hash__):
9 hashvalue = self.__hashvalue
10 if hashvalue is None:
11 self.__hashvalue = hashvalue = hash(self)
12 return hashvalue
13
14 def __add__(self, other, add=tuple.__add__):
15 return _HashedTuple(add(self, other))
16
17 def __radd__(self, other, add=tuple.__add__):
18 return _HashedTuple(add(other, self))
19
20 _kwmark = (object(),)
21
22
23 def hashkey(*args, **kwargs):
24 """Return a cache key for the specified hashable arguments."""
25
26 if kwargs:
27 return _HashedTuple(args + sum(sorted(kwargs.items()), _kwmark))
28 else:
29 return _HashedTuple(args)
30
31
32 def typedkey(*args, **kwargs):
33 """Return a typed cache key for the specified hashable arguments."""
34
35 key = hashkey(*args, **kwargs)
36 key += tuple(type(v) for v in args)
37 key += tuple(type(v) for _, v in sorted(kwargs.items()))
38 return key
OLDNEW
« no previous file with comments | « third_party/google-endpoints/cachetools/func.py ('k') | third_party/google-endpoints/cachetools/lfu.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698