view laterlinks2/pinlib.py @ 80:ff0878207f0e

add deer_crash/
author paulo
date Fri, 03 Jun 2016 22:25:08 -0700
parents
children
line source
1 import urlparse
4 PIN_KEY = "llpin"
5 PIN_FN = "_%s" % PIN_KEY
8 class PinFailError(Exception):
9 pass
12 def load():
13 ret = None
15 try:
16 with open(PIN_FN) as pin_f:
17 ret = pin_f.read().strip()
18 except IOError:
19 pass
21 return ret
24 def parse_cookies(environ):
25 return urlparse.parse_qs(environ.get("HTTP_COOKIE", ""))
28 def check(cookies):
29 if PIN_KEY not in cookies:
30 raise PinFailError()
32 pin = cookies[PIN_KEY][0]
33 if pin != load():
34 raise PinFailError()
36 return pin