Skip to content

Commit

Permalink
fix: indendtation for async_action function wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
mkhatri1 committed Aug 8, 2020
1 parent 6d473cf commit c6f2762
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions gavel/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,35 @@
asyncio.set_event_loop(loop)

def async_action(f):
@wraps(f)
def wrapped(*args, **kwargs):
return loop.run_until_complete(f(*args, **kwargs))
return wrapped
@wraps(f)
def wrapped(*args, **kwargs):
return loop.run_until_complete(f(*args, **kwargs))
return wrapped


def async_future(f):
@wraps(f)
def wrapped(*args, **kwargs):
return asyncio.Future(f(*args, **kwargs))
return wrapped


sendgrid_url = "https://api.sendgrid.com/v3/mail/send"


def gen_secret(length):
return base64.b32encode(os.urandom(length))[:length].decode('utf8').lower()


def check_auth(username, password):
return username == 'admin' and password == settings.ADMIN_PASSWORD


def authenticate():
return Response('Access denied.', 401,
{'WWW-Authenticate': 'Basic realm="Login Required"'})


def requires_auth(f):
@wraps(f)
def decorated(*args, **kwargs):
Expand All @@ -56,22 +62,26 @@ def decorated(*args, **kwargs):
return f(*args, **kwargs)
return decorated


def data_to_csv_string(data):
output = io.StringIO()
writer = csv.writer(output)
writer.writerows(data)
return output.getvalue()


def data_from_csv_string(string):
data_input = io.StringIO(string)
reader = csv.reader(data_input)
return list(reader)


def get_paragraphs(message):
paragraphs = re.split(r'\n\n+', message)
paragraphs = [i.replace('\n', ' ') for i in paragraphs if i]
return paragraphs


@celery.task(name='utils.send_emails')
def send_emails(emails):
if settings.EMAIL_PROVIDER not in ["smtp", "sendgrid", "mailgun"]:
Expand Down Expand Up @@ -167,9 +177,9 @@ async def mailgun_send_email(to_address, subject, body):
api_url,
auth=("api", mailgun_key),
data={"from": settings.EMAIL_FROM,
"to": [to_address],
"subject": subject,
"text": body})
"to": [to_address],
"subject": subject,
"text": body})
return response

def render_markdown(content):
Expand Down

0 comments on commit c6f2762

Please sign in to comment.