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

Side by Side Diff: client/third_party/cachetools/keys.py

Issue 2953253003: Replace custom blob gRPC API with ByteStream (Closed)
Patch Set: Import ndb directly to test code Created 3 years, 5 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
« no previous file with comments | « client/third_party/cachetools/func.py ('k') | client/third_party/cachetools/lfu.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 """Key functions for memoizing decorators."""
2
3 from __future__ import absolute_import
4
5 __all__ = ('hashkey', 'typedkey')
6
7
8 class _HashedTuple(tuple):
9
10 __hashvalue = None
11
12 def __hash__(self, hash=tuple.__hash__):
13 hashvalue = self.__hashvalue
14 if hashvalue is None:
15 self.__hashvalue = hashvalue = hash(self)
16 return hashvalue
17
18 def __add__(self, other, add=tuple.__add__):
19 return _HashedTuple(add(self, other))
20
21 def __radd__(self, other, add=tuple.__add__):
22 return _HashedTuple(add(other, self))
23
24 _kwmark = (object(),)
25
26
27 def hashkey(*args, **kwargs):
28 """Return a cache key for the specified hashable arguments."""
29
30 if kwargs:
31 return _HashedTuple(args + sum(sorted(kwargs.items()), _kwmark))
32 else:
33 return _HashedTuple(args)
34
35
36 def typedkey(*args, **kwargs):
37 """Return a typed cache key for the specified hashable arguments."""
38
39 key = hashkey(*args, **kwargs)
40 key += tuple(type(v) for v in args)
41 key += tuple(type(v) for _, v in sorted(kwargs.items()))
42 return key
OLDNEW
« no previous file with comments | « client/third_party/cachetools/func.py ('k') | client/third_party/cachetools/lfu.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698