<s> import urllib <EOL> from tornado . web import HTTPError <EOL> def role_required ( role ) : <EOL> def wrap ( view_func ) : <EOL> def has_role ( self , * args , ** kwargs ) : <EOL> if not self . current_user : <EOL> if self . request . method == "<STR_LIT:GET>" : <EOL> url = self . get_login_url ( ) <EOL> if "<STR_LIT:?>" not in url : <EOL> url += "<STR_LIT:?>" + urllib . urlencode ( dict ( next = self . request . uri ) ) <EOL> self . redirect ( url ) <EOL> return <EOL> raise HTTPError ( <NUM_LIT> ) <EOL> else : <EOL> if not self . current_user . has_role ( role ) : <EOL> self . flash . error = "<STR_LIT>" <EOL> self . redirect ( '<STR_LIT:/>' ) <EOL> return <EOL> return view_func ( self , * args , ** kwargs ) <EOL> return has_role <EOL> return wrap <EOL> class route ( object ) : <EOL> """<STR_LIT>""" <EOL> _routes = [ ] <EOL> def __init__ ( self , uri ) : <EOL> self . _uri = uri <EOL> def __call__ ( self , _handler ) : <EOL> """<STR_LIT>""" <EOL> self . _routes . append ( ( self . _uri , _handler ) ) <EOL> return _handler <EOL> @ classmethod <EOL> def get_routes ( self ) : <EOL> return self . _routes </s>
