<s> """<STR_LIT>""" <EOL> import pprint <EOL> import urlparse <EOL> password = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> integers = dict ( ) <EOL> strings = dict ( ) <EOL> sessions = dict ( ) <EOL> next_cookie = <NUM_LIT:0> <EOL> def application ( environ , start_response ) : <EOL> global next_cookie <EOL> response_headers = [ ] <EOL> cookie = environ . get ( '<STR_LIT>' ) <EOL> if ( environ [ '<STR_LIT>' ] == '<STR_LIT>' <EOL> and environ [ '<STR_LIT>' ] == '<STR_LIT:GET>' <EOL> and cookie not in sessions ) : <EOL> response_body = login_page <EOL> response_headers += [ <EOL> ( '<STR_LIT>' , '<STR_LIT>' % next_cookie ) ] <EOL> next_cookie += <NUM_LIT:1> <EOL> status = '<STR_LIT>' <EOL> elif ( environ [ '<STR_LIT>' ] == '<STR_LIT>' <EOL> and environ [ '<STR_LIT>' ] == '<STR_LIT:POST>' ) : <EOL> wd = environ [ '<STR_LIT>' ] <EOL> method = environ [ '<STR_LIT>' ] <EOL> length = int ( environ [ '<STR_LIT>' ] ) <EOL> request_body = wd . read ( length ) <EOL> vars = urlparse . parse_qs ( request_body ) <EOL> user = vars [ '<STR_LIT:username>' ] [ <NUM_LIT:0> ] <EOL> passwd = vars [ '<STR_LIT:password>' ] [ <NUM_LIT:0> ] <EOL> if user in password and password [ user ] == passwd : <EOL> sessions [ cookie ] = user <EOL> if not user in strings : <EOL> strings [ user ] = '<STR_LIT>' <EOL> integers [ user ] = <NUM_LIT:0> <EOL> response_headers += [ ( '<STR_LIT>' , '<STR_LIT>' ) ] <EOL> status = "<STR_LIT>" <EOL> response_body = '<STR_LIT>' <EOL> else : <EOL> response_body = login_failure_page <EOL> status = '<STR_LIT>' <EOL> elif ( environ [ '<STR_LIT>' ] == '<STR_LIT>' <EOL> and environ [ '<STR_LIT>' ] == '<STR_LIT:GET>' <EOL> and cookie in sessions ) : <EOL> user = sessions [ cookie ] <EOL> vars = urlparse . parse_qs ( environ [ '<STR_LIT>' ] ) <EOL> if '<STR_LIT>' in vars : <EOL> integers [ user ] = str ( vars [ '<STR_LIT>' ] [ <NUM_LIT:0> ] ) <EOL> if '<STR_LIT:str>' in vars : <EOL> strings [ user ] = vars [ '<STR_LIT:str>' ] [ <NUM_LIT:0> ] <EOL> response_body = dostuff_template % ( integers [ user ] , <EOL> strings [ user ] ) <EOL> status = '<STR_LIT>' <EOL> elif environ [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> if cookie in sessions : <EOL> del sessions [ cookie ] <EOL> response_body = '<STR_LIT>' <EOL> status = '<STR_LIT>' <EOL> pass <EOL> elif environ [ '<STR_LIT>' ] not in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> response_body = p404_page <EOL> status = '<STR_LIT>' <EOL> else : <EOL> raise ValueError <EOL> response_headers += [ ( '<STR_LIT:Content-Type>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , str ( len ( response_body ) ) ) ] <EOL> start_response ( status , response_headers ) <EOL> return [ response_body ] <EOL> environ_template = """<STR_LIT>""" <EOL> p404_page = """<STR_LIT>""" <EOL> login_page = """<STR_LIT>""" <EOL> login_failure_page = """<STR_LIT>""" <EOL> dostuff_template = """<STR_LIT>""" </s>
