Mercurial > hg > index.fcgi > www > www-1
view pinlib/pinlib.py @ 144:90f3021e3137
myrss2: FEEDS: Remove longform.org; add propublic.org
author | paulo |
---|---|
date | Tue, 28 May 2024 06:23:58 +0000 |
parents | d7d67887102f |
children |
line source
1 import urlparse
4 def parse_cookies(environ):
5 return urlparse.parse_qs(environ.get("HTTP_COOKIE", "").replace("; ", "&"))
8 class PinFailError(Exception):
9 pass
12 class PinMan(object):
13 def __init__(self, key):
14 assert key
15 self._key = key
16 self._fn = "_%s" % key
18 def load(self):
19 ret = None
21 try:
22 with open(self._fn) as pin_f:
23 ret = pin_f.read().strip()
24 except IOError:
25 pass
27 return ret
29 def check(self, cookies):
30 if self._key not in cookies:
31 raise PinFailError()
33 pin = cookies[self._key][0]
34 if pin != self.load():
35 raise PinFailError()
37 return pin