<s> """<STR_LIT>""" <EOL> from functools import update_wrapper <EOL> from . helpers import _PackageBoundObject , _endpoint_from_view_func <EOL> class BlueprintSetupState ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , blueprint , app , options , first_registration ) : <EOL> self . app = app <EOL> self . blueprint = blueprint <EOL> self . options = options <EOL> self . first_registration = first_registration <EOL> subdomain = self . options . get ( '<STR_LIT>' ) <EOL> if subdomain is None : <EOL> subdomain = self . blueprint . subdomain <EOL> self . subdomain = subdomain <EOL> url_prefix = self . options . get ( '<STR_LIT>' ) <EOL> if url_prefix is None : <EOL> url_prefix = self . blueprint . url_prefix <EOL> self . url_prefix = url_prefix <EOL> self . url_defaults = dict ( self . blueprint . url_values_defaults ) <EOL> self . url_defaults . update ( self . options . get ( '<STR_LIT>' , ( ) ) ) <EOL> def add_url_rule ( self , rule , endpoint = None , view_func = None , ** options ) : <EOL> """<STR_LIT>""" <EOL> if self . url_prefix : <EOL> rule = self . url_prefix + rule <EOL> options . setdefault ( '<STR_LIT>' , self . subdomain ) <EOL> if endpoint is None : <EOL> endpoint = _endpoint_from_view_func ( view_func ) <EOL> defaults = self . url_defaults <EOL> if '<STR_LIT>' in options : <EOL> defaults = dict ( defaults , ** options . pop ( '<STR_LIT>' ) ) <EOL> self . app . add_url_rule ( rule , '<STR_LIT>' % ( self . blueprint . name , endpoint ) , <EOL> view_func , defaults = defaults , ** options ) <EOL> class Blueprint ( _PackageBoundObject ) : <EOL> """<STR_LIT>""" <EOL> warn_on_modifications = False <EOL> _got_registered_once = False <EOL> def __init__ ( self , name , import_name , static_folder = None , <EOL> static_url_path = None , template_folder = None , <EOL> url_prefix = None , subdomain = None , url_defaults = None ) : <EOL> _PackageBoundObject . __init__ ( self , import_name , template_folder ) <EOL> self . name = name <EOL> self . url_prefix = url_prefix <EOL> self . subdomain = subdomain <EOL> self . static_folder = static_folder <EOL> self . static_url_path = static_url_path <EOL> self . deferred_functions = [ ] <EOL> self . view_functions = { } <EOL> if url_defaults is None : <EOL> url_defaults = { } <EOL> self . url_values_defaults = url_defaults <EOL> def record ( self , func ) : <EOL> """<STR_LIT>""" <EOL> if self . _got_registered_once and self . warn_on_modifications : <EOL> from warnings import warn <EOL> warn ( Warning ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) ) <EOL> self . deferred_functions . append ( func ) <EOL> def record_once ( self , func ) : <EOL> """<STR_LIT>""" <EOL> def wrapper ( state ) : <EOL> if state . first_registration : <EOL> func ( state ) <EOL> return self . record ( update_wrapper ( wrapper , func ) ) <EOL> def make_setup_state ( self , app , options , first_registration = False ) : <EOL> """<STR_LIT>""" <EOL> return BlueprintSetupState ( self , app , options , first_registration ) <EOL> def register ( self , app , options , first_registration = False ) : <EOL> """<STR_LIT>""" <EOL> self . _got_registered_once = True <EOL> state = self . make_setup_state ( app , options , first_registration ) <EOL> if self . has_static_folder : <EOL> state . add_url_rule ( self . static_url_path + '<STR_LIT>' , <EOL> view_func = self . send_static_file , <EOL> endpoint = '<STR_LIT>' ) <EOL> for deferred in self . deferred_functions : <EOL> deferred ( state ) <EOL> def route ( self , rule , ** options ) : <EOL> """<STR_LIT>""" <EOL> def decorator ( f ) : <EOL> endpoint = options . pop ( "<STR_LIT>" , f . __name__ ) <EOL> self . add_url_rule ( rule , endpoint , f , ** options ) <EOL> return f <EOL> return decorator <EOL> def add_url_rule ( self , rule , endpoint = None , view_func = None , ** options ) : <EOL> """<STR_LIT>""" <EOL> if endpoint : <EOL> assert '<STR_LIT:.>' not in endpoint , "<STR_LIT>" <EOL> self . record ( lambda s : <EOL> s . add_url_rule ( rule , endpoint , view_func , ** options ) ) <EOL> def endpoint ( self , endpoint ) : <EOL> """<STR_LIT>""" <EOL> def decorator ( f ) : <EOL> def register_endpoint ( state ) : <EOL> state . app . view_functions [ endpoint ] = f <EOL> self . record_once ( register_endpoint ) <EOL> return f <EOL> return decorator <EOL> def app_template_filter ( self , name = None ) : <EOL> """<STR_LIT>""" <EOL> def decorator ( f ) : <EOL> self . add_app_template_filter ( f , name = name ) <EOL> return f <EOL> return decorator <EOL> def add_app_template_filter ( self , f , name = None ) : <EOL> """<STR_LIT>""" <EOL> def register_template ( state ) : <EOL> state . app . jinja_env . filters [ name or f . __name__ ] = f <EOL> self . record_once ( register_template ) <EOL> def app_template_test ( self , name = None ) : <EOL> """<STR_LIT>""" <EOL> def decorator ( f ) : <EOL> self . add_app_template_test ( f , name = name ) <EOL> return f <EOL> return decorator <EOL> def add_app_template_test ( self , f , name = None ) : <EOL> """<STR_LIT>""" <EOL> def register_template ( state ) : <EOL> state . app . jinja_env . tests [ name or f . __name__ ] = f <EOL> self . record_once ( register_template ) <EOL> def app_template_global ( self , name = None ) : <EOL> """<STR_LIT>""" <EOL> def decorator ( f ) : <EOL> self . add_app_template_global ( f , name = name ) <EOL> return f <EOL> return decorator <EOL> def add_app_template_global ( self , f , name = None ) : <EOL> """<STR_LIT>""" <EOL> def register_template ( state ) : <EOL> state . app . jinja_env . globals [ name or f . __name__ ] = f <EOL> self . record_once ( register_template ) <EOL> def before_request ( self , f ) : <EOL> """<STR_LIT>""" <EOL> self . record_once ( lambda s : s . app . before_request_funcs <EOL> . setdefault ( self . name , [ ] ) . append ( f ) ) <EOL> return f <EOL> def before_app_request ( self , f ) : <EOL> """<STR_LIT>""" <EOL> self . record_once ( lambda s : s . app . before_request_funcs <EOL> . setdefault ( None , [ ] ) . append ( f ) ) <EOL> return f <EOL> def before_app_first_request ( self , f ) : <EOL> """<STR_LIT>""" <EOL> self . record_once ( lambda s : s . app . before_first_request_funcs . append ( f ) ) <EOL> return f <EOL> def after_request ( self , f ) : <EOL> """<STR_LIT>""" <EOL> self . record_once ( lambda s : s . app . after_request_funcs <EOL> . setdefault ( self . name , [ ] ) . append ( f ) ) <EOL> return f <EOL> def after_app_request ( self , f ) : <EOL> """<STR_LIT>""" <EOL> self . record_once ( lambda s : s . app . after_request_funcs <EOL> . setdefault ( None , [ ] ) . append ( f ) ) <EOL> return f <EOL> def teardown_request ( self , f ) : <EOL> """<STR_LIT>""" <EOL> self . record_once ( lambda s : s . app . teardown_request_funcs <EOL> . setdefault ( self . name , [ ] ) . append ( f ) ) <EOL> return f <EOL> def teardown_app_request ( self , f ) : <EOL> """<STR_LIT>""" <EOL> self . record_once ( lambda s : s . app . teardown_request_funcs <EOL> . setdefault ( None , [ ] ) . append ( f ) ) <EOL> return f <EOL> def context_processor ( self , f ) : <EOL> """<STR_LIT>""" <EOL> self . record_once ( lambda s : s . app . template_context_processors <EOL> . setdefault ( self . name , [ ] ) . append ( f ) ) <EOL> return f <EOL> def app_context_processor ( self , f ) : <EOL> """<STR_LIT>""" <EOL> self . record_once ( lambda s : s . app . template_context_processors <EOL> . setdefault ( None , [ ] ) . append ( f ) ) <EOL> return f <EOL> def app_errorhandler ( self , code ) : <EOL> """<STR_LIT>""" <EOL> def decorator ( f ) : <EOL> self . record_once ( lambda s : s . app . errorhandler ( code ) ( f ) ) <EOL> return f <EOL> return decorator <EOL> def url_value_preprocessor ( self , f ) : <EOL> """<STR_LIT>""" <EOL> self . record_once ( lambda s : s . app . url_value_preprocessors <EOL> . setdefault ( self . name , [ ] ) . append ( f ) ) <EOL> return f <EOL> def url_defaults ( self , f ) : <EOL> """<STR_LIT>""" <EOL> self . record_once ( lambda s : s . app . url_default_functions <EOL> . setdefault ( self . name , [ ] ) . append ( f ) ) <EOL> return f <EOL> def app_url_value_preprocessor ( self , f ) : <EOL> """<STR_LIT>""" <EOL> self . record_once ( lambda s : s . app . url_value_preprocessors <EOL> . setdefault ( None , [ ] ) . append ( f ) ) <EOL> return f <EOL> def app_url_defaults ( self , f ) : <EOL> """<STR_LIT>""" <EOL> self . record_once ( lambda s : s . app . url_default_functions <EOL> . setdefault ( None , [ ] ) . append ( f ) ) <EOL> return f <EOL> def errorhandler ( self , code_or_exception ) : <EOL> """<STR_LIT>""" <EOL> def decorator ( f ) : <EOL> self . record_once ( lambda s : s . app . _register_error_handler ( <EOL> self . name , code_or_exception , f ) ) <EOL> return f <EOL> return decorator </s>
