Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modifications for using Flask >=0.11 if available #1550

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions digits/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,12 +641,23 @@ def handle_error(e):
trace=trace,
), status_code


# Register this handler for all error codes
# flask>=0.11 only codes defined
# in werkzeug default_exceptions are valid
# [400, 401, 403, 404, 405, 406, 408, 409, 410,
# 411, 412, 413, 414, 415, 416, 417, 418, 422,
# 423, 428, 429, 431, 451, 500, 501, 502, 503, 504, 505]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there's any value in enumerating all these status codes.

if str(flask.__version__) >= "0.11":
for code in HTTP_STATUS_CODES:
if code in werkzeug.exceptions.default_exceptions:
app.register_error_handler(code, handle_error)
# Register this handler for all error codes
# Necessary for flask<=0.10.1
for code in HTTP_STATUS_CODES:
if code not in [301]:
app.register_error_handler(code, handle_error)

else:
for code in HTTP_STATUS_CODES:
if code not in [301]:
app.register_error_handler(code, handle_error)
# File serving


Expand Down
6 changes: 5 additions & 1 deletion digits/webapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
import os

import flask
from flask.ext.socketio import SocketIO
try:
from flask_socketio import SocketIO
except ImportError:
from flask.ext.socketio import SocketIO

from gevent import monkey
monkey.patch_all()

Expand Down