<s> """<STR_LIT>""" <EOL> from werkzeug . utils import import_string , cached_property <EOL> from flask . blueprints import Blueprint <EOL> from . decorators import as_json , with_request_body , with_template <EOL> __all__ = ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) <EOL> class LazyView ( object ) : <EOL> def __init__ ( self , import_name ) : <EOL> self . __module__ , self . __name__ = import_name . rsplit ( '<STR_LIT:.>' , <NUM_LIT:1> ) <EOL> self . import_name = import_name <EOL> @ cached_property <EOL> def view ( self ) : <EOL> return import_string ( self . import_name ) <EOL> def __call__ ( self , * args , ** kwargs ) : <EOL> return self . view ( * args , ** kwargs ) <EOL> def get_router ( blueprint , import_prefix = None , filters = None ) : <EOL> """<STR_LIT>""" <EOL> def router ( url_rule , func_name , endpoint = None , ** options ) : <EOL> """<STR_LIT>""" <EOL> if import_prefix : <EOL> func_name = import_prefix + '<STR_LIT:.>' + func_name <EOL> view = LazyView ( func_name ) <EOL> if filters : <EOL> assert isinstance ( filters , ( tuple , list ) ) <EOL> for f in filters : <EOL> if isinstance ( f , basestring ) : <EOL> f = import_string ( f ) <EOL> if callable ( f ) : <EOL> view = f ( view ) <EOL> endpoint = endpoint or func_name . split ( '<STR_LIT:.>' ) [ - <NUM_LIT:1> ] <EOL> blueprint . add_url_rule ( url_rule , endpoint , view_func = view , ** options ) <EOL> return router <EOL> class APIBlueprint ( Blueprint ) : <EOL> """<STR_LIT>""" <EOL> def add_url_rule ( self , rule , endpoint = None , view_func = None , ** options ) : <EOL> view_func = as_json ( with_request_body ( view_func ) ) <EOL> return super ( APIBlueprint , self ) . add_url_rule ( rule , endpoint , view_func , ** options ) <EOL> class TemplateBlueprint ( Blueprint ) : <EOL> """<STR_LIT>""" <EOL> def add_url_rule ( self , rule , endpoint = None , view_func = None , ** options ) : <EOL> view_func = with_template ( ) ( view_func ) <EOL> return super ( TemplateBlueprint , self ) . add_url_rule ( rule , endpoint , view_func , ** options ) </s>
