<s> """<STR_LIT>""" <EOL> import logging <EOL> from tornado . auth import TwitterMixin <EOL> from tornado . escape import json_decode , json_encode <EOL> from tornado . ioloop import IOLoop <EOL> from tornado import gen <EOL> from tornado . options import define , options , parse_command_line , parse_config_file <EOL> from tornado . web import Application , RequestHandler , authenticated <EOL> define ( '<STR_LIT:port>' , default = <NUM_LIT> , help = "<STR_LIT>" ) <EOL> define ( '<STR_LIT>' , default = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> define ( '<STR_LIT>' , default = False , group = '<STR_LIT>' , <EOL> help = "<STR_LIT>" ) <EOL> define ( '<STR_LIT>' , type = str , group = '<STR_LIT>' ) <EOL> define ( '<STR_LIT>' , type = str , group = '<STR_LIT>' ) <EOL> define ( '<STR_LIT>' , type = str , group = '<STR_LIT>' , <EOL> default = '<STR_LIT>' , <EOL> help = "<STR_LIT>" ) <EOL> class BaseHandler ( RequestHandler ) : <EOL> COOKIE_NAME = '<STR_LIT>' <EOL> def get_current_user ( self ) : <EOL> user_json = self . get_secure_cookie ( self . COOKIE_NAME ) <EOL> if not user_json : <EOL> return None <EOL> return json_decode ( user_json ) <EOL> class MainHandler ( BaseHandler , TwitterMixin ) : <EOL> @ authenticated <EOL> @ gen . coroutine <EOL> def get ( self ) : <EOL> timeline = yield self . twitter_request ( <EOL> '<STR_LIT>' , <EOL> access_token = self . current_user [ '<STR_LIT>' ] ) <EOL> self . render ( '<STR_LIT>' , timeline = timeline ) <EOL> class LoginHandler ( BaseHandler , TwitterMixin ) : <EOL> @ gen . coroutine <EOL> def get ( self ) : <EOL> if self . get_argument ( '<STR_LIT>' , None ) : <EOL> user = yield self . get_authenticated_user ( ) <EOL> del user [ "<STR_LIT:description>" ] <EOL> self . set_secure_cookie ( self . COOKIE_NAME , json_encode ( user ) ) <EOL> self . redirect ( self . get_argument ( '<STR_LIT>' , '<STR_LIT:/>' ) ) <EOL> else : <EOL> yield self . authorize_redirect ( callback_uri = self . request . full_url ( ) ) <EOL> class LogoutHandler ( BaseHandler ) : <EOL> def get ( self ) : <EOL> self . clear_cookie ( self . COOKIE_NAME ) <EOL> def main ( ) : <EOL> parse_command_line ( final = False ) <EOL> parse_config_file ( options . config_file ) <EOL> app = Application ( <EOL> [ <EOL> ( '<STR_LIT:/>' , MainHandler ) , <EOL> ( '<STR_LIT>' , LoginHandler ) , <EOL> ( '<STR_LIT>' , LogoutHandler ) , <EOL> ] , <EOL> login_url = '<STR_LIT>' , <EOL> ** options . group_dict ( '<STR_LIT>' ) ) <EOL> app . listen ( options . port ) <EOL> logging . info ( '<STR_LIT>' % options . port ) <EOL> IOLoop . current ( ) . start ( ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
