<s> """<STR_LIT>""" <EOL> from __future__ import with_statement <EOL> import os <EOL> import sys <EOL> from threading import Lock <EOL> from datetime import timedelta <EOL> from itertools import chain <EOL> from functools import update_wrapper <EOL> from werkzeug . datastructures import ImmutableDict <EOL> from werkzeug . routing import Map , Rule , RequestRedirect <EOL> from werkzeug . exceptions import HTTPException , InternalServerError , MethodNotAllowed , BadRequest <EOL> from . helpers import _PackageBoundObject , url_for , get_flashed_messages , locked_cached_property , _tojson_filter , _endpoint_from_view_func , find_package <EOL> from . wrappers import Request , Response <EOL> from . config import ConfigAttribute , Config <EOL> from . ctx import RequestContext <EOL> from . globals import _request_ctx_stack , request <EOL> from . sessions import SecureCookieSessionInterface <EOL> from . module import blueprint_is_module <EOL> from . templating import DispatchingJinjaLoader , Environment , _default_template_ctx_processor <EOL> from . signals import request_started , request_finished , got_request_exception , request_tearing_down <EOL> _logger_lock = Lock ( ) <EOL> def _make_timedelta ( value ) : <EOL> if not isinstance ( value , timedelta ) : <EOL> return timedelta ( seconds = value ) <EOL> return value <EOL> def setupmethod ( f ) : <EOL> """<STR_LIT>""" <EOL> def wrapper_func ( self , * args , ** kwargs ) : <EOL> if self . debug and self . _got_first_request : <EOL> raise AssertionError ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> return f ( self , * args , ** kwargs ) <EOL> return update_wrapper ( wrapper_func , f ) <EOL> class Flask ( _PackageBoundObject ) : <EOL> """<STR_LIT>""" <EOL> request_class = Request <EOL> response_class = Response <EOL> debug = ConfigAttribute ( '<STR_LIT>' ) <EOL> testing = ConfigAttribute ( '<STR_LIT>' ) <EOL> secret_key = ConfigAttribute ( '<STR_LIT>' ) <EOL> session_cookie_name = ConfigAttribute ( '<STR_LIT>' ) <EOL> permanent_session_lifetime = ConfigAttribute ( '<STR_LIT>' , <EOL> get_converter = _make_timedelta ) <EOL> use_x_sendfile = ConfigAttribute ( '<STR_LIT>' ) <EOL> logger_name = ConfigAttribute ( '<STR_LIT>' ) <EOL> enable_modules = True <EOL> debug_log_format = ( <EOL> '<STR_LIT:->' * <NUM_LIT> + '<STR_LIT:\n>' + <EOL> '<STR_LIT>' + <EOL> '<STR_LIT>' + <EOL> '<STR_LIT:->' * <NUM_LIT> <EOL> ) <EOL> jinja_options = ImmutableDict ( <EOL> extensions = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> default_config = ImmutableDict ( { <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : timedelta ( days = <NUM_LIT> ) , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : False <EOL> } ) <EOL> url_rule_class = Rule <EOL> test_client_class = None <EOL> session_interface = SecureCookieSessionInterface ( ) <EOL> def __init__ ( self , import_name , static_path = None , static_url_path = None , <EOL> static_folder = '<STR_LIT>' , template_folder = '<STR_LIT>' , <EOL> instance_path = None , instance_relative_config = False ) : <EOL> _PackageBoundObject . __init__ ( self , import_name , <EOL> template_folder = template_folder ) <EOL> if static_path is not None : <EOL> from warnings import warn <EOL> warn ( DeprecationWarning ( '<STR_LIT>' <EOL> '<STR_LIT>' ) , stacklevel = <NUM_LIT:2> ) <EOL> static_url_path = static_path <EOL> if static_url_path is not None : <EOL> self . static_url_path = static_url_path <EOL> if static_folder is not None : <EOL> self . static_folder = static_folder <EOL> if instance_path is None : <EOL> instance_path = self . auto_find_instance_path ( ) <EOL> elif not os . path . isabs ( instance_path ) : <EOL> raise ValueError ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> self . instance_path = instance_path <EOL> self . config = self . make_config ( instance_relative_config ) <EOL> self . _logger = None <EOL> self . logger_name = self . import_name <EOL> self . view_functions = { } <EOL> self . _error_handlers = { } <EOL> self . error_handler_spec = { None : self . _error_handlers } <EOL> self . before_request_funcs = { } <EOL> self . before_first_request_funcs = [ ] <EOL> self . after_request_funcs = { } <EOL> self . teardown_request_funcs = { } <EOL> self . url_value_preprocessors = { } <EOL> self . url_default_functions = { } <EOL> self . template_context_processors = { <EOL> None : [ _default_template_ctx_processor ] <EOL> } <EOL> self . blueprints = { } <EOL> self . extensions = { } <EOL> self . url_map = Map ( ) <EOL> self . _got_first_request = False <EOL> self . _before_request_lock = Lock ( ) <EOL> if self . has_static_folder : <EOL> self . add_url_rule ( self . static_url_path + '<STR_LIT>' , <EOL> endpoint = '<STR_LIT>' , <EOL> view_func = self . send_static_file ) <EOL> def _get_error_handlers ( self ) : <EOL> from warnings import warn <EOL> warn ( DeprecationWarning ( '<STR_LIT>' <EOL> '<STR_LIT>' ) , stacklevel = <NUM_LIT:1> ) <EOL> return self . _error_handlers <EOL> def _set_error_handlers ( self , value ) : <EOL> self . _error_handlers = value <EOL> self . error_handler_spec [ None ] = value <EOL> error_handlers = property ( _get_error_handlers , _set_error_handlers ) <EOL> del _get_error_handlers , _set_error_handlers <EOL> @ locked_cached_property <EOL> def name ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . import_name == '<STR_LIT:__main__>' : <EOL> fn = getattr ( sys . modules [ '<STR_LIT:__main__>' ] , '<STR_LIT>' , None ) <EOL> if fn is None : <EOL> return '<STR_LIT:__main__>' <EOL> return os . path . splitext ( os . path . basename ( fn ) ) [ <NUM_LIT:0> ] <EOL> return self . import_name <EOL> @ property <EOL> def propagate_exceptions ( self ) : <EOL> """<STR_LIT>""" <EOL> rv = self . config [ '<STR_LIT>' ] <EOL> if rv is not None : <EOL> return rv <EOL> return self . testing or self . debug <EOL> @ property <EOL> def preserve_context_on_exception ( self ) : <EOL> """<STR_LIT>""" <EOL> rv = self . config [ '<STR_LIT>' ] <EOL> if rv is not None : <EOL> return rv <EOL> return self . debug <EOL> @ property <EOL> def logger ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . _logger and self . _logger . name == self . logger_name : <EOL> return self . _logger <EOL> with _logger_lock : <EOL> if self . _logger and self . _logger . name == self . logger_name : <EOL> return self . _logger <EOL> from flask . logging import create_logger <EOL> self . _logger = rv = create_logger ( self ) <EOL> return rv <EOL> @ locked_cached_property <EOL> def jinja_env ( self ) : <EOL> """<STR_LIT>""" <EOL> rv = self . create_jinja_environment ( ) <EOL> if getattr ( self . init_jinja_globals , '<STR_LIT>' , None ) is not Flask . init_jinja_globals . im_func : <EOL> from warnings import warn <EOL> warn ( DeprecationWarning ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) ) <EOL> self . __dict__ [ '<STR_LIT>' ] = rv <EOL> self . init_jinja_globals ( ) <EOL> return rv <EOL> @ property <EOL> def got_first_request ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _got_first_request <EOL> def make_config ( self , instance_relative = False ) : <EOL> """<STR_LIT>""" <EOL> root_path = self . root_path <EOL> if instance_relative : <EOL> root_path = self . instance_path <EOL> return Config ( root_path , self . default_config ) <EOL> def auto_find_instance_path ( self ) : <EOL> """<STR_LIT>""" <EOL> prefix , package_path = find_package ( self . import_name ) <EOL> if prefix is None : <EOL> return os . path . join ( package_path , '<STR_LIT>' ) <EOL> return os . path . join ( prefix , '<STR_LIT>' , self . name + '<STR_LIT>' ) <EOL> def open_instance_resource ( self , resource , mode = '<STR_LIT:rb>' ) : <EOL> """<STR_LIT>""" <EOL> return open ( os . path . join ( self . instance_path , resource ) , mode ) <EOL> def create_jinja_environment ( self ) : <EOL> """<STR_LIT>""" <EOL> options = dict ( self . jinja_options ) <EOL> if '<STR_LIT>' not in options : <EOL> options [ '<STR_LIT>' ] = self . select_jinja_autoescape <EOL> rv = Environment ( self , ** options ) <EOL> rv . globals . update ( <EOL> url_for = url_for , <EOL> get_flashed_messages = get_flashed_messages <EOL> ) <EOL> rv . filters [ '<STR_LIT>' ] = _tojson_filter <EOL> return rv <EOL> def create_global_jinja_loader ( self ) : <EOL> """<STR_LIT>""" <EOL> return DispatchingJinjaLoader ( self ) <EOL> def init_jinja_globals ( self ) : <EOL> """<STR_LIT>""" <EOL> def select_jinja_autoescape ( self , filename ) : <EOL> """<STR_LIT>""" <EOL> if filename is None : <EOL> return False <EOL> return filename . endswith ( ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> def update_template_context ( self , context ) : <EOL> """<STR_LIT>""" <EOL> funcs = self . template_context_processors [ None ] <EOL> bp = _request_ctx_stack . top . request . blueprint <EOL> if bp is not None and bp in self . template_context_processors : <EOL> funcs = chain ( funcs , self . template_context_processors [ bp ] ) <EOL> orig_ctx = context . copy ( ) <EOL> for func in funcs : <EOL> context . update ( func ( ) ) <EOL> context . update ( orig_ctx ) <EOL> def run ( self , host = '<STR_LIT:127.0.0.1>' , port = <NUM_LIT> , debug = None , ** options ) : <EOL> """<STR_LIT>""" <EOL> from werkzeug . serving import run_simple <EOL> if debug is not None : <EOL> self . debug = bool ( debug ) <EOL> options . setdefault ( '<STR_LIT>' , self . debug ) <EOL> options . setdefault ( '<STR_LIT>' , self . debug ) <EOL> try : <EOL> run_simple ( host , port , self , ** options ) <EOL> finally : <EOL> self . _got_first_request = False <EOL> def test_client ( self , use_cookies = True ) : <EOL> """<STR_LIT>""" <EOL> cls = self . test_client_class <EOL> if cls is None : <EOL> from flask . testing import FlaskClient as cls <EOL> return cls ( self , self . response_class , use_cookies = use_cookies ) <EOL> def open_session ( self , request ) : <EOL> """<STR_LIT>""" <EOL> return self . session_interface . open_session ( self , request ) <EOL> def save_session ( self , session , response ) : <EOL> """<STR_LIT>""" <EOL> return self . session_interface . save_session ( self , session , response ) <EOL> def make_null_session ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . session_interface . make_null_session ( self ) <EOL> def register_module ( self , module , ** options ) : <EOL> """<STR_LIT>""" <EOL> assert blueprint_is_module ( module ) , '<STR_LIT>' '<STR_LIT>' <EOL> if not self . enable_modules : <EOL> raise RuntimeError ( '<STR_LIT>' <EOL> '<STR_LIT>' % module ) <EOL> else : <EOL> from warnings import warn <EOL> warn ( DeprecationWarning ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % module ) , <EOL> stacklevel = <NUM_LIT:2> ) <EOL> self . register_blueprint ( module , ** options ) <EOL> @ setupmethod <EOL> def register_blueprint ( self , blueprint , ** options ) : <EOL> """<STR_LIT>""" <EOL> first_registration = False <EOL> if blueprint . name in self . blueprints : <EOL> assert self . blueprints [ blueprint . name ] is blueprint , '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' % ( blueprint , self . blueprints [ blueprint . name ] , blueprint . name ) <EOL> else : <EOL> self . blueprints [ blueprint . name ] = blueprint <EOL> first_registration = True <EOL> blueprint . register ( self , options , first_registration ) <EOL> @ setupmethod <EOL> def add_url_rule ( self , rule , endpoint = None , view_func = None , ** options ) : <EOL> """<STR_LIT>""" <EOL> if endpoint is None : <EOL> endpoint = _endpoint_from_view_func ( view_func ) <EOL> options [ '<STR_LIT>' ] = endpoint <EOL> methods = options . pop ( '<STR_LIT>' , None ) <EOL> if methods is None : <EOL> methods = getattr ( view_func , '<STR_LIT>' , None ) or ( '<STR_LIT:GET>' , ) <EOL> provide_automatic_options = getattr ( view_func , <EOL> '<STR_LIT>' , None ) <EOL> if provide_automatic_options is None : <EOL> if '<STR_LIT>' not in methods : <EOL> methods = tuple ( methods ) + ( '<STR_LIT>' , ) <EOL> provide_automatic_options = True <EOL> else : <EOL> provide_automatic_options = False <EOL> options [ '<STR_LIT>' ] = options . get ( '<STR_LIT>' ) or None <EOL> rule = self . url_rule_class ( rule , methods = methods , ** options ) <EOL> rule . provide_automatic_options = provide_automatic_options <EOL> self . url_map . add ( rule ) <EOL> if view_func is not None : <EOL> self . view_functions [ endpoint ] = view_func <EOL> def route ( self , rule , ** options ) : <EOL> """<STR_LIT>""" <EOL> def decorator ( f ) : <EOL> endpoint = options . pop ( '<STR_LIT>' , None ) <EOL> self . add_url_rule ( rule , endpoint , f , ** options ) <EOL> return f <EOL> return decorator <EOL> @ setupmethod <EOL> def endpoint ( self , endpoint ) : <EOL> """<STR_LIT>""" <EOL> def decorator ( f ) : <EOL> self . view_functions [ endpoint ] = f <EOL> return f <EOL> return decorator <EOL> @ setupmethod <EOL> def errorhandler ( self , code_or_exception ) : <EOL> """<STR_LIT>""" <EOL> def decorator ( f ) : <EOL> self . _register_error_handler ( None , code_or_exception , f ) <EOL> return f <EOL> return decorator <EOL> def register_error_handler ( self , code_or_exception , f ) : <EOL> """<STR_LIT>""" <EOL> self . _register_error_handler ( None , code_or_exception , f ) <EOL> @ setupmethod <EOL> def _register_error_handler ( self , key , code_or_exception , f ) : <EOL> if isinstance ( code_or_exception , HTTPException ) : <EOL> code_or_exception = code_or_exception . code <EOL> if isinstance ( code_or_exception , ( int , long ) ) : <EOL> assert code_or_exception != <NUM_LIT> or key is None , '<STR_LIT>' '<STR_LIT>' <EOL> self . error_handler_spec . setdefault ( key , { } ) [ code_or_exception ] = f <EOL> else : <EOL> self . error_handler_spec . setdefault ( key , { } ) . setdefault ( None , [ ] ) . append ( ( code_or_exception , f ) ) <EOL> @ setupmethod <EOL> def template_filter ( self , name = None ) : <EOL> """<STR_LIT>""" <EOL> def decorator ( f ) : <EOL> self . jinja_env . filters [ name or f . __name__ ] = f <EOL> return f <EOL> return decorator <EOL> @ setupmethod <EOL> def before_request ( self , f ) : <EOL> """<STR_LIT>""" <EOL> self . before_request_funcs . setdefault ( None , [ ] ) . append ( f ) <EOL> return f <EOL> @ setupmethod <EOL> def before_first_request ( self , f ) : <EOL> """<STR_LIT>""" <EOL> self . before_first_request_funcs . append ( f ) <EOL> @ setupmethod <EOL> def after_request ( self , f ) : <EOL> """<STR_LIT>""" <EOL> self . after_request_funcs . setdefault ( None , [ ] ) . append ( f ) <EOL> return f <EOL> @ setupmethod <EOL> def teardown_request ( self , f ) : <EOL> """<STR_LIT>""" <EOL> self . teardown_request_funcs . setdefault ( None , [ ] ) . append ( f ) <EOL> return f <EOL> @ setupmethod <EOL> def context_processor ( self , f ) : <EOL> """<STR_LIT>""" <EOL> self . template_context_processors [ None ] . append ( f ) <EOL> return f <EOL> @ setupmethod <EOL> def url_value_preprocessor ( self , f ) : <EOL> """<STR_LIT>""" <EOL> self . url_value_preprocessors . setdefault ( None , [ ] ) . append ( f ) <EOL> return f <EOL> @ setupmethod <EOL> def url_defaults ( self , f ) : <EOL> """<STR_LIT>""" <EOL> self . url_default_functions . setdefault ( None , [ ] ) . append ( f ) <EOL> return f <EOL> def handle_http_exception ( self , e ) : <EOL> """<STR_LIT>""" <EOL> handlers = self . error_handler_spec . get ( request . blueprint ) <EOL> if handlers and e . code in handlers : <EOL> handler = handlers [ e . code ] <EOL> else : <EOL> handler = self . error_handler_spec [ None ] . get ( e . code ) <EOL> if handler is None : <EOL> return e <EOL> return handler ( e ) <EOL> def trap_http_exception ( self , e ) : <EOL> """<STR_LIT>""" <EOL> if self . config [ '<STR_LIT>' ] : <EOL> return True <EOL> if self . config [ '<STR_LIT>' ] : <EOL> return isinstance ( e , BadRequest ) <EOL> return False <EOL> def handle_user_exception ( self , e ) : <EOL> """<STR_LIT>""" <EOL> exc_type , exc_value , tb = sys . exc_info ( ) <EOL> assert exc_value is e <EOL> if isinstance ( e , HTTPException ) and not self . trap_http_exception ( e ) : <EOL> return self . handle_http_exception ( e ) <EOL> blueprint_handlers = ( ) <EOL> handlers = self . error_handler_spec . get ( request . blueprint ) <EOL> if handlers is not None : <EOL> blueprint_handlers = handlers . get ( None , ( ) ) <EOL> app_handlers = self . error_handler_spec [ None ] . get ( None , ( ) ) <EOL> for typecheck , handler in chain ( blueprint_handlers , app_handlers ) : <EOL> if isinstance ( e , typecheck ) : <EOL> return handler ( e ) <EOL> raise exc_type , exc_value , tb <EOL> def handle_exception ( self , e ) : <EOL> """<STR_LIT>""" <EOL> exc_type , exc_value , tb = sys . exc_info ( ) <EOL> got_request_exception . send ( self , exception = e ) <EOL> handler = self . error_handler_spec [ None ] . get ( <NUM_LIT> ) <EOL> if self . propagate_exceptions : <EOL> if exc_value is e : <EOL> raise exc_type , exc_value , tb <EOL> else : <EOL> raise e <EOL> self . log_exception ( ( exc_type , exc_value , tb ) ) <EOL> if handler is None : <EOL> return InternalServerError ( ) <EOL> return handler ( e ) <EOL> def log_exception ( self , exc_info ) : <EOL> """<STR_LIT>""" <EOL> self . logger . error ( '<STR_LIT>' % ( <EOL> request . path , <EOL> request . method <EOL> ) , exc_info = exc_info ) <EOL> def raise_routing_exception ( self , request ) : <EOL> """<STR_LIT>""" <EOL> if not self . debug or not isinstance ( request . routing_exception , RequestRedirect ) or request . method in ( '<STR_LIT:GET>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> raise request . routing_exception <EOL> from . debughelpers import FormDataRoutingRedirect <EOL> raise FormDataRoutingRedirect ( request ) <EOL> def dispatch_request ( self ) : <EOL> """<STR_LIT>""" <EOL> req = _request_ctx_stack . top . request <EOL> if req . routing_exception is not None : <EOL> self . raise_routing_exception ( req ) <EOL> rule = req . url_rule <EOL> if getattr ( rule , '<STR_LIT>' , False ) and req . method == '<STR_LIT>' : <EOL> return self . make_default_options_response ( ) <EOL> return self . view_functions [ rule . endpoint ] ( ** req . view_args ) <EOL> def full_dispatch_request ( self ) : <EOL> """<STR_LIT>""" <EOL> self . try_trigger_before_first_request_functions ( ) <EOL> try : <EOL> request_started . send ( self ) <EOL> rv = self . preprocess_request ( ) <EOL> if rv is None : <EOL> rv = self . dispatch_request ( ) <EOL> except Exception , e : <EOL> rv = self . handle_user_exception ( e ) <EOL> response = self . make_response ( rv ) <EOL> response = self . process_response ( response ) <EOL> request_finished . send ( self , response = response ) <EOL> return response <EOL> def try_trigger_before_first_request_functions ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . _got_first_request : <EOL> return <EOL> with self . _before_request_lock : <EOL> if self . _got_first_request : <EOL> return <EOL> self . _got_first_request = True <EOL> for func in self . before_first_request_funcs : <EOL> func ( ) <EOL> def make_default_options_response ( self ) : <EOL> """<STR_LIT>""" <EOL> adapter = _request_ctx_stack . top . url_adapter <EOL> if hasattr ( adapter , '<STR_LIT>' ) : <EOL> methods = adapter . allowed_methods ( ) <EOL> else : <EOL> methods = [ ] <EOL> try : <EOL> adapter . match ( method = '<STR_LIT>' ) <EOL> except MethodNotAllowed , e : <EOL> methods = e . valid_methods <EOL> except HTTPException , e : <EOL> pass <EOL> rv = self . response_class ( ) <EOL> rv . allow . update ( methods ) <EOL> return rv <EOL> def make_response ( self , rv ) : <EOL> """<STR_LIT>""" <EOL> if rv is None : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> if isinstance ( rv , self . response_class ) : <EOL> return rv <EOL> if isinstance ( rv , basestring ) : <EOL> return self . response_class ( rv ) <EOL> if isinstance ( rv , tuple ) : <EOL> return self . response_class ( * rv ) <EOL> return self . response_class . force_type ( rv , request . environ ) <EOL> def create_url_adapter ( self , request ) : <EOL> """<STR_LIT>""" <EOL> return self . url_map . bind_to_environ ( request . environ , <EOL> server_name = self . config [ '<STR_LIT>' ] ) <EOL> def inject_url_defaults ( self , endpoint , values ) : <EOL> """<STR_LIT>""" <EOL> funcs = self . url_default_functions . get ( None , ( ) ) <EOL> if '<STR_LIT:.>' in endpoint : <EOL> bp = endpoint . split ( '<STR_LIT:.>' , <NUM_LIT:1> ) [ <NUM_LIT:0> ] <EOL> funcs = chain ( funcs , self . url_default_functions . get ( bp , ( ) ) ) <EOL> for func in funcs : <EOL> func ( endpoint , values ) <EOL> def preprocess_request ( self ) : <EOL> """<STR_LIT>""" <EOL> bp = _request_ctx_stack . top . request . blueprint <EOL> funcs = self . url_value_preprocessors . get ( None , ( ) ) <EOL> if bp is not None and bp in self . url_value_preprocessors : <EOL> funcs = chain ( funcs , self . url_value_preprocessors [ bp ] ) <EOL> for func in funcs : <EOL> func ( request . endpoint , request . view_args ) <EOL> funcs = self . before_request_funcs . get ( None , ( ) ) <EOL> if bp is not None and bp in self . before_request_funcs : <EOL> funcs = chain ( funcs , self . before_request_funcs [ bp ] ) <EOL> for func in funcs : <EOL> rv = func ( ) <EOL> if rv is not None : <EOL> return rv <EOL> def process_response ( self , response ) : <EOL> """<STR_LIT>""" <EOL> ctx = _request_ctx_stack . top <EOL> bp = ctx . request . blueprint <EOL> if not self . session_interface . is_null_session ( ctx . session ) : <EOL> self . save_session ( ctx . session , response ) <EOL> funcs = ( ) <EOL> if bp is not None and bp in self . after_request_funcs : <EOL> funcs = reversed ( self . after_request_funcs [ bp ] ) <EOL> if None in self . after_request_funcs : <EOL> funcs = chain ( funcs , reversed ( self . after_request_funcs [ None ] ) ) <EOL> for handler in funcs : <EOL> response = handler ( response ) <EOL> return response <EOL> def do_teardown_request ( self ) : <EOL> """<STR_LIT>""" <EOL> funcs = reversed ( self . teardown_request_funcs . get ( None , ( ) ) ) <EOL> bp = _request_ctx_stack . top . request . blueprint <EOL> if bp is not None and bp in self . teardown_request_funcs : <EOL> funcs = chain ( funcs , reversed ( self . teardown_request_funcs [ bp ] ) ) <EOL> exc = sys . exc_info ( ) [ <NUM_LIT:1> ] <EOL> for func in funcs : <EOL> rv = func ( exc ) <EOL> if rv is not None : <EOL> return rv <EOL> request_tearing_down . send ( self ) <EOL> def request_context ( self , environ ) : <EOL> """<STR_LIT>""" <EOL> return RequestContext ( self , environ ) <EOL> def test_request_context ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> from flask . testing import make_test_environ_builder <EOL> builder = make_test_environ_builder ( self , * args , ** kwargs ) <EOL> try : <EOL> return self . request_context ( builder . get_environ ( ) ) <EOL> finally : <EOL> builder . close ( ) <EOL> def wsgi_app ( self , environ , start_response ) : <EOL> """<STR_LIT>""" <EOL> with self . request_context ( environ ) : <EOL> try : <EOL> response = self . full_dispatch_request ( ) <EOL> except Exception , e : <EOL> response = self . make_response ( self . handle_exception ( e ) ) <EOL> return response ( environ , start_response ) <EOL> @ property <EOL> def modules ( self ) : <EOL> from warnings import warn <EOL> warn ( DeprecationWarning ( '<STR_LIT>' <EOL> '<STR_LIT>' ) , stacklevel = <NUM_LIT:2> ) <EOL> return self . blueprints <EOL> def __call__ ( self , environ , start_response ) : <EOL> """<STR_LIT>""" <EOL> return self . wsgi_app ( environ , start_response ) </s>
