2424
2525TALISMAN_CONFIG = dict (
2626 # on heroku force https redirect
27- force_https = ' DYNO' in os .environ ,
27+ force_https = " DYNO" in os .environ ,
2828 force_https_permanent = False ,
2929 force_file_save = False ,
3030 frame_options = flask_talisman .talisman .SAMEORIGIN ,
3434 strict_transport_security_max_age = flask_talisman .talisman .ONE_YEAR_IN_SECS ,
3535 strict_transport_security_include_subdomains = True ,
3636 content_security_policy = {
37- ' default-src' : ' \' none\' ' ,
37+ " default-src" : "' none'" ,
3838 # unsafe-inline is needed for the Swagger UI
39- ' script-src' : ' \' self\' \ ' unsafe-inline\' ' ,
40- ' style-src' : ' \' self\' \ ' unsafe-inline\' ' ,
41- ' img-src' : ' \' self\' ' ,
42- ' connect-src' : ' \' self\' ' ,
39+ " script-src" : "' self' 'unsafe-inline'" ,
40+ " style-src" : "' self' 'unsafe-inline'" ,
41+ " img-src" : "' self'" ,
42+ " connect-src" : "' self'" ,
4343 },
4444 content_security_policy_report_uri = None ,
4545 content_security_policy_report_only = False ,
5050
5151def handle_default_exceptions (e ):
5252 error = {
53- ' type' : ' about:blank' ,
54- ' title' : str (e ),
55- ' status' : getattr (e , ' code' , 500 ),
56- ' detail' : getattr (e , ' description' , str (e )),
57- ' instance' : ' about:blank' ,
53+ " type" : " about:blank" ,
54+ " title" : str (e ),
55+ " status" : getattr (e , " code" , 500 ),
56+ " detail" : getattr (e , " description" , str (e )),
57+ " instance" : " about:blank" ,
5858 }
59- return flask .jsonify (error ), error [' status' ]
59+ return flask .jsonify (error ), error [" status" ]
6060
6161
6262def build_flask_app (project_name , app_name , openapi ):
63- '''
63+ """
6464 Create a new Flask backend application
6565 app_name is the Python application name, used as Flask import_name
6666 project_name is a "nice" name, used to identify the application
67- '''
68- assert os .path .exists (openapi ), ' Missing openapi file {}' .format (openapi )
69- logger .debug (' Initializing' , app = app_name , openapi = openapi )
67+ """
68+ assert os .path .exists (openapi ), " Missing openapi file {}" .format (openapi )
69+ logger .debug (" Initializing" , app = app_name , openapi = openapi )
7070
7171 # Start OpenAPI app
7272 app = connexion .App (import_name = app_name )
@@ -79,19 +79,21 @@ def build_flask_app(project_name, app_name, openapi):
7979
8080 # Enable wildcard CORS
8181 cors = flask_cors .CORS ()
82- cors .init_app (app .app , origins = ['*' ])
82+ cors .init_app (app .app , origins = ["*" ])
8383
8484 # Add exception Json renderer
8585 for code , exception in werkzeug .exceptions .default_exceptions .items ():
8686 app .app .register_error_handler (exception , handle_default_exceptions )
8787
8888 # Redirect root to API
89- app .add_url_rule ('/' , 'root' , lambda : flask .redirect (app .options .openapi_console_ui_path ))
89+ app .add_url_rule (
90+ "/" , "root" , lambda : flask .redirect (app .options .openapi_console_ui_path )
91+ )
9092
9193 # Dockerflow checks
92- app .add_url_rule (' /__heartbeat__' , view_func = heartbeat_response )
93- app .add_url_rule (' /__lbheartbeat__' , view_func = lbheartbeat_response )
94- app .add_url_rule (' /__version__' , view_func = get_version )
94+ app .add_url_rule (" /__heartbeat__" , view_func = heartbeat_response )
95+ app .add_url_rule (" /__lbheartbeat__" , view_func = lbheartbeat_response )
96+ app .add_url_rule (" /__version__" , view_func = get_version )
9597
96- logger .debug (' Initialized' , app = app .name )
98+ logger .debug (" Initialized" , app = app .name )
9799 return app
0 commit comments