diff options
Diffstat (limited to 'accounts/utils/__init__.py')
-rw-r--r-- | accounts/utils/__init__.py | 14 |
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) |