當前位置: 首頁>>代碼示例>>Python>>正文


Python routing.BuildError方法代碼示例

本文整理匯總了Python中werkzeug.routing.BuildError方法的典型用法代碼示例。如果您正苦於以下問題:Python routing.BuildError方法的具體用法?Python routing.BuildError怎麽用?Python routing.BuildError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在werkzeug.routing的用法示例。


在下文中一共展示了routing.BuildError方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: handle_url_build_error

# 需要導入模塊: from werkzeug import routing [as 別名]
# 或者: from werkzeug.routing import BuildError [as 別名]
def handle_url_build_error(self, error, endpoint, values):
        """Handle :class:`~werkzeug.routing.BuildError` on :meth:`url_for`.
        """
        exc_type, exc_value, tb = sys.exc_info()
        for handler in self.url_build_error_handlers:
            try:
                rv = handler(error, endpoint, values)
                if rv is not None:
                    return rv
            except BuildError as e:
                # make error available outside except block (py3)
                error = e

        # At this point we want to reraise the exception.  If the error is
        # still the same one we can reraise it with the original traceback,
        # otherwise we raise it from here.
        if error is exc_value:
            reraise(exc_type, exc_value, tb)
        raise error 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:21,代碼來源:app.py

示例2: default_unauthz_handler

# 需要導入模塊: from werkzeug import routing [as 別名]
# 或者: from werkzeug.routing import BuildError [as 別名]
def default_unauthz_handler(func, params):
    unauthz_message, unauthz_message_type = get_message("UNAUTHORIZED")
    if _security._want_json(request):
        payload = json_error_response(errors=unauthz_message)
        return _security._render_json(payload, 403, None, None)
    view = config_value("UNAUTHORIZED_VIEW")
    if view:
        if callable(view):
            view = view()
        else:
            try:
                view = get_url(view)
            except BuildError:
                view = None
        do_flash(unauthz_message, unauthz_message_type)
        redirect_to = "/"
        if request.referrer and not request.referrer.split("?")[0].endswith(
            request.path
        ):
            redirect_to = request.referrer

        return redirect(view or redirect_to)
    abort(403) 
開發者ID:Flask-Middleware,項目名稱:flask-security,代碼行數:25,代碼來源:decorators.py

示例3: handle_url_build_error

# 需要導入模塊: from werkzeug import routing [as 別名]
# 或者: from werkzeug.routing import BuildError [as 別名]
def handle_url_build_error(self, error, endpoint, values):
        """Handle :class:`~werkzeug.routing.BuildError` on :meth:`url_for`.
        """
        exc_type, exc_value, tb = sys.exc_info()
        for handler in self.url_build_error_handlers:
            try:
                rv = handler(error, endpoint, values)
                if rv is not None:
                    return rv
            except BuildError as error:
                pass

        # At this point we want to reraise the exception.  If the error is
        # still the same one we can reraise it with the original traceback,
        # otherwise we raise it from here.
        if error is exc_value:
            reraise(exc_type, exc_value, tb)
        raise error 
開發者ID:chalasr,項目名稱:Flask-P2P,代碼行數:20,代碼來源:app.py

示例4: test_build_error_handler

# 需要導入模塊: from werkzeug import routing [as 別名]
# 或者: from werkzeug.routing import BuildError [as 別名]
def test_build_error_handler(self):
        app = flask.Flask(__name__)

        # Test base case, a URL which results in a BuildError.
        with app.test_request_context():
            self.assertRaises(BuildError, flask.url_for, 'spam')

        # Verify the error is re-raised if not the current exception.
        try:
            with app.test_request_context():
                flask.url_for('spam')
        except BuildError as err:
            error = err
        try:
            raise RuntimeError('Test case where BuildError is not current.')
        except RuntimeError:
            self.assertRaises(BuildError, app.handle_url_build_error, error, 'spam', {})

        # Test a custom handler.
        def handler(error, endpoint, values):
            # Just a test.
            return '/test_handler/'
        app.url_build_error_handlers.append(handler)
        with app.test_request_context():
            self.assert_equal(flask.url_for('spam'), '/test_handler/') 
開發者ID:chalasr,項目名稱:Flask-P2P,代碼行數:27,代碼來源:basic.py

示例5: seasonized_url

# 需要導入模塊: from werkzeug import routing [as 別名]
# 或者: from werkzeug.routing import BuildError [as 別名]
def seasonized_url(season_id: Union[int, str]) -> str:
    args = request.view_args.copy()
    if season_id == rotation.current_season_num():
        args.pop('season_id', None)
        endpoint = cast(str, request.endpoint).replace('seasons.', '')
    else:
        args['season_id'] = season_id
        prefix = '' if cast(str, request.endpoint).startswith('seasons.') else 'seasons.'
        endpoint = '{prefix}{endpoint}'.format(prefix=prefix, endpoint=request.endpoint)
    try:
        return url_for(endpoint, **args)
    except BuildError:
        return url_for(cast(str, request.endpoint)) 
開發者ID:PennyDreadfulMTG,項目名稱:Penny-Dreadful-Tools,代碼行數:15,代碼來源:view.py

示例6: test_lang_ignored_for_static

# 需要導入模塊: from werkzeug import routing [as 別名]
# 或者: from werkzeug.routing import BuildError [as 別名]
def test_lang_ignored_for_static(self):
        self.assertEqual(url_for('i18nbp.static', filename='test.jpg'),
                         '/static/test.jpg')
        with self.assertRaises(BuildError):
            url_for('i18nbp.static_redirect', filename='test.jpg') 
開發者ID:opendatateam,項目名稱:udata,代碼行數:7,代碼來源:test_i18n.py


注:本文中的werkzeug.routing.BuildError方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。