Upgrade Flask, Flask-SQLAlchemy, Flask-WTF, Flask-Babel, Flask-Security-Too, WTForms, Werkzeug and keep backward compatibility with Python 3.7

This commit is contained in:
Aditya Toshniwal
2023-11-03 18:19:01 +05:30
committed by GitHub
parent 5f3965ff0a
commit 96fccd28a9
23 changed files with 73 additions and 163 deletions

View File

@@ -9,12 +9,13 @@
import re
import flask
from flask import current_app, request, session, testing
from flask import current_app, testing
from werkzeug.datastructures import Headers
from werkzeug.test import EnvironBuilder
from flask_wtf.csrf import generate_csrf
import config
import sys
class RequestShim():
@@ -26,9 +27,17 @@ class RequestShim():
def set_cookie(self, key, value='', *args, **kwargs):
"Set the cookie on the Flask test client."
server_name = current_app.config["SERVER_NAME"] or "localhost"
if sys.version_info <= (3, 7, 9999):
server_name = current_app.config["SERVER_NAME"] or "localhost"
return self.client.set_cookie(
server_name, key=key, value=value, *args, **kwargs
)
if kwargs['domain'] is None:
kwargs['domain'] = current_app.config["SERVER_NAME"] or "localhost"
return self.client.set_cookie(
server_name, key=key, value=value, *args, **kwargs
key=key, value=value, *args, **kwargs
)
def delete_cookie(self, key, *args, **kwargs):
@@ -90,8 +99,14 @@ class TestClient(testing.FlaskClient):
# this test client, such as the secure cookie that
# powers `flask.session`,
# and make a test request context that has those cookies in it.
environ_overrides = {}
self.cookie_jar.inject_wsgi(environ_overrides)
environ_overrides = {
'wsgi.url_scheme': ''
}
if sys.version_info <= (3, 7, 9999):
self.cookie_jar.inject_wsgi(environ_overrides)
else:
self._add_cookies_to_wsgi(environ_overrides)
with self.app.test_request_context():
# Now, we call Flask-WTF's method of generating a CSRF token...
csrf_token = generate_csrf()