diff --git a/setup.py b/setup.py index ba2bf0c..5e4251b 100755 --- a/setup.py +++ b/setup.py @@ -1,13 +1,13 @@ #!/usr/bin/python -import sys import os import subprocess - -from setuptools import setup, find_packages -from setuptools.command.install_lib import install_lib as _install_lib +import sys +from distutils.cmd import Command from distutils.command.build import build as _build from distutils.command.sdist import sdist -from distutils.cmd import Command + +from setuptools import find_packages, setup +from setuptools.command.install_lib import install_lib as _install_lib class compile_translations(Command): @@ -60,7 +60,7 @@ class install_lib(_install_lib): def get_version(): if os.path.exists('VERSION'): - with open('VERSION', 'r') as v: + with open('VERSION') as v: return v.read() if os.path.exists('.git'): p = subprocess.Popen( diff --git a/src/authentic2_auth_fedict/__init__.py b/src/authentic2_auth_fedict/__init__.py index c9649ea..5fc18e4 100644 --- a/src/authentic2_auth_fedict/__init__.py +++ b/src/authentic2_auth_fedict/__init__.py @@ -17,8 +17,8 @@ import json import django.apps -from django.utils.translation import ugettext_lazy as _ from django.contrib.auth.signals import user_logged_in +from django.utils.translation import ugettext_lazy as _ class AppConfig(django.apps.AppConfig): @@ -39,7 +39,7 @@ class AppConfig(django.apps.AppConfig): default_app_config = 'authentic2_auth_fedict.AppConfig' -class Plugin(object): +class Plugin: def get_before_urls(self): from . import urls diff --git a/src/authentic2_auth_fedict/adapters.py b/src/authentic2_auth_fedict/adapters.py index 6979f25..e040ea4 100644 --- a/src/authentic2_auth_fedict/adapters.py +++ b/src/authentic2_auth_fedict/adapters.py @@ -20,19 +20,16 @@ import logging import os import time +import lasso +import mellon.utils as mellon_utils import requests - +from authentic2.a2_rbac.utils import get_default_ou +from authentic2.models import Attribute from django.conf import settings from django.contrib.auth import get_user_model from django.core.files.storage import default_storage from django.utils.encoding import force_bytes, force_text - -import lasso - from mellon.adapters import DefaultAdapter, app_settings -import mellon.utils as mellon_utils -from authentic2.models import Attribute -from authentic2.a2_rbac.utils import get_default_ou try: import authentic2.utils.misc as a2_utils_misc @@ -95,7 +92,7 @@ class AuthenticAdapter(DefaultAdapter): saml_attributes['name_id_content_orig'] = saml_attributes['name_id_content'] saml_attributes['name_id_content'] = saml_attributes['urn:be:fedict:iam:attr:fedid'][0] saml_attributes['name_id_format'] = lasso.SAML2_NAME_IDENTIFIER_FORMAT_UNSPECIFIED - user = super(AuthenticAdapter, self).lookup_user(idp, saml_attributes) + user = super().lookup_user(idp, saml_attributes) if not user.ou_id: user.ou = get_default_ou() user.save() @@ -164,7 +161,7 @@ class AuthenticAdapter(DefaultAdapter): pass def provision_attribute(self, user, idp, saml_attributes): - super(AuthenticAdapter, self).provision_attribute(user, idp, saml_attributes) + super().provision_attribute(user, idp, saml_attributes) if not user.email: # make sure the account is not usable for now user.is_active = False diff --git a/src/authentic2_auth_fedict/app_settings.py b/src/authentic2_auth_fedict/app_settings.py index e03a395..fc62c4c 100644 --- a/src/authentic2_auth_fedict/app_settings.py +++ b/src/authentic2_auth_fedict/app_settings.py @@ -15,7 +15,7 @@ # along with this program. If not, see . -class AppSettings(object): +class AppSettings: '''Thanks django-allauth''' __SENTINEL = object() diff --git a/src/authentic2_auth_fedict/authenticators.py b/src/authentic2_auth_fedict/authenticators.py index 1725c34..bd83e33 100644 --- a/src/authentic2_auth_fedict/authenticators.py +++ b/src/authentic2_auth_fedict/authenticators.py @@ -14,13 +14,11 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from django.template.loader import render_to_string -from django.shortcuts import render -from django.utils.translation import ugettext_lazy as _ - -from mellon.utils import get_idp, get_idps - from authentic2.authenticators import BaseAuthenticator +from django.shortcuts import render +from django.template.loader import render_to_string +from django.utils.translation import ugettext_lazy as _ +from mellon.utils import get_idp, get_idps try: from authentic2.utils import redirect_to_login diff --git a/src/authentic2_auth_fedict/fields.py b/src/authentic2_auth_fedict/fields.py index 418f653..6ed89e5 100644 --- a/src/authentic2_auth_fedict/fields.py +++ b/src/authentic2_auth_fedict/fields.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # authentic2_auth_fedict - Fedict authentication for Authentic # Copyright (C) 2016 Entr'ouvert # @@ -16,20 +15,19 @@ # along with this program. If not, see . import re -import requests import time from urllib.parse import urljoin +import requests from django import forms from django.conf import settings from django.utils.translation import ugettext_lazy as _ - from gadjo.templatetags.gadjo import xstatic class NrnField(forms.CharField): def validate(self, value): - super(NrnField, self).validate(value) + super().validate(value) if not value: return try: @@ -62,7 +60,7 @@ class DateField(forms.CharField): widget = DateWidget def validate(self, value): - super(DateField, self).validate(value) + super().validate(value) if not value: return for format_string in ('%d/%m/%Y', '%Y-%m-%d'): @@ -133,7 +131,7 @@ class CountryField(forms.CharField): class NumHouseField(forms.CharField): def validate(self, value): - super(NumHouseField, self).validate(value) + super().validate(value) if not value: return try: @@ -145,11 +143,11 @@ class NumHouseField(forms.CharField): class NumPhoneField(forms.CharField): def validate(self, value): - super(NumPhoneField, self).validate(value) + super().validate(value) if not value: return try: - if not re.match("^(0|\\+|00)(\d{8,})", value): + if not re.match("^(0|\\+|00)(\\d{8,})", value): raise ValueError() except ValueError: raise forms.ValidationError(getattr(settings, 'A2_NUMPHONE_ERROR_MESSAGE', _('Invalid format'))) diff --git a/src/authentic2_auth_fedict/urls.py b/src/authentic2_auth_fedict/urls.py index 4db121e..ddb6451 100644 --- a/src/authentic2_auth_fedict/urls.py +++ b/src/authentic2_auth_fedict/urls.py @@ -14,7 +14,7 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from django.conf.urls import url, include +from django.conf.urls import include, url from . import views diff --git a/src/authentic2_auth_fedict/views.py b/src/authentic2_auth_fedict/views.py index d25a0af..ad26f10 100644 --- a/src/authentic2_auth_fedict/views.py +++ b/src/authentic2_auth_fedict/views.py @@ -14,15 +14,15 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -import urllib.parse import random +import urllib.parse from django.conf import settings from django.core import signing -from django.urls import reverse from django.db import transaction from django.http import HttpResponseRedirect from django.shortcuts import resolve_url +from django.urls import reverse from django.views.decorators.csrf import csrf_exempt from django.views.generic import View @@ -65,7 +65,7 @@ class LoginView(mellon.views.LoginView): return HttpResponseRedirect(a2_utils_misc.build_activation_url(request, **data)) user.is_active = True user.save() - return super(LoginView, self).authenticate(request, login, attributes) + return super().authenticate(request, login, attributes) login = transaction.non_atomic_requests(csrf_exempt(LoginView.as_view()))