2
2
import logging .config
3
3
import os
4
4
import tempfile
5
- from typing import Optional
5
+ from typing import Any , Optional , Tuple
6
6
7
7
import keyring
8
8
import sentry_sdk
9
- from flask import render_template , request , send_from_directory
9
+ from flask import Response , render_template , request , send_from_directory
10
10
from keyrings .cryptfile .cryptfile import CryptFileKeyring
11
11
from sentry_sdk .integrations .flask import FlaskIntegration
12
12
from werkzeug .utils import ImportStringError
@@ -63,7 +63,7 @@ def make_app() -> Application:
63
63
return app
64
64
65
65
66
- def configure_app (app : Application ):
66
+ def configure_app (app : Application ) -> None :
67
67
"""Load application configuration.
68
68
69
69
:param app: application object
@@ -80,7 +80,7 @@ def configure_app(app: Application):
80
80
app .config ['TESTING' ] = True
81
81
82
82
@app .route ('/attachment/<filename>' , endpoint = 'attachment' )
83
- def serve_attachment (filename ) :
83
+ def serve_attachment (filename : str ) -> Response :
84
84
kw = {
85
85
'as_attachment' : True ,
86
86
}
@@ -91,7 +91,7 @@ def serve_attachment(filename):
91
91
return send_from_directory (dir_name , filename , ** kw )
92
92
93
93
94
- def configure_logging_handler (app : Application ):
94
+ def configure_logging_handler (app : Application ) -> None :
95
95
"""Bind application logging to Gunicorn handler.
96
96
97
97
This is done only in production and only if Gunicorn logger has any
@@ -108,7 +108,7 @@ def configure_logging_handler(app: Application):
108
108
app .logger .setLevel (gunicorn_logger .level )
109
109
110
110
111
- def configure_database (_app : Application ):
111
+ def configure_database (_app : Application ) -> None :
112
112
"""Configure application database connectivity.
113
113
114
114
:param app: application object
@@ -143,15 +143,15 @@ def configure_database(_app: Application):
143
143
db .init (db_name , ** kw )
144
144
145
145
146
- def configure_hooks (app : Application ):
146
+ def configure_hooks (app : Application ) -> None :
147
147
"""Set up application lifetime hooks.
148
148
149
149
:param app: application object
150
150
:type app: Application
151
151
"""
152
152
153
153
@app .before_first_request
154
- def load_site_objects ():
154
+ def load_site_objects () -> None :
155
155
if os .getenv ('FLASK_ENV' ) == 'test' and not os .getenv ('SITE_JSON' ):
156
156
site = test_site ()
157
157
else :
@@ -161,16 +161,16 @@ def load_site_objects():
161
161
app .site = app .jinja_env .globals ['site' ] = site
162
162
163
163
@app .before_request
164
- def db_connect ():
164
+ def db_connect () -> None :
165
165
db .connect (reuse_if_open = True )
166
166
167
167
@app .teardown_request
168
- def db_close (exc ) :
168
+ def db_close (exc : Any ) -> None :
169
169
if not db .is_closed ():
170
170
db .close ()
171
171
172
172
173
- def configure_blueprints (app : Application ):
173
+ def configure_blueprints (app : Application ) -> None :
174
174
"""Register (mount) blueprint objects.
175
175
176
176
:param app: application object
@@ -182,7 +182,7 @@ def configure_blueprints(app: Application):
182
182
app .register_blueprint (user_bp , url_prefix = '/uzytkownik' )
183
183
184
184
185
- def configure_extensions (app : Application ):
185
+ def configure_extensions (app : Application ) -> None :
186
186
"""Register and configure framework extensions.
187
187
188
188
:param app: application object
@@ -202,7 +202,7 @@ def get_user(userid: str) -> Optional[User]: # pylint: disable=unused-variable
202
202
return User .get_or_none (User .pk == userid )
203
203
204
204
205
- def configure_templating (app : Application ):
205
+ def configure_templating (app : Application ) -> None :
206
206
"""Configure template system extensions.
207
207
208
208
:param app: application object
@@ -212,27 +212,27 @@ def configure_templating(app: Application):
212
212
app .jinja_env .filters .update (extra_filters ())
213
213
214
214
215
- def configure_error_handlers (app : Application ):
215
+ def configure_error_handlers (app : Application ) -> None :
216
216
"""Configure global error handlers.
217
217
218
218
:param app: application object
219
219
:type app: Application
220
220
"""
221
221
222
222
@app .errorhandler (403 )
223
- def forbidden_page (error ): # pylint: disable=unused-variable
223
+ def forbidden_page (_error : Any ) -> Tuple [ str , int ]:
224
224
return render_template ('errors/403.html' ), 403
225
225
226
226
@app .errorhandler (404 )
227
- def page_not_found (error ): # pylint: disable=unused-variable
227
+ def page_not_found (_error : Any ) -> Tuple [ str , int ]:
228
228
return render_template ('errors/404.html' ), 404
229
229
230
230
@app .errorhandler (500 )
231
- def server_error_page (error ): # pylint: disable=unused-variable
231
+ def server_error_page (_error : Any ) -> Tuple [ str , int ]:
232
232
return render_template ('errors/500.html' ), 500
233
233
234
234
235
- def configure_logging ():
235
+ def configure_logging () -> None :
236
236
"""Configure application logging on prod.
237
237
238
238
This configuration is overwritten if running under Gunicorn.
0 commit comments