Skip to content

Commit

Permalink
Switch to flake8
Browse files Browse the repository at this point in the history
  • Loading branch information
adferrand committed Jul 26, 2020
1 parent 7539c7b commit f7e95ff
Show file tree
Hide file tree
Showing 47 changed files with 104 additions and 164 deletions.
2 changes: 1 addition & 1 deletion lexicon/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from lexicon.config import ConfigResolver
from lexicon.parser import generate_cli_main_parser

logger = logging.getLogger(__name__) # pylint: disable=C0103
logger = logging.getLogger(__name__)


def generate_list_table_result(lexicon_logger, output=None, without_header=None):
Expand Down
4 changes: 1 addition & 3 deletions lexicon/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ class ProviderNotAvailableError(Exception):
"""


class Client(
object
): # pylint: disable=useless-object-inheritance,too-few-public-methods
class Client(object):
"""This is the Lexicon client, that will execute all the logic."""

def __init__(self, config=None):
Expand Down
22 changes: 8 additions & 14 deletions lexicon/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
LOGGER = logging.getLogger(__name__)


class ConfigResolver(object): # pylint: disable=useless-object-inheritance
class ConfigResolver(object):
"""
Highly customizable configuration resolver object, that gets configuration parameters
from various sources with a precedence order. Sources and their priority are configured
Expand Down Expand Up @@ -201,9 +201,7 @@ def with_legacy_dict(self, legacy_dict_object):
return self.with_config_source(LegacyDictConfigSource(legacy_dict_object))


