Tighten the types for _normalize_token; include werkzeug wrappers.

This commit is contained in:
voussoir 2018-01-15 18:39:40 -08:00
parent 5e6f3d96b1
commit 8a1f2c65f9

View file

@ -13,8 +13,16 @@ def _generate_token(length=32):
return token return token
def _normalize_token(token): def _normalize_token(token):
if isinstance(token, flask.Request): if isinstance(token, (flask.Request, werkzeug.wrappers.Request, werkzeug.local.LocalProxy)):
token = token.cookies.get('etiquette_session', None) request = token
token = request.cookies.get('etiquette_session', None)
if token is None:
message = 'Cannot normalize token for request with no etiquette_session header.'
raise TypeError(message, request)
elif isinstance(token, str):
pass
else:
raise TypeError('Unsupported token normalization', type(token))
return token return token