-
Notifications
You must be signed in to change notification settings - Fork 0
/
unit4.py
26 lines (22 loc) · 1.03 KB
/
unit4.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# custom imports
from handlers import Validators, Handler, Hashers
import hashlib
###################################################################################################
# Unit 4
###################################################################################################
class CookieHandler(Handler, Validators, Hashers):
def get(self):
self.response.headers['Content-Type'] = 'text/plain'
visits = 0
visits_cookie_str = self.request.cookies.get('visits')
if visits_cookie_str:
cookie_val = self.check_hash_str(visits_cookie_str, hashlib.md5 )
if cookie_val:
visits = int(cookie_val)
visits += 1
new_cookie_val = self.hash_str( str(visits), hashlib.md5 )
self.response.headers.add_header( 'Set-Cookie','visits=%s' % new_cookie_val )
if visits > 10:
self.write("You are the best ever!")
else:
self.write("You've been here %s times!" % str(visits) )