1 """A simple store using only in-process memory."""
2
3 from openid.store import nonce
4
5 import copy
6 import time
7
11
12 - def set(self, assoc):
14
15 - def get(self, handle):
17
19 try:
20 del self.assocs[handle]
21 except KeyError:
22 return False
23 else:
24 return True
25
27 """Returns association with the oldest issued date.
28
29 or None if there are no associations.
30 """
31 best = None
32 for assoc in self.assocs.values():
33 if best is None or best.issued < assoc.issued:
34 best = assoc
35 return best
36
49
50
51
53 """In-process memory store.
54
55 Use for single long-running processes. No persistence supplied.
56 """
58 self.server_assocs = {}
59 self.nonces = {}
60
67
71
78
82
83 - def useNonce(self, server_url, timestamp, salt):
84 if abs(timestamp - time.time()) > nonce.SKEW:
85 return False
86
87 anonce = (str(server_url), int(timestamp), str(salt))
88 if anonce in self.nonces:
89 return False
90 else:
91 self.nonces[anonce] = None
92 return True
93
95 now = time.time()
96 expired = []
97 for anonce in self.nonces.iterkeys():
98 if abs(anonce[1] - now) > nonce.SKEW:
99
100 expired.append(anonce)
101
102 for anonce in expired:
103 del self.nonces[anonce]
104 return len(expired)
105
107 remove_urls = []
108 removed_assocs = 0
109 for server_url, assocs in self.server_assocs.iteritems():
110 removed, remaining = assocs.cleanup()
111 removed_assocs += removed
112 if not remaining:
113 remove_urls.append(server_url)
114
115
116 for server_url in remove_urls:
117 del self.server_assocs[server_url]
118 return removed_assocs
119
121 return ((self.server_assocs == other.server_assocs) and
122 (self.nonces == other.nonces))
123
125 return not (self == other)
126