<s> import sys ; sys . path . insert ( <NUM_LIT:0> , '<STR_LIT>' ) <EOL> from pycnic . core import WSGI , Handler <EOL> from pycnic . errors import HTTP_400 , HTTP_401 <EOL> class Login ( Handler ) : <EOL> def get ( self ) : <EOL> sess_id = self . request . cookies . get ( "<STR_LIT>" ) <EOL> return { "<STR_LIT>" : sess_id } <EOL> def post ( self ) : <EOL> username = self . request . data . get ( "<STR_LIT:username>" ) <EOL> password = self . request . data . get ( "<STR_LIT:password>" ) <EOL> if not username or not password : <EOL> raise HTTP_400 ( "<STR_LIT>" ) <EOL> if username != "<STR_LIT:foo>" or password != "<STR_LIT:foo>" : <EOL> raise HTTP_401 ( "<STR_LIT>" ) <EOL> self . response . set_cookie ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> return { "<STR_LIT:message>" : "<STR_LIT>" } <EOL> class Logout ( Handler ) : <EOL> def post ( self ) : <EOL> if self . request . cookies . get ( "<STR_LIT>" ) : <EOL> self . response . delete_cookie ( "<STR_LIT>" ) <EOL> return { "<STR_LIT:message>" : "<STR_LIT>" } <EOL> return { <EOL> "<STR_LIT:message>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : self . request . cookies <EOL> } <EOL> class app ( WSGI ) : <EOL> routes = [ <EOL> ( "<STR_LIT>" , Login ( ) ) , <EOL> ( "<STR_LIT>" , Logout ( ) ) , <EOL> ] <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> from wsgiref . simple_server import make_server <EOL> try : <EOL> print ( "<STR_LIT>" ) <EOL> make_server ( '<STR_LIT>' , <NUM_LIT> , app ) . serve_forever ( ) <EOL> except KeyboardInterrupt : <EOL> pass <EOL> print ( "<STR_LIT>" ) </s>
