Update to Pylint 1.9.4 and corrections

This commit is contained in:
Adrien Ferrand
2019-04-09 09:22:19 +02:00
parent 4515a52d3f
commit 04152c21b5
64 changed files with 193 additions and 216 deletions
+1 -3
View File
@@ -166,7 +166,6 @@ class NginxConfigurator(common.Installer):
# Entry point in main.py for installing cert
def deploy_cert(self, domain, cert_path, key_path,
chain_path=None, fullchain_path=None):
# pylint: disable=unused-argument
"""Deploys certificate to specified virtual host.
.. note:: Aborts if the vhost is missing ssl_certificate or
@@ -187,8 +186,7 @@ class NginxConfigurator(common.Installer):
for vhost in vhosts:
self._deploy_cert(vhost, cert_path, key_path, chain_path, fullchain_path)
def _deploy_cert(self, vhost, cert_path, key_path, chain_path, fullchain_path):
# pylint: disable=unused-argument
def _deploy_cert(self, vhost, cert_path, key_path, chain_path, fullchain_path): # pylint: disable=unused-argument
"""
Helper function for deploy_cert() that handles the actual deployment
this exists because we might want to do multiple deployments per
+2 -1
View File
@@ -1,7 +1,8 @@
"""nginx plugin constants."""
import pkg_resources
import platform
import pkg_resources
FREEBSD_DARWIN_SERVER_ROOT = "/usr/local/etc/nginx"
LINUX_SERVER_ROOT = "/etc/nginx"
+2 -3
View File
@@ -83,8 +83,7 @@ class NginxParser(object):
"""
if not os.path.isabs(path):
return os.path.normpath(os.path.join(self.root, path))
else:
return os.path.normpath(path)
return os.path.normpath(path)
def _build_addr_to_ssl(self):
"""Builds a map from address to whether it listens on ssl in any server block
@@ -395,7 +394,7 @@ class NginxParser(object):
addr.default = False
addr.ipv6only = False
for directive in enclosing_block[new_vhost.path[-1]][1]:
if len(directive) > 0 and directive[0] == 'listen':
if directive and directive[0] == 'listen':
# Exclude one-time use parameters which will cause an error if repeated.
# https://nginx.org/en/docs/http/ngx_http_core_module.html#listen
exclude = set(('default_server', 'default', 'setfib', 'fastopen', 'backlog',
+26 -22
View File
@@ -13,6 +13,7 @@ logger = logging.getLogger(__name__)
COMMENT = " managed by Certbot"
COMMENT_BLOCK = ["#", COMMENT]
class Parsable(object):
""" Abstract base class for "Parsable" objects whose underlying representation
is a tree of lists.
@@ -112,6 +113,7 @@ class Parsable(object):
"""
return [elem.dump(include_spaces) for elem in self._data]
class Statements(Parsable):
""" A group or list of "Statements". A Statement is either a Block or a Sentence.
@@ -142,24 +144,23 @@ class Statements(Parsable):
if self.parent is not None:
self._trailing_whitespace = "\n" + self.parent.get_tabs()
def parse(self, parse_this, add_spaces=False):
def parse(self, raw_list, add_spaces=False):
""" Parses a list of statements.
Expects all elements in `parse_this` to be parseable by `type(self).parsing_hooks`,
with an optional whitespace string at the last index of `parse_this`.
Expects all elements in `raw_list` to be parseable by `type(self).parsing_hooks`,
with an optional whitespace string at the last index of `raw_list`.
"""
if not isinstance(parse_this, list):
if not isinstance(raw_list, list):
raise errors.MisconfigurationError("Statements parsing expects a list!")
# If there's a trailing whitespace in the list of statements, keep track of it.
if len(parse_this) > 0 and isinstance(parse_this[-1], six.string_types) \
and parse_this[-1].isspace():
self._trailing_whitespace = parse_this[-1]
parse_this = parse_this[:-1]
self._data = [parse_raw(elem, self, add_spaces) for elem in parse_this]
if raw_list and isinstance(raw_list[-1], six.string_types) and raw_list[-1].isspace():
self._trailing_whitespace = raw_list[-1]
raw_list = raw_list[:-1]
self._data = [parse_raw(elem, self, add_spaces) for elem in raw_list]
def get_tabs(self):
""" Takes a guess at the tabbing of all contained Statements by retrieving the
tabbing of the first Statement."""
if len(self._data) > 0:
if self._data:
return self._data[0].get_tabs()
return ""
@@ -179,6 +180,7 @@ class Statements(Parsable):
# ======== End overridden functions
def _space_list(list_):
""" Inserts whitespace between adjacent non-whitespace tokens. """
spaced_statement = [] # type: List[str]
@@ -188,6 +190,7 @@ def _space_list(list_):
spaced_statement.insert(0, " ")
return spaced_statement
class Sentence(Parsable):
""" A list of words. Non-whitespace words are typically separated with whitespace tokens. """
@@ -205,15 +208,15 @@ class Sentence(Parsable):
return isinstance(lists, list) and len(lists) > 0 and \
all([isinstance(elem, six.string_types) for elem in lists])
def parse(self, parse_this, add_spaces=False):
def parse(self, raw_list, add_spaces=False):
""" Parses a list of string types into this object.
If add_spaces is set, adds whitespace tokens between adjacent non-whitespace tokens."""
if add_spaces:
parse_this = _space_list(parse_this)
if not isinstance(parse_this, list) or \
any([not isinstance(elem, six.string_types) for elem in parse_this]):
raw_list = _space_list(raw_list)
if not isinstance(raw_list, list) or \
any([not isinstance(elem, six.string_types) for elem in raw_list]):
raise errors.MisconfigurationError("Sentence parsing expects a list of string types.")
self._data = parse_this
self._data = raw_list
def iterate(self, expanded=False, match=None):
""" Simply yields itself. """
@@ -255,6 +258,7 @@ class Sentence(Parsable):
def __contains__(self, word):
return word in self.words
class Block(Parsable):
""" Any sort of bloc, denoted by a block name and curly braces, like so:
The parsed block:
@@ -297,26 +301,26 @@ class Block(Parsable):
for elem in self.contents.iterate(expanded, match):
yield elem
def parse(self, parse_this, add_spaces=False):
def parse(self, raw_list, add_spaces=False):
""" Parses a list that resembles a block.
The assumptions that this routine makes are:
1. the first element of `parse_this` is a valid Sentence.
2. the second element of `parse_this` is a valid Statement.
1. the first element of `raw_list` is a valid Sentence.
2. the second element of `raw_list` is a valid Statement.
If add_spaces is set, we call it recursively on `names` and `contents`, and
add an extra trailing space to `names` (to separate the block's opening bracket
and the block name).
"""
if not Block.should_parse(parse_this):
if not Block.should_parse(raw_list):
raise errors.MisconfigurationError("Block parsing expects a list of length 2. "
"First element should be a list of string types (the bloc names), "
"and second should be another list of statements (the bloc content).")
self.names = Sentence(self)
if add_spaces:
parse_this[0].append(" ")
self.names.parse(parse_this[0], add_spaces)
raw_list[0].append(" ")
self.names.parse(raw_list[0], add_spaces)
self.contents = Statements(self)
self.contents.parse(parse_this[1], add_spaces)
self.contents.parse(raw_list[1], add_spaces)
self._data = [self.names, self.contents]
def get_tabs(self):
+3 -5
View File
@@ -1,21 +1,19 @@
"""Common utilities for certbot_nginx."""
import copy
import os
import pkg_resources
import shutil
import tempfile
import unittest
import shutil
import warnings
import josepy as jose
import mock
import pkg_resources
import zope.component
from certbot import configuration
from certbot.tests import util as test_util
from certbot.plugins import common
from certbot.tests import util as test_util
from certbot_nginx import configurator
from certbot_nginx import nginxparser