Move REQUEST_TYPES, RESPONSE_TYPES to voussoirkit.flasktools.

This commit is contained in:
voussoir 2021-06-04 21:00:22 -07:00
parent 0012999744
commit 53e8030186
No known key found for this signature in database
GPG key ID: 5F7554F8C26DACCB
2 changed files with 4 additions and 6 deletions

View file

@ -174,7 +174,7 @@ def render_template(request, template_name, **kwargs):
**kwargs,
)
if not isinstance(response, sessions.RESPONSE_TYPES):
if not isinstance(response, flasktools.RESPONSE_TYPES):
response = flask.Response(response)
if new_theme is None:

View file

@ -1,22 +1,20 @@
import flask; from flask import request
import functools
import werkzeug.wrappers
import werkzeug.datastructures
from voussoirkit import cacheclass
from voussoirkit import flasktools
from voussoirkit import passwordy
import etiquette
SESSION_MAX_AGE = 86400
REQUEST_TYPES = (flask.Request, werkzeug.wrappers.Request, werkzeug.local.LocalProxy)
RESPONSE_TYPES = (flask.Response, werkzeug.wrappers.Response)
def _generate_token(length=32):
return passwordy.random_hex(length=length)
def _normalize_token(token):
if isinstance(token, REQUEST_TYPES):
if isinstance(token, flasktools.REQUEST_TYPES):
request = token
token = request.cookies.get('etiquette_session', None)
if token is None:
@ -81,7 +79,7 @@ class SessionManager:
session.maintain()
response = function(*args, **kwargs)
if not isinstance(response, RESPONSE_TYPES):
if not isinstance(response, flasktools.RESPONSE_TYPES):
response = flask.Response(response)
# Send the token back to the client