def error_handler(self, view):
"""Register a function that will generate the response for CSRF errors.
.. deprecated:: 0.14
Use the standard Flask error system with
``@app.errorhandler(CSRFError)`` instead. This will be removed in
version 1.0.
The function will be passed one argument, ``reason``. By default it will
raise a :class:`~flask_wtf.csrf.CSRFError`. ::
@csrf.error_handler
def csrf_error(reason):
return render_template('error.html', reason=reason)
Due to historical reasons, the function may either return a response
or raise an exception with :func:`flask.abort`.
"""
warnings.warn(FlaskWTFDeprecationWarning(
'"@csrf.error_handler" is deprecated. Use the standard Flask error '
'system with "@app.errorhandler(CSRFError)" instead. This will be'
'removed in 1.0.'
), stacklevel=2)
@wraps(view)
def handler(reason):
response = current_app.make_response(view(reason))
raise CSRFError(response.get_data(as_text=True), response=response)
self._error_response = handler
return view
python类make_response()的实例源码
def error_handler(self, view):
"""Register a function that will generate the response for CSRF errors.
.. deprecated:: 0.14
Use the standard Flask error system with
``@app.errorhandler(CSRFError)`` instead. This will be removed in
version 1.0.
The function will be passed one argument, ``reason``. By default it will
raise a :class:`~flask_wtf.csrf.CSRFError`. ::
@csrf.error_handler
def csrf_error(reason):
return render_template('error.html', reason=reason)
Due to historical reasons, the function may either return a response
or raise an exception with :func:`flask.abort`.
"""
warnings.warn(FlaskWTFDeprecationWarning(
'"@csrf.error_handler" is deprecated. Use the standard Flask error '
'system with "@app.errorhandler(CSRFError)" instead. This will be'
'removed in 1.0.'
), stacklevel=2)
@wraps(view)
def handler(reason):
response = current_app.make_response(view(reason))
raise CSRFError(response.get_data(as_text=True), response=response)
self._error_response = handler
return view
def error_handler(self, view):
"""Register a function that will generate the response for CSRF errors.
.. deprecated:: 0.14
Use the standard Flask error system with
``@app.errorhandler(CSRFError)`` instead. This will be removed in
version 1.0.
The function will be passed one argument, ``reason``. By default it will
raise a :class:`~flask_wtf.csrf.CSRFError`. ::
@csrf.error_handler
def csrf_error(reason):
return render_template('error.html', reason=reason)
Due to historical reasons, the function may either return a response
or raise an exception with :func:`flask.abort`.
"""
warnings.warn(FlaskWTFDeprecationWarning(
'"@csrf.error_handler" is deprecated. Use the standard Flask error '
'system with "@app.errorhandler(CSRFError)" instead. This will be'
'removed in 1.0.'
), stacklevel=2)
@wraps(view)
def handler(reason):
response = current_app.make_response(view(reason))
raise CSRFError(response.get_data(as_text=True), response=response)
self._error_response = handler
return view
def error_handler(self, view):
"""Register a function that will generate the response for CSRF errors.
.. deprecated:: 0.14
Use the standard Flask error system with
``@app.errorhandler(CSRFError)`` instead. This will be removed in
version 1.0.
The function will be passed one argument, ``reason``. By default it will
raise a :class:`~flask_wtf.csrf.CSRFError`. ::
@csrf.error_handler
def csrf_error(reason):
return render_template('error.html', reason=reason)
Due to historical reasons, the function may either return a response
or raise an exception with :func:`flask.abort`.
"""
warnings.warn(FlaskWTFDeprecationWarning(
'"@csrf.error_handler" is deprecated. Use the standard Flask error '
'system with "@app.errorhandler(CSRFError)" instead. This will be'
'removed in 1.0.'
), stacklevel=2)
@wraps(view)
def handler(reason):
response = current_app.make_response(view(reason))
raise CSRFError(response.get_data(as_text=True), response=response)
self._error_response = handler
return view
def error_handler(self, view):
"""Register a function that will generate the response for CSRF errors.
.. deprecated:: 0.14
Use the standard Flask error system with
``@app.errorhandler(CSRFError)`` instead. This will be removed in
version 1.0.
The function will be passed one argument, ``reason``. By default it will
raise a :class:`~flask_wtf.csrf.CSRFError`. ::
@csrf.error_handler
def csrf_error(reason):
return render_template('error.html', reason=reason)
Due to historical reasons, the function may either return a response
or raise an exception with :func:`flask.abort`.
"""
warnings.warn(FlaskWTFDeprecationWarning(
'"@csrf.error_handler" is deprecated. Use the standard Flask error '
'system with "@app.errorhandler(CSRFError)" instead. This will be'
'removed in 1.0.'
), stacklevel=2)
@wraps(view)
def handler(reason):
response = current_app.make_response(view(reason))
raise CSRFError(response.get_data(as_text=True), response=response)
self._error_response = handler
return view
def error_handler(self, view):
"""Register a function that will generate the response for CSRF errors.
.. deprecated:: 0.14
Use the standard Flask error system with
``@app.errorhandler(CSRFError)`` instead. This will be removed in
version 1.0.
The function will be passed one argument, ``reason``. By default it will
raise a :class:`~flask_wtf.csrf.CSRFError`. ::
@csrf.error_handler
def csrf_error(reason):
return render_template('error.html', reason=reason)
Due to historical reasons, the function may either return a response
or raise an exception with :func:`flask.abort`.
"""
warnings.warn(FlaskWTFDeprecationWarning(
'"@csrf.error_handler" is deprecated. Use the standard Flask error '
'system with "@app.errorhandler(CSRFError)" instead. This will be'
'removed in 1.0.'
), stacklevel=2)
@wraps(view)
def handler(reason):
response = current_app.make_response(view(reason))
raise CSRFError(response.get_data(as_text=True), response=response)
self._error_response = handler
return view
def error_handler(self, view):
"""Register a function that will generate the response for CSRF errors.
.. deprecated:: 0.14
Use the standard Flask error system with
``@app.errorhandler(CSRFError)`` instead. This will be removed in
version 1.0.
The function will be passed one argument, ``reason``. By default it will
raise a :class:`~flask_wtf.csrf.CSRFError`. ::
@csrf.error_handler
def csrf_error(reason):
return render_template('error.html', reason=reason)
Due to historical reasons, the function may either return a response
or raise an exception with :func:`flask.abort`.
"""
warnings.warn(FlaskWTFDeprecationWarning(
'"@csrf.error_handler" is deprecated. Use the standard Flask error '
'system with "@app.errorhandler(CSRFError)" instead. This will be'
'removed in 1.0.'
), stacklevel=2)
@wraps(view)
def handler(reason):
response = current_app.make_response(view(reason))
raise CSRFError(response.get_data(as_text=True), response=response)
self._error_response = handler
return view
def error_handler(self, view):
"""Register a function that will generate the response for CSRF errors.
.. deprecated:: 0.14
Use the standard Flask error system with
``@app.errorhandler(CSRFError)`` instead. This will be removed in
version 1.0.
The function will be passed one argument, ``reason``. By default it will
raise a :class:`~flask_wtf.csrf.CSRFError`. ::
@csrf.error_handler
def csrf_error(reason):
return render_template('error.html', reason=reason)
Due to historical reasons, the function may either return a response
or raise an exception with :func:`flask.abort`.
"""
warnings.warn(FlaskWTFDeprecationWarning(
'"@csrf.error_handler" is deprecated. Use the standard Flask error '
'system with "@app.errorhandler(CSRFError)" instead. This will be'
'removed in 1.0.'
), stacklevel=2)
@wraps(view)
def handler(reason):
response = current_app.make_response(view(reason))
raise CSRFError(response.get_data(as_text=True), response=response)
self._error_response = handler
return view
def build_tar(namespace, package_name, release, media_type):
reponame = repo_name(namespace, package_name)
k = _build(reponame, release, media_type)
resp = current_app.make_response(k.build_tar())
resp.mimetype = 'application/tar'
resp.headers['Content-Disposition'] = 'filename="%s_%s.tar.gz"' % (k.name.replace("/", "_"),
k.version)
return resp
def _pull(data, json_format=True):
if json_format:
resp = jsonify(data)
else:
resp = current_app.make_response(b64decode(data['blob']))
resp.headers['Content-Disposition'] = data['filename']
resp.mimetype = 'application/x-gzip'
return resp
def list_packages():
values = getvalues()
namespace = values.get('namespace', None)
result = appr.api.impl.registry.list_packages(namespace, Package, search=values.get(
'query', None), media_type=values.get('media_type', None))
resp = current_app.make_response(json.dumps(result))
resp.mimetype = 'application/json'
return resp
def list_channels(namespace, package_name):
reponame = repo_name(namespace, package_name)
result = appr.api.impl.registry.list_channels(reponame, Channel)
resp = current_app.make_response(json.dumps(result))
resp.mimetype = 'application/json'
return resp
def build_tar(namespace, package_name, release, media_type):
reponame = repo_name(namespace, package_name)
k = _build(reponame, release, media_type)
resp = current_app.make_response(k.build_tar())
resp.mimetype = 'application/tar'
resp.headers['Content-Disposition'] = 'filename="%s_%s.tar.gz"' % (k.name.replace("/", "_"),
k.version)
return resp