Mercurial > hg > index.fcgi > www > www-1
view pinlib/pinlib.py @ 123:b2aebd4994ea
myrss2: update FEEDS again to remove The Browser
author | paulo |
---|---|
date | Thu, 25 Mar 2021 00:23:17 -0700 |
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