mirror of
https://github.com/yawaflua/Flask-Discord.git
synced 2025-12-10 12:29:30 +02:00
Refactor and improve jwt state manager
This commit is contained in:
@@ -1,10 +1,37 @@
|
||||
"""Few utility functions and decorators."""
|
||||
|
||||
import functools
|
||||
|
||||
from . import exceptions
|
||||
from flask import current_app
|
||||
|
||||
|
||||
class JSONBool(object):
|
||||
|
||||
def __init__(self, value):
|
||||
self.value = bool(value)
|
||||
|
||||
def __bool__(self):
|
||||
return self.value
|
||||
|
||||
def __str__(self):
|
||||
return "true" if self else "false"
|
||||
|
||||
@classmethod
|
||||
def from_string(cls, value):
|
||||
if value.lower() == "true":
|
||||
return cls(True)
|
||||
if value.lower() == "false":
|
||||
return cls(False)
|
||||
raise ValueError
|
||||
|
||||
|
||||
def json_bool(value):
|
||||
if isinstance(value, str):
|
||||
return str(JSONBool.from_string(value))
|
||||
return str(JSONBool(value))
|
||||
|
||||
|
||||
# Decorators.
|
||||
|
||||
def requires_authorization(view):
|
||||
|
||||
Reference in New Issue
Block a user