<s> from flask import _app_ctx_stack , _request_ctx_stack <EOL> from werkzeug . exceptions import NotFound <EOL> from werkzeug . urls import url_parse <EOL> def route_from ( url , method = None ) : <EOL> appctx = _app_ctx_stack . top <EOL> reqctx = _request_ctx_stack . top <EOL> if appctx is None : <EOL> raise RuntimeError ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> if reqctx is not None : <EOL> url_adapter = reqctx . url_adapter <EOL> else : <EOL> url_adapter = appctx . url_adapter <EOL> if url_adapter is None : <EOL> raise RuntimeError ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> parsed_url = url_parse ( url ) <EOL> if parsed_url . netloc is not "<STR_LIT>" and parsed_url . netloc != url_adapter . server_name : <EOL> raise NotFound ( ) <EOL> return url_adapter . match ( parsed_url . path , method ) <EOL> def unpack ( value ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( value , tuple ) : <EOL> return value , <NUM_LIT:200> , { } <EOL> try : <EOL> data , code , headers = value <EOL> return data , code , headers <EOL> except ValueError : <EOL> pass <EOL> try : <EOL> data , code = value <EOL> return data , code , { } <EOL> except ValueError : <EOL> pass <EOL> return value , <NUM_LIT:200> , { } <EOL> def get_value ( key , obj , default ) : <EOL> if hasattr ( obj , '<STR_LIT>' ) : <EOL> try : <EOL> return obj [ key ] <EOL> except ( IndexError , TypeError , KeyError ) : <EOL> pass <EOL> return getattr ( obj , key , default ) <EOL> class AttributeDict ( dict ) : <EOL> __getattr__ = dict . __getitem__ <EOL> __setattr__ = dict . __setitem__ </s>
