本文整理汇总了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
示例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)
示例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
示例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/')
示例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))
示例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')