summaryrefslogtreecommitdiffstats
path: root/accounts/utils/__init__.py
diff options
context:
space:
mode:
authorJonah BrĂ¼chert <jbb@kaidan.im>2024-03-28 06:22:55 +0100
committerJonah BrĂ¼chert <jbb@kaidan.im>2024-03-28 16:57:21 +0100
commita3f0c006b5fb5beab1704aad56777dcd98c42efb (patch)
tree2a2acb62303c25a299aea4030eff55bca7e28650 /accounts/utils/__init__.py
parentd5977387f3e6716cc7594dc872539ccd7f130524 (diff)
downloadweb-a3f0c006b5fb5beab1704aad56777dcd98c42efb.tar.gz
web-a3f0c006b5fb5beab1704aad56777dcd98c42efb.tar.bz2
web-a3f0c006b5fb5beab1704aad56777dcd98c42efb.zip
Add some type annotations
Diffstat (limited to 'accounts/utils/__init__.py')
-rw-r--r--accounts/utils/__init__.py14
1 files changed, 5 insertions, 9 deletions
diff --git a/accounts/utils/__init__.py b/accounts/utils/__init__.py
index 8d49363..6adf317 100644
--- a/accounts/utils/__init__.py
+++ b/accounts/utils/__init__.py
@@ -1,12 +1,14 @@
# -*- coding: utf-8 -*-
import importlib
from functools import wraps
-from flask import render_template, request
+from flask import render_template, request, Flask
from wtforms.validators import Regexp, ValidationError
+from typing import Optional
+
# using http://flask.pocoo.org/docs/patterns/viewdecorators/
-def templated(template=None):
+def templated(template: Optional[str] = None):
def templated_(f):
@wraps(f)
def templated__(*args, **kwargs):
@@ -24,12 +26,6 @@ def templated(template=None):
return templated_
-def ensure_utf8(s):
- if isinstance(s, str):
- s = s.encode('utf8')
- return s
-
-
class NotRegexp(Regexp):
"""
Like wtforms.validators.Regexp, but rejects data that DOES match the regex.
@@ -42,7 +38,7 @@ class NotRegexp(Regexp):
raise ValidationError(self.message)
-def get_backend(path, app):
+def get_backend(path: str, app: Flask):
module = path.rsplit(".", 1).pop()
class_name = '%sBackend' % module.title()
backend_class = getattr(importlib.import_module(path), class_name)