From d4d69b4dbb5ad6be4691599396648e32f1a3e22e Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Tue, 6 Feb 2018 12:11:41 +0100 Subject: [PATCH] Applying flake8 rules to pp_lib/pdns_app.py --- pp_lib/pdns_app.py | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/pp_lib/pdns_app.py b/pp_lib/pdns_app.py index 91cf038..d7f14ca 100644 --- a/pp_lib/pdns_app.py +++ b/pp_lib/pdns_app.py @@ -22,17 +22,16 @@ import time # Third party modules import requests -import six import psutil # Own modules -from .common import pp, to_bool +from .common import pp from .cfg_app import PpCfgAppError, PpConfigApplication from .pdns_zone import PdnsApiZone -from .pdns_record import PdnsApiRecord, PdnsSoaData, PdnsApiRrset +from .pdns_record import PdnsSoaData -__version__ = '0.6.4' +__version__ = '0.6.5' LOG = logging.getLogger(__name__) _LIBRARY_NAME = "pp-pdns-api-client" @@ -41,9 +40,9 @@ _LIBRARY_NAME = "pp-pdns-api-client" class PpPDNSAppError(PpCfgAppError): """Base error class for all exceptions happened during execution this configured application""" - pass + # ============================================================================= class PDNSApiError(PpPDNSAppError): """Base class for more complex exceptions""" @@ -56,32 +55,37 @@ class PDNSApiError(PpPDNSAppError): # ============================================================================= class PDNSApiNotAuthorizedError(PDNSApiError): """The authorization information provided is not correct""" + pass # ============================================================================= class PDNSApiNotFoundError(PDNSApiError): """The ProfitBricks entity was not found""" + pass # ============================================================================= class PDNSApiValidationError(PDNSApiError): """The HTTP data provided is not valid""" + pass # ============================================================================= class PDNSApiRateLimitExceededError(PDNSApiError): """The number of requests sent have exceeded the allowed API rate limit""" + pass # ============================================================================= class PDNSApiRequestError(PDNSApiError): """Base error for request failures""" + pass # ============================================================================= class PDNSApiTimeoutError(PDNSApiRequestError): """Raised when a request does not finish in the given time span.""" - + pass # ============================================================================= @@ -109,10 +113,10 @@ class PpPDNSApplication(PpConfigApplication): # ------------------------------------------------------------------------- def __init__( self, appname=None, verbose=0, version=__version__, base_dir=None, - initialized=None, usage=None, description=None, - argparse_epilog=None, argparse_prefix_chars='-', env_prefix=None, - cfg_dir=None, cfg_stems=None, cfg_encoding='utf-8', need_config_file=False, - environment='global'): + initialized=None, usage=None, description=None, + argparse_epilog=None, argparse_prefix_chars='-', env_prefix=None, + cfg_dir=None, cfg_stems=None, cfg_encoding='utf-8', need_config_file=False, + environment='global'): self._api_key = self.api_keys['global'] self._api_host = self.api_hosts['global'] @@ -135,13 +139,13 @@ class PpPDNSApplication(PpConfigApplication): s = str(stem).strip() if not s: msg = "Invalid configuration stem {!r} given.".format(stem) - raise PpLdapAppError(msg) + raise PpPDNSAppError(msg) stems.append(s) else: s = str(cfg_stems).strip() if not s: msg = "Invalid configuration stem {!r} given.".format(cfg_stems) - raise PpLdapAppError(msg) + raise PpPDNSAppError(msg) stems.append(s) else: stems = [self.appname] @@ -341,7 +345,8 @@ class PpPDNSApplication(PpConfigApplication): pdns_group.add_argument( '-p', '--port', metavar="PORT", type=int, dest='api_port', default=self.default_api_port, - help=("Which port to connect to PowerDNS API, default: {}.".format(self.default_api_port)), + help=("Which port to connect to PowerDNS API, default: {}.".format( + self.default_api_port)), ) pdns_group.add_argument( @@ -387,7 +392,7 @@ class PpPDNSApplication(PpConfigApplication): if section_name.lower() in ( 'powerdns-api', 'powerdns_api', 'powerdnsapi', - 'pdns-api', 'pdns_api', 'pdnsapi' ): + 'pdns-api', 'pdns_api', 'pdnsapi'): self.set_cfg_api_options(section, section_name) # ------------------------------------------------------------------------- @@ -420,7 +425,7 @@ class PpPDNSApplication(PpConfigApplication): "a port must be greater than 0 and less than {}.".format(2**16)) except (TypeError, ValueError) as e: LOG.error("Wrong port number {!r} in configuration section {!r}: {}".format( - section['port'], section_name, e)) + section['port'], section_name, e)) self.config_has_errors = True else: self.api_port = port @@ -503,7 +508,7 @@ class PpPDNSApplication(PpConfigApplication): path = "/servers/{}".format(self.api_servername) try: json_response = self.perform_request(path) - except (PDNSApiNotFoundError, PDNSApiValidationError) as e: + except (PDNSApiNotFoundError, PDNSApiValidationError): LOG.error("Could not found server info.") return None if self.verbose > 2: @@ -631,14 +636,14 @@ class PpPDNSApplication(PpConfigApplication): path = "/servers/{}/zones/{}".format(self.api_servername, zone_name) try: json_response = self.perform_request(path) - except (PDNSApiNotFoundError, PDNSApiValidationError) as e: + except (PDNSApiNotFoundError, PDNSApiValidationError): LOG.error("The given zone {} was not found.".format(zout)) return None if self.verbose > 2: LOG.debug("Got a response:\n{}".format(pp(json_response))) zone = PdnsApiZone.init_from_dict( - json_response, appname=self.appname, verbose=self.verbose, base_dir=self. base_dir) + json_response, appname=self.appname, verbose=self.verbose, base_dir=self.base_dir) if self.verbose > 2: LOG.debug("Zone object:\n{}".format(pp(zone.as_dict()))) -- 2.39.5