class ConfigSource(
object
): # pylint: disable=useless-object-inheritance,too-few-public-methods
class ConfigSource(object):
"""
Base class to implement a configuration source for a ConfigResolver.
The relevant method to override is resolve(self, config_parameter).
Expand All @@ -224,7 +222,7 @@ def resolve(self, config_key):
)


class EnvironmentConfigSource(ConfigSource): # pylint: disable=too-few-public-methods
class EnvironmentConfigSource(ConfigSource):
"""ConfigSource that resolve configuration against existing environment variables."""

def __init__(self):
Expand Down Expand Up @@ -265,7 +263,7 @@ def resolve(self, config_key):
return None


class ArgsConfigSource(ConfigSource): # pylint: disable=too-few-public-methods
class ArgsConfigSource(ConfigSource):
"""ConfigSource that resolve configuration against an argparse namespace."""

def __init__(self, namespace):
Expand All @@ -281,7 +279,7 @@ def resolve(self, config_key):
return self._parameters.get(splitted_config_key[-1], None)


class DictConfigSource(ConfigSource): # pylint: disable=too-few-public-methods
class DictConfigSource(ConfigSource):
"""ConfigSource that resolve configuration against a dict object."""

def __init__(self, dict_object):
Expand All @@ -299,7 +297,7 @@ def resolve(self, config_key):
return cursor.get(splitted_config_key[-1], None)


class FileConfigSource(DictConfigSource): # pylint: disable=too-few-public-methods
class FileConfigSource(DictConfigSource):
"""ConfigSource that resolve configuration against a lexicon config file."""

def __init__(self, file_path):
Expand All @@ -309,9 +307,7 @@ def __init__(self, file_path):
super(FileConfigSource, self).__init__(yaml_object)


class ProviderFileConfigSource(
FileConfigSource
): # pylint: disable=too-few-public-methods
class ProviderFileConfigSource(FileConfigSource):
"""ConfigSource that resolve configuration against an provider config file."""

def __init__(self, provider_name, file_path):
Expand All @@ -320,9 +316,7 @@ def __init__(self, provider_name, file_path):
self._parameters = {provider_name: self._parameters}


class LegacyDictConfigSource(
DictConfigSource
): # pylint: disable=too-few-public-methods
class LegacyDictConfigSource(DictConfigSource):
"""ConfigSource that resolve configuration against a legacy Lexicon 2.x dict object."""

def __init__(self, dict_object):
Expand Down
6 changes: 2 additions & 4 deletions lexicon/providers/aliyun.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def provider_parser(subparser):
subparser.description = """
Aliyun Provider requires an access key id and access secret with full rights on dns.
Better to use RAM on Aliyun cloud to create a specified user for the dns operation.
The referrence for Aliyun DNS production:
The referrence for Aliyun DNS production:
https://help.aliyun.com/product/29697.html"""
subparser.add_argument(
"--auth-key-id", help="specify access key id for authentication"
Expand Down Expand Up @@ -111,9 +111,7 @@ def _update_record(self, identifier, rtype=None, name=None, content=None):

if not identifier:
record = resources[0] if resources else None
identifier = (
record["id"] if record else None
) # pylint: disable=unsubscriptable-object
identifier = record["id"] if record else None

if not identifier:
raise ValueError("updating %s identifier not exists" % identifier)
Expand Down
19 changes: 6 additions & 13 deletions lexicon/providers/auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,21 +138,21 @@ def provider_parser(subparser):
parser = argparse.ArgumentParser(add_help=False)
provider_module.provider_parser(parser)

for action in parser._actions: # pylint: disable=protected-access
for action in parser._actions:
action.option_strings = [
re.sub(r"^--(.*)$", r"--{0}-\1".format(provider_name), option)
for option in action.option_strings
]
action.dest = "auto_{0}_{1}".format(provider_name, action.dest)
subparser._add_action(action) # pylint: disable=protected-access
subparser._add_action(action)


# Take care of the fact that this provider extends object, not BaseProvider !
# Indeed we want to delegate every parameter/method call to the delegate provider
# but __getattr__ is called only if the parameter/method cannot be found in the
# current Provider hierarchy. If it is object, it will be the case for every relevant
# call in the Lexicon library.
class Provider(object): # pylint: disable=useless-object-inheritance
class Provider(object):
"""
Implementation of the provider 'auto'.
For the given domain, it will resolve the actual Provider class to use by inspecting the
Expand All @@ -176,7 +176,7 @@ def __init__(self, config):
self.domain = config.resolve("lexicon:domain")
self.proxy_provider = None

def authenticate(self): # pylint: disable=too-many-locals
def authenticate(self):
"""
Launch the authentication process: for 'auto' provider, it means first to find the relevant
provider, then call its authenticate() method. Almost every subsequent operation will then
Expand Down Expand Up @@ -216,21 +216,14 @@ def authenticate(self): # pylint: disable=too-many-locals
new_config.with_dict({"provider_name": provider_name})

target_prefix = "auto_{0}_".format(provider_name)
for (
config_source
) in self.config._config_sources: # pylint: disable=protected-access
for config_source in self.config._config_sources:
if not isinstance(config_source, helper_config.ArgsConfigSource):
new_config.with_config_source(config_source)
else:
# ArgsConfigSource needs to be reprocessed to rescope the provided
# args to the delegate provider
new_dict = {}
for (
key,
value,
) in (
config_source._parameters.items()
): # pylint: disable=protected-access
for (key, value,) in config_source._parameters.items():
if key.startswith(target_prefix):
new_param_name = re.sub("^{0}".format(target_prefix), "", key)
if provider_name not in new_dict:
Expand Down
2 changes: 1 addition & 1 deletion lexicon/providers/azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def _delete_record(self, identifier=None, rtype=None, name=None, content=None):

def _delete_record_internal(
self, identifier=None, rtype=None, name=None, content=None
): # pylint: disable=too-many-locals
):
result = self._get("/{0}".format(rtype if rtype else "recordsets"))

to_delete = []
Expand Down
4 changes: 2 additions & 2 deletions lexicon/providers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from lexicon.config import ConfigResolver, legacy_config_resolver


