Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flask[async] compatibility #72

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions flask_discord/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from . import exceptions
from flask import current_app
import asyncio


class JSONBool(object):
Expand Down Expand Up @@ -41,11 +42,18 @@ def requires_authorization(view):
"""

# TODO: Add support to validate scopes.

@functools.wraps(view)
def wrapper(*args, **kwargs):
if not current_app.discord.authorized:
raise exceptions.Unauthorized
return view(*args, **kwargs)

return wrapper
if asyncio.iscoroutinefunction(view):

@functools.wraps(view)
async def wrapper(*args, **kwargs):
if not current_app.discord.authorized:
raise exceptions.Unauthorized
return await view(*args, **kwargs)
return wrapper
else:
@functools.wraps(view)
def wrapper(*args, **kwargs):
if not current_app.discord.authorized:
raise exceptions.Unauthorized
return view(*args, **kwargs)
return wrapper