]> Frank Brehm's Git Trees - pixelpark/pp-admin-tools.git/commitdiff
Make the linter happy with lib/pp_admintools/config/mail.py
authorFrank Brehm <frank.brehm@pixelpark.com>
Tue, 13 Jun 2023 16:18:11 +0000 (18:18 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Tue, 13 Jun 2023 16:18:11 +0000 (18:18 +0200)
lib/pp_admintools/config/dns_deploy_zones.py
lib/pp_admintools/config/mail.py

index 67949b7ed8b5b21d78b153407f4460bb1d0b2c51..62d25376bfa8504e92e816c5dc8df0a64912d59b 100644 (file)
@@ -45,7 +45,7 @@ class DnsDeployZonesConfigError(PdnsConfigError):
 # =============================================================================
 class DnsDeployZonesConfig(PdnsConfiguration):
     """
-    A class for providing a configuration for an arbitrary PowerDNS Application.
+    A class for providing a configuration for a dns-deploy-zones application.
 
     It provides also methods to read from configuration files.
     """
index a373de93ffa5a44303a85f28404cdc460dee2db7..fd616ed45112cbc1a7b4340fe72aa43685bc5ab4 100644 (file)
@@ -1,38 +1,34 @@
 #!/usr/bin/env python
 # -*- coding: utf-8 -*-
 """
+@summary: A module for providing a configuration for applications, which are sending mails.
+
 @author: Frank Brehm
 @contact: frank.brehm@pixelpark.com
 @copyright: © 2023 by Frank Brehm, Berlin
-@summary: A module for providing a configuration for applications,
-          which are sending mails
 """
 from __future__ import absolute_import
 
 # Standard module
+import copy
 import logging
 import re
-import copy
 
 # Third party modules
-
-# Own modules
-
+from fb_tools import MailAddress
 from fb_tools.common import is_sequence, to_bool
-
 from fb_tools.multi_config import DEFAULT_ENCODING
 
-from fb_tools import MailAddress
-
+# Own modules
+from . import PpBaseConfiguration
+from . import PpConfigurationError
+from .. import DEFAULT_CONFIG_DIR
+from .. import MAX_PORT_NUMBER
 from .. import __version__ as GLOBAL_VERSION
-from .. import MAX_PORT_NUMBER, DEFAULT_CONFIG_DIR
 from .. import pp
-
-from . import PpConfigurationError, PpBaseConfiguration
-
 from ..xlate import XLATOR
 
-__version__ = '0.2.4'
+__version__ = '0.2.5'
 LOG = logging.getLogger(__name__)
 
 _ = XLATOR.gettext
@@ -42,18 +38,14 @@ DEFAULT_DOMAIN = 'pixelpark.com'
 
 # =============================================================================
 class MailConfigError(PpConfigurationError):
-    """Base error class for all exceptions happened during
-    execution this configured application"""
+    """Base error class for all exceptions happened during execution a configured application."""
 
     pass
 
 
 # =============================================================================
 class MailConfiguration(PpBaseConfiguration):
-    """
-    A class for providing a configuration for an arbitrary PowerDNS Application
-    and methods to read it from configuration files.
-    """
+    """A class for providing a configuration for applications, which are sending mails."""
 
     whitespace_re = re.compile(r'(?:[,;]+|\s*[,;]*\s+)+')
 
@@ -63,7 +55,7 @@ class MailConfiguration(PpBaseConfiguration):
             append_appname_to_stems=True, additional_stems=None, config_dir=DEFAULT_CONFIG_DIR,
             additional_config_file=None, additional_cfgdirs=None, encoding=DEFAULT_ENCODING,
             ensure_privacy=False, raise_on_error=True, use_chardet=True, initialized=False):
-
+        """Initialize the MailConfiguration object."""
         add_stems = []
         if additional_stems:
             if is_sequence(additional_stems):
@@ -85,7 +77,7 @@ class MailConfiguration(PpBaseConfiguration):
             raise_on_error=raise_on_error, ensure_privacy=ensure_privacy, initialized=False,
         )
 
