mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-17 05:41:25 +02:00
Replaced pylint by ruff
This commit is contained in:
@@ -3,12 +3,12 @@
|
||||
repos:
|
||||
- repo: local
|
||||
hooks:
|
||||
- id: pylint
|
||||
name: pylint
|
||||
entry: pylint
|
||||
- id: ruff
|
||||
name: ruff
|
||||
entry: ruff
|
||||
language: system
|
||||
types: [python]
|
||||
args: ["-rn", "-sn", "--fail-under=5"]
|
||||
args: ["check"]
|
||||
- id: prettier
|
||||
name: prettier
|
||||
entry: prettier --config frontend/.prettierrc.json --write --ignore-unknown
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
from typing import List
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.auth import password_validation
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.shortcuts import get_object_or_404
|
||||
|
||||
@@ -240,9 +240,7 @@ class AdminGlobalParametersSerializer(serializers.Serializer):
|
||||
if not value:
|
||||
return value
|
||||
try:
|
||||
ip_addresses = [
|
||||
ipaddress.ip_network(v.strip()) for v in value.split() if v.strip()
|
||||
]
|
||||
[ipaddress.ip_network(v.strip()) for v in value.split() if v.strip()]
|
||||
except ValueError:
|
||||
raise serializers.ValidationError(
|
||||
_("This field only allows valid IP addresses (or networks)")
|
||||
|
||||
@@ -255,9 +255,7 @@ class AdminParametersForm(param_forms.AdminParametersForm):
|
||||
if not value:
|
||||
return value
|
||||
try:
|
||||
ip_addresses = [
|
||||
ipaddress.ip_network(v.strip()) for v in value.split() if v.strip()
|
||||
]
|
||||
[ipaddress.ip_network(v.strip()) for v in value.split() if v.strip()]
|
||||
except ValueError:
|
||||
raise forms.ValidationError(
|
||||
gettext_lazy("This field only allows valid IP addresses (or networks)")
|
||||
|
||||
@@ -205,7 +205,7 @@ def get_authoritative_server(domain, resolver=None):
|
||||
return str(first_answer.target)
|
||||
if hasattr(first_answer, "address"):
|
||||
return str(first_answer.address)
|
||||
except dns.resolver.NoAnswer as e:
|
||||
except dns.resolver.NoAnswer:
|
||||
dnsname = dnsname.parent()
|
||||
else:
|
||||
dnsname = dnsname.parent()
|
||||
|
||||
@@ -7,7 +7,6 @@ import os
|
||||
import progressbar
|
||||
from chardet.universaldetector import UniversalDetector
|
||||
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
from django.db import transaction
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from django.db import models, migrations
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
def rename_and_clean(apps, schema_editor):
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
"""Alarm related tests."""
|
||||
|
||||
from django.urls import reverse
|
||||
|
||||
from modoboa.lib.tests import ModoTestCase
|
||||
from ..factories import populate_database
|
||||
from ..models import Alarm, Domain
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
"""Import related views."""
|
||||
|
||||
import csv
|
||||
import io
|
||||
|
||||
from reversion import revisions as reversion
|
||||
|
||||
from django.contrib.auth.decorators import (
|
||||
@@ -10,15 +7,11 @@ from django.contrib.auth.decorators import (
|
||||
permission_required,
|
||||
user_passes_test,
|
||||
)
|
||||
from django.db import transaction
|
||||
from django.shortcuts import render
|
||||
from django.urls import reverse
|
||||
from django.utils.encoding import smart_str
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from modoboa.lib.exceptions import Conflict, ModoboaException
|
||||
from .. import lib
|
||||
from .. import signals
|
||||
from ..forms import ImportDataForm, ImportIdentitiesForm
|
||||
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ class CalendarsConfig(AppConfig):
|
||||
verbose_name = "Modoboa calendars"
|
||||
|
||||
def ready(self):
|
||||
from modoboa.calendars import handlers
|
||||
from modoboa.calendars import handlers # noqa
|
||||
from modoboa.calendars.app_settings import load_settings
|
||||
|
||||
load_settings()
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
|
||||
from importlib import import_module
|
||||
|
||||
from modoboa.lib.cryptutils import decrypt
|
||||
|
||||
|
||||
class CalendarBackend(object):
|
||||
"""Base backend class."""
|
||||
@@ -37,5 +35,4 @@ def get_backend(name, *args, **kwargs):
|
||||
|
||||
def get_backend_from_request(name, request, calendar=None):
|
||||
"""Return a backend instance from a request."""
|
||||
# password = decrypt(request.session["password"])
|
||||
return get_backend(name, request.user.email, request.auth, calendar=calendar)
|
||||
|
||||
@@ -7,7 +7,7 @@ class ModoboaContactsConfig(AppConfig):
|
||||
name = "modoboa.contacts"
|
||||
|
||||
def ready(self):
|
||||
from . import handlers
|
||||
from . import handlers # noqa
|
||||
from modoboa.contacts.app_settings import load_settings
|
||||
|
||||
load_settings()
|
||||
|
||||
@@ -339,7 +339,7 @@ class ImportTestCase(TestDataMixin, ModoTestCase):
|
||||
def test_import_from_outlook_auto(self):
|
||||
management.call_command("import_contacts", "user@test.com", self.path)
|
||||
address = models.EmailAddress.objects.get(address="toto@titi.com")
|
||||
phone = models.PhoneNumber.objects.get(number="12345678")
|
||||
models.PhoneNumber.objects.get(number="12345678")
|
||||
self.assertEqual(address.contact.first_name, "Toto Tata")
|
||||
self.assertEqual(address.contact.addressbook.user.email, "user@test.com")
|
||||
self.assertEqual(address.contact.address, "Street 1 Street 2")
|
||||
@@ -352,7 +352,7 @@ class ImportTestCase(TestDataMixin, ModoTestCase):
|
||||
backend="outlook",
|
||||
)
|
||||
address = models.EmailAddress.objects.get(address="toto@titi.com")
|
||||
phone = models.PhoneNumber.objects.get(number="12345678")
|
||||
models.PhoneNumber.objects.get(number="12345678")
|
||||
self.assertEqual(address.contact.first_name, "Toto Tata")
|
||||
self.assertEqual(address.contact.addressbook.user.email, "user@test.com")
|
||||
self.assertEqual(address.contact.address, "Street 1 Street 2")
|
||||
@@ -366,7 +366,7 @@ class ImportTestCase(TestDataMixin, ModoTestCase):
|
||||
carddav_password="Toto1234",
|
||||
)
|
||||
address = models.EmailAddress.objects.get(address="toto@titi.com")
|
||||
phone = models.PhoneNumber.objects.get(number="12345678")
|
||||
models.PhoneNumber.objects.get(number="12345678")
|
||||
self.assertEqual(address.contact.first_name, "Toto Tata")
|
||||
self.assertEqual(address.contact.addressbook.user.email, "user@test.com")
|
||||
self.assertEqual(address.contact.address, "Street 1 Street 2")
|
||||
|
||||
@@ -25,11 +25,11 @@ from . import serializers
|
||||
logger = logging.getLogger("modoboa.auth")
|
||||
|
||||
|
||||
def delete_cache_key(class_target, throttles, request):
|
||||
def delete_cache_key(class_target, throttles: list, request) -> None:
|
||||
"""Attempt to delete cache key from throttling on login/password reset success."""
|
||||
|
||||
for throttle in throttles:
|
||||
if type(throttle) == class_target:
|
||||
if isinstance(throttle, class_target):
|
||||
throttle.reset_cache(request)
|
||||
return
|
||||
|
||||
|
||||
@@ -680,7 +680,7 @@ class GeneralParametersForm(param_forms.AdminParametersForm):
|
||||
Doing so, we can use the django_auth_ldap module.
|
||||
"""
|
||||
try:
|
||||
import ldap
|
||||
import ldap # noqa
|
||||
|
||||
ldap_available = True
|
||||
except ImportError:
|
||||
|
||||
@@ -114,7 +114,7 @@ class DeployCommand(Command):
|
||||
if p.returncode:
|
||||
if output:
|
||||
print(
|
||||
"\n".join([l.decode() for l in output if l is not None]),
|
||||
"\n".join([line.decode() for line in output if line is not None]),
|
||||
file=sys.stderr,
|
||||
)
|
||||
print("%s failed, check your configuration" % cmd, file=sys.stderr)
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
"""Factories for core application."""
|
||||
|
||||
import base64
|
||||
|
||||
import factory
|
||||
|
||||
from django.contrib.auth.models import Group
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from django.db import models, migrations
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
@@ -6,7 +6,6 @@ from django.test.utils import override_settings
|
||||
|
||||
from modoboa.core import checks
|
||||
from modoboa.lib.tests import SimpleModoTestCase
|
||||
from modoboa.core.password_hashers.base import CRYPTHasher
|
||||
|
||||
|
||||
class CheckSessionCookieSecureTest(SimpleModoTestCase):
|
||||
|
||||
@@ -1,3 +1 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
|
||||
@@ -13,4 +13,4 @@ class DmarcConfig(AppConfig):
|
||||
|
||||
def ready(self):
|
||||
load_settings()
|
||||
from . import handlers
|
||||
from . import handlers # noqa
|
||||
|
||||
@@ -129,7 +129,7 @@ def import_report(content):
|
||||
else:
|
||||
print(f"Report skipped because of malformed data (empty {attr})")
|
||||
return
|
||||
value = setattr(report, "policy_{}".format(attr), node.text)
|
||||
setattr(report, "policy_{}".format(attr), node.text)
|
||||
report.save()
|
||||
for record in root.findall("record"):
|
||||
import_record(record, report)
|
||||
|
||||
@@ -161,9 +161,7 @@ def check_spf_syntax(record):
|
||||
for part in parts:
|
||||
if part == "":
|
||||
continue
|
||||
qualifier = None
|
||||
if part[0] in ["+", "-", "~", "?"]:
|
||||
qualifier = part[0]
|
||||
part = part[1:]
|
||||
if part == "all":
|
||||
continue
|
||||
|
||||
@@ -1,13 +1,8 @@
|
||||
"""Crypto related utilities."""
|
||||
|
||||
import base64
|
||||
import time
|
||||
|
||||
from cryptography.fernet import Fernet
|
||||
from cryptography.hazmat.backends import default_backend
|
||||
from cryptography.hazmat.primitives.twofactor import InvalidToken
|
||||
from cryptography.hazmat.primitives.twofactor.totp import TOTP
|
||||
from cryptography.hazmat.primitives.hashes import SHA1
|
||||
|
||||
from django.conf import settings
|
||||
from django.utils.crypto import get_random_string
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from django.db import models, migrations
|
||||
from django.db import migrations
|
||||
|
||||
APPLICATIONS = [
|
||||
("admin", "modoboa_admin"),
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from django.db import models, migrations
|
||||
from django.db import migrations
|
||||
|
||||
APPS = (
|
||||
("modoboa_admin", "admin"),
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from django.db import models, migrations
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
def move_language_preference(apps, schema_editor):
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from django.db import models, migrations
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from django.db import migrations, models
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
@@ -288,8 +288,8 @@ class ResellerTestCase(ResourceTestCase):
|
||||
self._create_domain("domain.tld")
|
||||
self._create_account("admin1@domain.tld", role="DomainAdmins")
|
||||
domadmin = User.objects.get(username="admin1@domain.tld")
|
||||
for l in ["mailboxes", "mailbox_aliases"]:
|
||||
self.assertEqual(domadmin.userobjectlimit_set.get(name=l).max_value, 0)
|
||||
for name in ["mailboxes", "mailbox_aliases"]:
|
||||
self.assertEqual(domadmin.userobjectlimit_set.get(name=name).max_value, 0)
|
||||
|
||||
def test_domain_admins_limit_from_domain_tpl(self):
|
||||
self.user.userobjectlimit_set.filter(name="domains").update(max_value=3)
|
||||
|
||||
@@ -73,4 +73,4 @@ class MaillogConfig(AppConfig):
|
||||
|
||||
def ready(self):
|
||||
load_maillog_settings()
|
||||
from . import handlers
|
||||
from . import handlers # noqa
|
||||
|
||||
@@ -4,7 +4,6 @@ from django.urls import reverse
|
||||
from django.dispatch import receiver
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from modoboa.admin import signals as admin_signals
|
||||
from modoboa.core import signals as core_signals
|
||||
from modoboa.parameters import tools as param_tools
|
||||
|
||||
|
||||
@@ -18,6 +18,6 @@ def date_to_timestamp(timetuple):
|
||||
try:
|
||||
local = time.strptime(date, fmt)
|
||||
except ValueError:
|
||||
print >> sys.stderr, "Error: failed to convert date and time"
|
||||
print("Error: failed to convert date and time", file=sys.stderr)
|
||||
return 0
|
||||
return int(time.mktime(local))
|
||||
|
||||
@@ -19,7 +19,6 @@ Predefined events are:
|
||||
"""
|
||||
|
||||
from datetime import datetime
|
||||
import io
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
|
||||
@@ -273,7 +273,7 @@ class MaillogParser:
|
||||
if not parser(log, host, pid, subprog):
|
||||
self._dprint("[parser] ignoring %r log: %r" % (prog, log))
|
||||
except AttributeError:
|
||||
self._dprint('[parser] no log handler for "%r": %r'.format(prog, log))
|
||||
self._dprint('[parser] no log handler for "%r": %r' % (prog, log))
|
||||
|
||||
def parse(self, logfile):
|
||||
"""Process the log file."""
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
"""PDF Credentials API v2 views."""
|
||||
|
||||
import os
|
||||
|
||||
from django.utils.translation import gettext as _
|
||||
from django.http import HttpResponse
|
||||
|
||||
from rest_framework import permissions
|
||||
|
||||
@@ -35,6 +35,6 @@ class PDFCredentialsConfig(AppConfig):
|
||||
verbose_name = "PDF credentials for Modoboa"
|
||||
|
||||
def ready(self):
|
||||
from . import handlers
|
||||
from . import handlers # noqa
|
||||
|
||||
load_pdfcredential_settings()
|
||||
|
||||
@@ -28,7 +28,7 @@ def password_updated(sender, account, password, created, **kwargs):
|
||||
return
|
||||
try:
|
||||
init_storage_dir()
|
||||
except InternalError as e:
|
||||
except InternalError:
|
||||
logger = logging.getLogger("modoboa.admin")
|
||||
logger.error(
|
||||
_(
|
||||
|
||||
@@ -74,7 +74,7 @@ def crypt_and_save_to_file(content, filename, length, chunksize=64 * 512):
|
||||
chunk += b" " * (16 - len(chunk) % 16)
|
||||
fp.write(encryptor.update(force_bytes(chunk)))
|
||||
fp.write(encryptor.finalize())
|
||||
except FileNotFoundError as e:
|
||||
except FileNotFoundError:
|
||||
logger = logging.getLogger("modoboa.admin")
|
||||
logger.error(
|
||||
_(
|
||||
|
||||
@@ -1,3 +1 @@
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
|
||||
@@ -2,13 +2,10 @@
|
||||
|
||||
import os
|
||||
import shutil
|
||||
import tempfile
|
||||
|
||||
from django.test import override_settings
|
||||
from django.urls import reverse
|
||||
|
||||
from modoboa.admin import factories
|
||||
from modoboa.core import models as core_models
|
||||
|
||||
from modoboa.lib.tests import ModoAPITestCase
|
||||
from modoboa.lib.exceptions import InternalError
|
||||
|
||||
@@ -141,7 +141,7 @@ class EventsTestCase(ModoTestCase):
|
||||
"""Test storage directory creation."""
|
||||
self.set_global_parameter("storage_dir", "/nonexistentdir")
|
||||
with self.assertLogs(logger="modoboa.admin", level="ERROR") as log:
|
||||
resp = self._create_account("leon@test.com")
|
||||
self._create_account("leon@test.com")
|
||||
self.assertIn(
|
||||
"ERROR:modoboa.admin:Failed to create PDF_credentials directory. "
|
||||
"Please check the permissions or the path.",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models, migrations
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
def move_aliases(apps, schema_editor):
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models, migrations
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
def remove_useless_aliases(apps, schema_editor):
|
||||
|
||||
@@ -13,7 +13,7 @@ from django.utils.formats import date_format
|
||||
|
||||
from modoboa.admin import factories as admin_factories, models as admin_models
|
||||
from modoboa.core.models import User
|
||||
from modoboa.lib.tests import ModoTestCase, ModoAPITestCase
|
||||
from modoboa.lib.tests import ModoTestCase
|
||||
from modoboa.transport import models as tr_models
|
||||
|
||||
from . import factories, models
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from django.db import models, migrations
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
+2
-2
@@ -19,10 +19,10 @@ classifiers = [
|
||||
"License :: OSI Approved :: ISC License (ISCL)",
|
||||
"Operating System :: OS Independent",
|
||||
"Programming Language :: Python :: 3",
|
||||
"Programming Language :: Python :: 3.8",
|
||||
"Programming Language :: Python :: 3.9",
|
||||
"Programming Language :: Python :: 3.10",
|
||||
"Programming Language :: Python :: 3.11",
|
||||
"Programming Language :: Python :: 3.12",
|
||||
"Topic :: Communications :: Email",
|
||||
"Topic :: Internet :: WWW/HTTP",
|
||||
]
|
||||
@@ -87,7 +87,7 @@ dev = [
|
||||
"django-debug-toolbar",
|
||||
"pre-commit",
|
||||
"black",
|
||||
"pylint",
|
||||
"ruff",
|
||||
"django-extensions",
|
||||
"Werkzeug",
|
||||
"pyOpenSSL"
|
||||
|
||||
Reference in New Issue
Block a user