view pinlib/pinlib.py @ 82:d7d67887102f

move pinlib to a shared location and have pics use it
author paulo
date Wed, 29 Jun 2016 00:11:55 -0700
parents laterlinks2/pinlib.py@f833a888c548
children d521df55f56c
line source
1 import urlparse
4 def parse_cookies(environ):
5 return urlparse.parse_qs(environ.get("HTTP_COOKIE", ""))
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