class Provider(object): # pylint: disable=useless-object-inheritance
class Provider(object):
"""
This is the base class for all lexicon Providers.
It provides common functionality and ensures that all implemented
Expand Down Expand Up @@ -195,7 +195,7 @@ def _relative_name(self, record_name):
record_name = record_name.rstrip(".")
return record_name

def _clean_TXT_record(self, record): # pylint: disable=no-self-use,invalid-name
def _clean_TXT_record(self, record):
if record["type"] == "TXT":
# Some providers have quotes around the TXT records,
# so we're going to remove those extra quotes
Expand Down
2 changes: 1 addition & 1 deletion lexicon/providers/conoha.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def _send_request(self, action, url, data=None, query_params=None):
return response.json()
return response.text

def _record_name(self, name): # pylint: disable=no-self-use
def _record_name(self, name):
return "%s." % name.rstrip(".") if name else None

def _record_payload(self, rtype, name, content):
Expand Down
8 changes: 3 additions & 5 deletions lexicon/providers/constellix.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def _delete_record(self, identifier=None, rtype=None, name=None, content=None):
return True

# Helpers
def _check_type(self, rtype=None): # pylint: disable=no-self-use
def _check_type(self, rtype=None):
# Constellix doesn't treat SOA as a separate record type, so we bail on SOA modificiations.
# It looks like it would be possible to fake SOA CRUD, so an area for possible future
# improvement
Expand All @@ -238,14 +238,12 @@ def _check_type(self, rtype=None): # pylint: disable=no-self-use

def _filter_records(
self, records, rtype=None, name=None, content=None, identifier=None
): # pylint: disable=too-many-arguments
):
_records = []
for record in records:
if (
(not identifier or record["id"] == identifier)
and ( # pylint: disable=too-many-boolean-expressions
not rtype or record["type"] == rtype
)
and (not rtype or record["type"] == rtype)
and (not name or record["name"] == self._full_name(name))
and (not content or record["content"] == content)
):
Expand Down
2 changes: 1 addition & 1 deletion lexicon/providers/directadmin.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def _authenticate(self):

try:
self.domain_id = domains.index(self.domain)
except:
except BaseException:
raise Exception("Domain {0} not found".format(self.domain))

def _create_record(self, rtype, name, content):
Expand Down
4 changes: 2 additions & 2 deletions lexicon/providers/dreamhost.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def _create_record(self, rtype, name, content):
try:
self._get(
"dns-add_record",
query_params={"record": name, "type": rtype, "value": content,},
query_params={"record": name, "type": rtype, "value": content},
)
except AlreadyExistError:
pass
Expand Down Expand Up @@ -194,7 +194,7 @@ def _delete_record(self, identifier=None, rtype=None, name=None, content=None):
dreamhost_record = Provider._record_to_dreamhost_record(each)
self._get("dns-remove_record", query_params=dreamhost_record)

except Exception as exception: # pylint: disable=broad-except
except Exception as exception:
err = exception

# Sleeping for 1-second to avoid trigerring ddos protecting in case of looped requests
Expand Down
6 changes: 3 additions & 3 deletions lexicon/providers/easyname.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ def _is_zone_tr(elm):

def _filter_records(
self, records, rtype=None, name=None, content=None, identifier=None
): # pylint: disable=too-many-arguments,no-self-use
):
"""
Filter dns entries based on type, name or content.
"""
Expand Down Expand Up @@ -421,7 +421,7 @@ def _get_domain_text_of_authoritative_zone(self):
assert domain_text is not None, "The domain does not exist on Easyname."
return domain_text

def _get_domain_id(self, domain_text_element): # pylint: disable=no-self-use
def _get_domain_id(self, domain_text_element):
"""Return the easyname id of the domain."""
try:
# Hierarchy: TR > TD > SPAN > Domain Text
Expand All @@ -439,7 +439,7 @@ def _get_domain_id(self, domain_text_element): # pylint: disable=no-self-use
LOGGER.warning(errmsg)
raise AssertionError(errmsg)

def _log(self, name, element): # pylint: disable=no-self-use
def _log(self, name, element):
"""
Log Response and Tag elements. Do nothing if elements is none of them.
"""
Expand Down
10 changes: 3 additions & 7 deletions lexicon/providers/gandi.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,15 +286,13 @@ def _request(self, action="GET", url="/", data=None, query_params=None):
return response.json()


class GandiRPCSubProvider(object): # pylint: disable=useless-object-inheritance
class GandiRPCSubProvider(object):
"""Provide Gandi RPCXML API implementation of Lexicon Provider interface.
This implementation is called through the main LiveDNS implementation
is RPC protocol is used.
"""

def __init__(
self, api_key, api_endpoint, domain, relative_name_fn, full_name_fn
): # pylint: disable=too-many-arguments
def __init__(self, api_key, api_endpoint, domain, relative_name_fn, full_name_fn):
"""Initialize Gandi RCPXML API provider."""
super(GandiRPCSubProvider, self).__init__()

Expand Down Expand Up @@ -388,9 +386,7 @@ def list_records(self, rtype=None, name=None, content=None):
return records

# Update a record. Identifier or type+name+content
def update_record(
self, identifier, rtype=None, name=None, content=None
): # pylint: disable=too-many-branches
def update_record(self, identifier, rtype=None, name=None, content=None):
"""Updates the specified record in a new Gandi zone."""
if not identifier:
records = self.list_records(rtype, name)
Expand Down
10 changes: 4 additions & 6 deletions lexicon/providers/gehirn.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,14 +254,12 @@ def _full_name(self, record_name):
record_name += "."
return record_name

def _bind_format_target(self, rtype, target): # pylint: disable=no-self-use
def _bind_format_target(self, rtype, target):
if rtype == "CNAME" and not target.endswith("."):
target += "."
return target

def _filter_records(
self, records, identifier=None, rtype=None, name=None
): # pylint: disable=no-self-use
def _filter_records(self, records, identifier=None, rtype=None, name=None):
filtered_records = []

if identifier:
Expand Down Expand Up @@ -295,10 +293,10 @@ def _update_internal_record(self, record):
path = "/zones/{}/versions/{}/records".format(self.domain_id, self.version_id,)
return self._post(path, record)

def _build_content(self, rtype, record): # pylint: disable=no-self-use
def _build_content(self, rtype, record):
return BUILD_FORMATS[rtype].format(**record)

def _parse_content(self, rtype, content): # pylint: disable=no-self-use
def _parse_content(self, rtype, content):
return FORMAT_RE[rtype].match(content).groupdict()

def _request(self, action="GET", url="/", data=None, query_params=None):
Expand Down
2 changes: 1 addition & 1 deletion lexicon/providers/glesys.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def _addttl(self, request_data):
request_data["ttl"] = self._get_lexicon_option("ttl")

# From Glesys record structure: [u'domainname', u'recordid', u'type', u'host', u'ttl', u'data']
def _glesysrecord2lexiconrecord(self, glesys_record): # pylint: disable=no-self-use
def _glesysrecord2lexiconrecord(self, glesys_record):
return {
"id": glesys_record["recordid"],
"type": glesys_record["type"],
Expand Down
8 changes: 2 additions & 6 deletions lexicon/providers/godaddy.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,7 @@ def _update_record(self, identifier, rtype=None, name=None, content=None):
# - or the first matching by its rtype+name where content does not match
# (first match, see first method comment for explanation).
for record in records:
if (
identifier and Provider._identifier(record) == identifier
) or ( # pylint: disable=too-many-boolean-expressions
if (identifier and Provider._identifier(record) == identifier) or (
not identifier
and record["type"] == rtype
and self._relative_name(record["name"]) == relative_name
Expand Down Expand Up @@ -198,9 +196,7 @@ def _delete_record(self, identifier=None, rtype=None, name=None, content=None):
else:
for record in records:
if (
(
not rtype and not relative_name and not content
) # pylint: disable=too-many-boolean-expressions
(not rtype and not relative_name and not content)
or (
rtype
and not relative_name
Expand Down
4 changes: 1 addition & 3 deletions lexicon/providers/gransy.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,7 @@ def domains_list(self):
response = self._request_domains_list()
return response["domains"] if "domains" in response else list()

def _create_request_record(
self, identifier, rtype, name, content, ttl, priority
): # pylint: disable=too-many-arguments
def _create_request_record(self, identifier, rtype, name, content, ttl, priority):
"""Creates record for Subreg API calls"""
record = collections.OrderedDict()

Expand Down
Loading

0 comments on commit f7e95ff

Please sign in to comment.