-        self.xmailer = "{a} (Admin Tools version {v})".format(
+        self.xmailer = '{a} (Admin Tools version {v})'.format(
             a=self.appname, v=GLOBAL_VERSION)
 
         if initialized:
@@ -94,7 +86,7 @@ class MailConfiguration(PpBaseConfiguration):
     # -----------------------------------------------------------
     @property
     def mail_cc_configured(self):
-        """Should there be used LDAPS for communicating with the LDAP server?"""
+        """Return, whether cc addresses are configured."""
         return self._mail_cc_configured
 
     @mail_cc_configured.setter
@@ -104,7 +96,7 @@ class MailConfiguration(PpBaseConfiguration):
     # -------------------------------------------------------------------------
     def as_dict(self, short=True):
         """
-        Transforms the elements of the object into a dict
+        Transform the elements of the object into a dict.
 
         @param short: don't include local properties in resulting dict.
         @type short: bool
@@ -112,7 +104,6 @@ class MailConfiguration(PpBaseConfiguration):
         @return: structure as dict
         @rtype:  dict
         """
-
         res = super(MailConfiguration, self).as_dict(short=short)
 
         res['mail_cc_configured'] = self.mail_cc_configured
@@ -120,8 +111,8 @@ class MailConfiguration(PpBaseConfiguration):
         return res
 
     # -------------------------------------------------------------------------
-    def eval(self):
-
+    def eval(self):                                                                 # noqa: A003
+        """Evaluate read configuration and storing it in object properties."""
         super(MailConfiguration, self).eval()
 
         if not self.mail_recipients:
@@ -132,7 +123,7 @@ class MailConfiguration(PpBaseConfiguration):
 
     # -------------------------------------------------------------------------
     def eval_section(self, section_name):
-
+        """Evaluate a particular configuration section."""
         super(MailConfiguration, self).eval_section(section_name)
         sn = section_name.lower()
 
@@ -144,7 +135,7 @@ class MailConfiguration(PpBaseConfiguration):
     def _eval_mail(self, section_name, section):
 
         if self.verbose > 2:
-            msg = _("Evaluating config section {!r}:").format(section_name)
+            msg = _('Evaluating config section {!r}:').format(section_name)
             LOG.debug(msg + '\n' + pp(section))
 
         self._eval_mail_from(section_name, section)
@@ -165,7 +156,7 @@ class MailConfiguration(PpBaseConfiguration):
             if MailAddress.valid_address(token):
                 result.append(token)
             else:
-                msg = _("Found invalid {what} {addr!r} in configuration.")
+                msg = _('Found invalid {what} {addr!r} in configuration.')
                 LOG.error(msg.format(what=what, addr=token))
 
         return result
@@ -189,8 +180,8 @@ class MailConfiguration(PpBaseConfiguration):
             if MailAddress.valid_address(val):
                 self.mail_from = val
             else:
-                msg = _("Found invalid {what} {addr!r} in configuration.")
-                LOG.error(msg.format(what=_("from address"), addr=val))
+                msg = _('Found invalid {what} {addr!r} in configuration.')
+                LOG.error(msg.format(what=_('from address'), addr=val))
 
     # -------------------------------------------------------------------------
     def _eval_mail_rcpt(self, section_name, section):
@@ -208,11 +199,11 @@ class MailConfiguration(PpBaseConfiguration):
                 continue
             if is_sequence(val):
                 for v in val:
-                    result = self._split_mailaddress_tokens(v, _("recipient mail address"))
+                    result = self._split_mailaddress_tokens(v, _('recipient mail address'))
                     if result:
                         self.mail_recipients += result
             else:
-                result = self._split_mailaddress_tokens(val, _("recipient mail address"))
+                result = self._split_mailaddress_tokens(val, _('recipient mail address'))
                 if result:
                     self.mail_recipients += result
 
@@ -234,11 +225,11 @@ class MailConfiguration(PpBaseConfiguration):
                 continue
             if is_sequence(val):
                 for v in val:
-                    result = self._split_mailaddress_tokens(v, _("cc mail address"))
+                    result = self._split_mailaddress_tokens(v, _('cc mail address'))
                     if result:
                         self.mail_cc += result
             else:
-                result = self._split_mailaddress_tokens(val, _("cc mail address"))
+                result = self._split_mailaddress_tokens(val, _('cc mail address'))
                 if result:
                     self.mail_cc += result
 
@@ -261,8 +252,8 @@ class MailConfiguration(PpBaseConfiguration):
             if MailAddress.valid_address(val):
                 self.reply_to = val
             else:
-                msg = _("Found invalid {what} {addr!r} in configuration.")
-                LOG.error(msg.format(what=_("reply to address"), addr=val))
+                msg = _('Found invalid {what} {addr!r} in configuration.')
+                LOG.error(msg.format(what=_('reply to address'), addr=val))
 
     # -------------------------------------------------------------------------
     def _eval_mail_method(self, section_name, section):
@@ -278,7 +269,7 @@ class MailConfiguration(PpBaseConfiguration):
                 continue
 
             if val not in self.valid_mail_methods:
-                msg = _("Found invalid mail method {!r} in configuration.")
+                msg = _('Found invalid mail method {!r} in configuration.')
                 LOG.error(msg.format(section[key]))
                 continue
 
@@ -312,12 +303,12 @@ class MailConfiguration(PpBaseConfiguration):
             try:
                 port = int(val)
             except (ValueError, TypeError) as e:
-                msg = _("Value {!r} for SMTP port is invalid:").format(val)
+                msg = _('Value {!r} for SMTP port is invalid:').format(val)
                 msg += ' ' + str(e)
                 LOG.error(msg)
                 continue
             if port <= 0 or port > MAX_PORT_NUMBER:
-                msg = _("Found invalid SMTP port number {} in configuration.").format(port)
+                msg = _('Found invalid SMTP port number {} in configuration.').format(port)
                 LOG.error(msg)
                 continue
 
@@ -325,7 +316,7 @@ class MailConfiguration(PpBaseConfiguration):
 
 
 # =============================================================================
-if __name__ == "__main__":
+if __name__ == '__main__':
 
     pass