<s> import datetime <EOL> from paste . auth import auth_tkt <EOL> from webob import Request <EOL> LOGIN_FORM_TEMPLATE = """<STR_LIT>""" <EOL> SECRET = '<STR_LIT>' <EOL> COOKIE_NAME = '<STR_LIT>' <EOL> MAX_AGE = '<STR_LIT>' <EOL> AUTH = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> def _validate ( login_name , password ) : <EOL> return AUTH . get ( login_name ) == password <EOL> def _get_cookies ( environ , value ) : <EOL> later = ( datetime . datetime . now ( ) + <EOL> datetime . timedelta ( seconds = int ( MAX_AGE ) ) ) <EOL> expires = later . strftime ( '<STR_LIT>' ) <EOL> tail = "<STR_LIT>" % ( MAX_AGE , expires ) <EOL> cur_domain = environ . get ( '<STR_LIT>' , environ . get ( '<STR_LIT>' ) ) <EOL> wild_domain = '<STR_LIT:.>' + cur_domain <EOL> return [ ( '<STR_LIT>' , '<STR_LIT>' <EOL> % ( COOKIE_NAME , value , wild_domain , tail ) ) , <EOL> ] <EOL> def login ( environ , start_response ) : <EOL> request = Request ( environ ) <EOL> message = '<STR_LIT>' <EOL> if '<STR_LIT>' in request . POST : <EOL> came_from = request . POST [ '<STR_LIT>' ] <EOL> login_name = request . POST [ '<STR_LIT>' ] <EOL> password = request . POST [ '<STR_LIT:password>' ] <EOL> remote_addr = environ [ '<STR_LIT>' ] <EOL> if _validate ( login_name , password ) : <EOL> headers = [ ( '<STR_LIT>' , came_from ) ] <EOL> ticket = auth_tkt . AuthTicket ( SECRET , login_name , remote_addr , <EOL> cookie_name = COOKIE_NAME , secure = True ) <EOL> headers = _get_cookies ( environ , ticket . cookie_value ( ) ) <EOL> headers . append ( ( '<STR_LIT>' , came_from ) ) <EOL> start_response ( '<STR_LIT>' , headers ) <EOL> return [ ] <EOL> message = '<STR_LIT>' <EOL> else : <EOL> came_from = request . GET . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> login_name = '<STR_LIT>' <EOL> body = LOGIN_FORM_TEMPLATE % { '<STR_LIT:message>' : message , <EOL> '<STR_LIT>' : came_from , <EOL> '<STR_LIT>' : login_name , <EOL> } <EOL> start_response ( '<STR_LIT>' , [ ] ) <EOL> return [ body ] <EOL> def main ( global_config , ** local_config ) : <EOL> return login </s>
