From 6c0818b4d60ba5cf58b15ebeab4bcb522e59a549 Mon Sep 17 00:00:00 2001 From: Sami Date: Thu, 30 Mar 2017 14:21:25 +0200 Subject: [PATCH 1/4] Modifications for using Flask >=0.11 if available --- digits/views.py | 18 ++++++++++++++---- digits/webapp.py | 6 +++++- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/digits/views.py b/digits/views.py index 6068cecc5..119da1775 100644 --- a/digits/views.py +++ b/digits/views.py @@ -642,11 +642,21 @@ def handle_error(e): ), 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] +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 diff --git a/digits/webapp.py b/digits/webapp.py index caea4f6dc..82ae71110 100644 --- a/digits/webapp.py +++ b/digits/webapp.py @@ -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() From b7b73f3237b25b93fde3c184fd189d06c5cef9a4 Mon Sep 17 00:00:00 2001 From: Sami Date: Thu, 30 Mar 2017 14:56:12 +0200 Subject: [PATCH 2/4] Fix lint warnings --- digits/views.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/digits/views.py b/digits/views.py index 119da1775..dad1ce9d0 100644 --- a/digits/views.py +++ b/digits/views.py @@ -644,19 +644,19 @@ def handle_error(e): # 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] +# [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] 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) + app.register_error_handler(code, handle_error) # Register this handler for all error codes # Necessary for flask<=0.10.1 else: for code in HTTP_STATUS_CODES: if code not in [301]: - app.register_error_handler(code,handle_error) + app.register_error_handler(code, handle_error) # File serving From e446396a057577efd4aac093e19a5234a9fa856c Mon Sep 17 00:00:00 2001 From: Sami Date: Thu, 30 Mar 2017 15:15:01 +0200 Subject: [PATCH 3/4] Fix lint warnings. --- digits/views.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/digits/views.py b/digits/views.py index dad1ce9d0..0876dbb3d 100644 --- a/digits/views.py +++ b/digits/views.py @@ -641,6 +641,7 @@ 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 @@ -656,7 +657,7 @@ def handle_error(e): else: for code in HTTP_STATUS_CODES: if code not in [301]: - app.register_error_handler(code, handle_error) + app.register_error_handler(code, handle_error) # File serving From eb5fe4aad1624f467eaaed6344176e24e2a55b29 Mon Sep 17 00:00:00 2001 From: Sami Kama Date: Thu, 30 Mar 2017 20:41:49 +0200 Subject: [PATCH 4/4] Removed comment listing html error codes --- digits/views.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/digits/views.py b/digits/views.py index 0876dbb3d..fb6fb6c9e 100644 --- a/digits/views.py +++ b/digits/views.py @@ -642,17 +642,13 @@ def handle_error(e): ), status_code -# Register this handler for all error codes -# flask>=0.11 only codes defined +# Register this handler for all error codes. +# In flask>=0.11 only codes that are 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] 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 else: for code in HTTP_STATUS_CODES: