<s> import tornado . web <EOL> import logging <EOL> class BaseHandler ( tornado . web . RequestHandler ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , application , request , ** kwargs ) : <EOL> tornado . web . RequestHandler . __init__ ( self , application , request , ** kwargs ) <EOL> def _get_current_user ( self , callback ) : <EOL> """<STR_LIT>""" <EOL> user_id = self . get_secure_cookie ( "<STR_LIT:user>" ) <EOL> if not user_id : <EOL> logging . warning ( "<STR_LIT>" ) <EOL> callback ( user = None ) <EOL> return <EOL> def query_callback ( result ) : <EOL> if result == "<STR_LIT:null>" or not result : <EOL> logging . warning ( "<STR_LIT>" ) <EOL> user = { } <EOL> else : <EOL> user = tornado . escape . json_decode ( result ) <EOL> self . _current_user = user <EOL> callback ( user = user ) <EOL> self . application . client . get ( "<STR_LIT>" + user_id , query_callback ) <EOL> return <EOL> def render_default ( self , template_name , ** kwargs ) : <EOL> if not hasattr ( self , '<STR_LIT>' ) : <EOL> self . _current_user = None <EOL> kwargs [ '<STR_LIT:user>' ] = self . _current_user <EOL> kwargs [ '<STR_LIT:path>' ] = self . request . path ; <EOL> if hasattr ( self , '<STR_LIT>' ) : <EOL> kwargs [ '<STR_LIT>' ] = int ( self . room ) <EOL> else : kwargs [ '<STR_LIT>' ] = None <EOL> kwargs [ '<STR_LIT>' ] = self . application . settings [ '<STR_LIT>' ] <EOL> if not self . request . connection . stream . closed ( ) : <EOL> try : <EOL> self . render ( template_name , ** kwargs ) <EOL> except : pass </s>
