<s> from functools import wraps <EOL> from flask import request , current_app <EOL> from werkzeug . exceptions import Forbidden <EOL> from werkzeug import LocalProxy <EOL> class Allows ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , app = None , identity_loader = None , throws = Forbidden ) : <EOL> self . _identity_loader = identity_loader <EOL> self . throws = throws <EOL> if app : <EOL> self . init_app ( app ) <EOL> def init_app ( self , app ) : <EOL> if not hasattr ( app , '<STR_LIT>' ) : <EOL> app . extensions = { } <EOL> app . extensions [ '<STR_LIT>' ] = self <EOL> def requires ( self , * requirements , ** opts ) : <EOL> """<STR_LIT>""" <EOL> throws = opts . get ( '<STR_LIT>' , self . throws ) <EOL> def decorator ( f ) : <EOL> @ wraps ( f ) <EOL> def allower ( * args , ** kwargs ) : <EOL> if self . fulfill ( requirements ) : <EOL> return f ( * args , ** kwargs ) <EOL> else : <EOL> raise throws <EOL> return allower <EOL> return decorator <EOL> def identity_loader ( self , f ) : <EOL> "<STR_LIT>" <EOL> self . _identity_loader = f <EOL> return f <EOL> def fulfill ( self , requirements , identity = None ) : <EOL> "<STR_LIT>" <EOL> identity = identity or self . _identity_loader ( ) <EOL> return all ( r ( identity , request ) for r in requirements ) <EOL> def __get_allows ( ) : <EOL> "<STR_LIT>" <EOL> try : <EOL> return current_app . extensions [ '<STR_LIT>' ] <EOL> except ( AttributeError , KeyError ) : <EOL> raise RuntimeError ( "<STR_LIT>" ) <EOL> _allows = LocalProxy ( __get_allows , name = "<STR_LIT>" ) </s>
