mirror of
https://github.com/certbot/certbot.git
synced 2026-06-08 08:12:15 -04:00
pylint fixes
This commit is contained in:
parent
a311df9c2d
commit
5fb9cc4c39
11 changed files with 75 additions and 47 deletions
|
|
@ -272,7 +272,7 @@ def validate_key_csr(privkey, csr=None):
|
|||
if csr:
|
||||
if csr.form == "der":
|
||||
csr_obj = M2Crypto.X509.load_request_der_string(csr.data)
|
||||
csr = Client.CSR(csr.file, csr_obj.as_pem(), "der")
|
||||
csr = le_util.CSR(csr.file, csr_obj.as_pem(), "der")
|
||||
|
||||
# If CSR is provided, it must be readable and valid.
|
||||
if csr.data and not crypto_util.valid_csr(csr.data):
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import textwrap
|
|||
import dialog
|
||||
import zope.interface
|
||||
|
||||
from letsencrypt.client import errors
|
||||
from letsencrypt.client import interfaces
|
||||
|
||||
|
||||
|
|
@ -35,6 +34,7 @@ class NcursesDisplay(object):
|
|||
self.height = height
|
||||
|
||||
def notification(self, message, height=10, pause=False):
|
||||
# pylint: disable=unused-argument
|
||||
"""Display a notification to the user and wait for user acceptance.
|
||||
|
||||
:param str message: Message to display
|
||||
|
|
@ -150,6 +150,7 @@ class FileDisplay(object):
|
|||
self.outfile = outfile
|
||||
|
||||
def notification(self, message, height=10, pause=True):
|
||||
# pylint: disable=unused-argument
|
||||
"""Displays a notification and waits for user acceptance.
|
||||
|
||||
:param str message: Message to display
|
||||
|
|
@ -166,8 +167,9 @@ class FileDisplay(object):
|
|||
if pause:
|
||||
raw_input("Press Enter to Continue")
|
||||
|
||||
def menu(
|
||||
self, message, choices, ok_label="", cancel_label="", help_label=""):
|
||||
def menu(self, message, choices,
|
||||
ok_label="", cancel_label="", help_label=""):
|
||||
# pylint: disable=unused-argument
|
||||
"""Display a menu.
|
||||
|
||||
:param str message: title of menu
|
||||
|
|
@ -264,6 +266,7 @@ class FileDisplay(object):
|
|||
return code, []
|
||||
|
||||
def _scrub_checklist_input(self, indices, tags):
|
||||
# pylint: disable=no-self-use
|
||||
"""Validate input and transform indices to appropriate tags.
|
||||
|
||||
:param list indices: input
|
||||
|
|
@ -335,7 +338,7 @@ class FileDisplay(object):
|
|||
|
||||
return os.linesep.join(fixed_l)
|
||||
|
||||
def _get_valid_int_ans(self, max):
|
||||
def _get_valid_int_ans(self, max_):
|
||||
"""Get a numerical selection.
|
||||
|
||||
:param int max: The maximum entry (len of choices), must be positive
|
||||
|
|
@ -347,10 +350,10 @@ class FileDisplay(object):
|
|||
|
||||
"""
|
||||
selection = -1
|
||||
if max > 1:
|
||||
if max_ > 1:
|
||||
input_msg = ("Select the appropriate number "
|
||||
"[1-{max}] then [enter] (press 'c' to "
|
||||
"cancel): ".format(max=max))
|
||||
"[1-{max_}] then [enter] (press 'c' to "
|
||||
"cancel): ".format(max_=max_))
|
||||
else:
|
||||
input_msg = ("Press 1 [enter] to confirm the selection "
|
||||
"(press 'c' to cancel): ")
|
||||
|
|
@ -360,7 +363,7 @@ class FileDisplay(object):
|
|||
return CANCEL, -1
|
||||
try:
|
||||
selection = int(ans)
|
||||
if selection < 1 or selection > max:
|
||||
if selection < 1 or selection > max_:
|
||||
selection = -1
|
||||
raise ValueError
|
||||
|
||||
|
|
@ -371,16 +374,16 @@ class FileDisplay(object):
|
|||
return OK, selection
|
||||
|
||||
|
||||
def separate_list_input(input):
|
||||
def separate_list_input(input_):
|
||||
"""Separate a comma or space separated list.
|
||||
|
||||
:param str input: input from the user
|
||||
:param str input_: input from the user
|
||||
|
||||
:returns: strings
|
||||
:rtype: list
|
||||
|
||||
"""
|
||||
no_commas = input.replace(",", " ")
|
||||
no_commas = input_.replace(",", " ")
|
||||
return [string for string in no_commas.split()]
|
||||
|
||||
def _parens_around_char(label):
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ def ask(enhancement):
|
|||
|
||||
"""
|
||||
try:
|
||||
return _dispatch[enhancement]()
|
||||
return dispatch[enhancement]()
|
||||
except KeyError:
|
||||
logging.error("Unsupported enhancement given to ask()")
|
||||
raise errors.LetsEncryptClientError("Unsupported Enhancement")
|
||||
|
|
@ -40,19 +40,19 @@ def redirect_by_default():
|
|||
("Secure", "Make all requests redirect to secure HTTPS access"),
|
||||
]
|
||||
|
||||
result = _util(interfaces.IDisplay).menu(
|
||||
code, selection = util(interfaces.IDisplay).menu(
|
||||
"Please choose whether HTTPS access is required or optional.",
|
||||
choices)
|
||||
|
||||
if result[0] != display_util.OK:
|
||||
if code != display_util.OK:
|
||||
return False
|
||||
|
||||
return result[1] == 1
|
||||
return selection == 1
|
||||
|
||||
|
||||
_util = zope.component.getUtility
|
||||
util = zope.component.getUtility # pylint: disable=invalid-name
|
||||
|
||||
|
||||
_dispatch = {
|
||||
dispatch = { # pylint: disable=invalid-name
|
||||
"redirect": redirect_by_default
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import logging
|
||||
"""Contains UI methods for LE user operations."""
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
|
@ -8,7 +8,7 @@ from letsencrypt.client import interfaces
|
|||
from letsencrypt.client.display import display_util
|
||||
|
||||
# Define a helper function to avoid verbose code
|
||||
util = zope.component.getUtility
|
||||
util = zope.component.getUtility # pylint: disable=invalid-name
|
||||
|
||||
|
||||
def choose_authenticator(auths):
|
||||
|
|
@ -82,11 +82,11 @@ def _filter_names(names):
|
|||
def _choose_names_manually():
|
||||
"""Manualy input names for those without an installer."""
|
||||
|
||||
code, input = util(interfaces.IDisplay).input(
|
||||
code, input_ = util(interfaces.IDisplay).input(
|
||||
"Please enter in your domain name(s) (comma and/or space separated) ")
|
||||
|
||||
if code == display_util.OK:
|
||||
return display_util.separate_list_input(input)
|
||||
return display_util.separate_list_input(input_)
|
||||
|
||||
sys.exit(0)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
"""Revocation UI class."""
|
||||
import os
|
||||
|
||||
import zope.component
|
||||
|
|
@ -5,7 +6,7 @@ import zope.component
|
|||
from letsencrypt.client import interfaces
|
||||
from letsencrypt.client.display import display_util
|
||||
|
||||
util = zope.component.getUtility
|
||||
util = zope.component.getUtility # pylint: disable=invalid-name
|
||||
|
||||
|
||||
def choose_certs(certs):
|
||||
|
|
@ -45,12 +46,13 @@ def display_certs(certs):
|
|||
|
||||
"""
|
||||
list_choices = [
|
||||
("%s | %s | %s" %
|
||||
(str(cert.get_cn().ljust(display_util.WIDTH - 39)),
|
||||
cert.get_not_before().strftime("%m-%d-%y"),
|
||||
"Installed" if cert.installed and cert.installed != ["Unknown"]
|
||||
else "")
|
||||
for cert in enumerate(certs))
|
||||
("%s | %s | %s" % (
|
||||
str(cert.get_cn().ljust(display_util.WIDTH - 39)),
|
||||
cert.get_not_before().strftime("%m-%d-%y"),
|
||||
"Installed" if cert.installed and cert.installed != ["Unknown"]
|
||||
else "")
|
||||
for cert in enumerate(certs)
|
||||
)
|
||||
]
|
||||
|
||||
code, tag = util(interfaces.IDisplay).menu(
|
||||
|
|
|
|||
|
|
@ -41,4 +41,4 @@ class LetsEncryptMisconfigurationError(LetsEncryptConfiguratorError):
|
|||
|
||||
|
||||
class LetsEncryptRevokerError(LetsEncryptClientError):
|
||||
"""Let's Encrypt Revoker error."""
|
||||
"""Let's Encrypt Revoker error."""
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ class Revoker(object):
|
|||
|
||||
self._remove_mark()
|
||||
|
||||
def _mark_for_revocation(self, cert):
|
||||
def _mark_for_revocation(self, cert): # pylint: disable=no-self-use
|
||||
"""Marks a cert for revocation."""
|
||||
if os.path.isfile(Revoker.marked_path):
|
||||
raise errors.LetsEncryptRevokerError(
|
||||
|
|
@ -104,7 +104,7 @@ class Revoker(object):
|
|||
csvwriter = csv.writer(marked_file)
|
||||
csvwriter.writerow([cert.backup_path, cert.backup_key_path])
|
||||
|
||||
def _remove_mark(self):
|
||||
def _remove_mark(self): # pylint: disable=no-self-use
|
||||
"""Remove the marked file."""
|
||||
os.remove(Revoker.marked_path)
|
||||
|
||||
|
|
@ -128,6 +128,7 @@ class Revoker(object):
|
|||
"certificates for this server.")
|
||||
|
||||
def _populate_saved_certs(self, csha1_vhlist):
|
||||
# pylint: disable=no-self-use
|
||||
"""Populate a list of all the saved certs."""
|
||||
certs = []
|
||||
with open(Revoker.list_path, "rb") as csvfile:
|
||||
|
|
@ -188,7 +189,7 @@ class Revoker(object):
|
|||
os.remove(cert.backup_path)
|
||||
os.remove(cert.backup_key_path)
|
||||
|
||||
def _remove_cert_from_list(self, cert):
|
||||
def _remove_cert_from_list(self, cert): # pylint: disable=no-self-use
|
||||
"""Remove a certificate from the LIST file."""
|
||||
list_path2 = os.path.join(CONFIG.CERT_KEY_BACKUP, "LIST.tmp")
|
||||
|
||||
|
|
@ -346,34 +347,44 @@ class Cert(object):
|
|||
self.backup_key_path = backup_key
|
||||
|
||||
def get_installed_msg(self):
|
||||
"""Access installed message."""
|
||||
return ", ".join(self.installed)
|
||||
|
||||
def get_subject(self):
|
||||
"""Get subject."""
|
||||
return self.cert.get_subject().as_text()
|
||||
|
||||
def get_cn(self):
|
||||
"""Get common name."""
|
||||
return self.cert.get_subject().CN
|
||||
|
||||
def get_issuer(self):
|
||||
"""Get issuer."""
|
||||
return self.cert.get_issuer().as_text()
|
||||
|
||||
def get_fingerprint(self):
|
||||
"""Get sha1 fingerprint."""
|
||||
return self.cert.get_fingerprint(md="sha1")
|
||||
|
||||
def get_not_before(self):
|
||||
"""Get not_valid_before field."""
|
||||
return self.cert.get_not_before().get_datetime()
|
||||
|
||||
def get_not_after(self):
|
||||
"""Get not_valid_after field."""
|
||||
return self.cert.get_not_after().get_datetime()
|
||||
|
||||
def get_serial(self):
|
||||
"""Get serial number."""
|
||||
self.cert.get_serial_number()
|
||||
|
||||
def get_pub_key(self):
|
||||
"""Get public key size."""
|
||||
# .. todo:: M2Crypto doesn't support ECC, this will have to be updated
|
||||
return "RSA " + str(self.cert.get_pubkey().size() * 8)
|
||||
|
||||
def get_san(self):
|
||||
"""Get subject alternative name if available."""
|
||||
try:
|
||||
return self.cert.get_ext("subjectAltName").get_value()
|
||||
except LookupError:
|
||||
|
|
|
|||
|
|
@ -166,6 +166,7 @@ class TwoVhost80Test(util.ApacheTest):
|
|||
|
||||
|
||||
class GetVersionTest(unittest.TestCase):
|
||||
# pylint: disable=too-few-public-methods
|
||||
@classmethod
|
||||
def _call(cls):
|
||||
from letsencrypt.client.apache.configurator import get_version
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import contextlib
|
||||
"""Test the display utility."""
|
||||
import os
|
||||
import unittest
|
||||
|
||||
|
|
@ -8,6 +8,8 @@ from letsencrypt.client.display import display_util
|
|||
|
||||
|
||||
class DisplayT(unittest.TestCase):
|
||||
"""Base class for both utility classes."""
|
||||
# pylint: disable=too-few-public-methods
|
||||
def setUp(self):
|
||||
self.choices = [("First", "Description1"), ("Second", "Description2")]
|
||||
self.tags = ["tag1", "tag2", "tag3"]
|
||||
|
|
@ -205,6 +207,7 @@ class FileOutputDisplayTest(DisplayT):
|
|||
self.assertEqual(ret, (display_util.CANCEL, []))
|
||||
|
||||
def test_scrub_checklist_input_valid(self):
|
||||
# pylint: disable=protected-access
|
||||
indices = [
|
||||
["1"],
|
||||
["1", "2", "1"],
|
||||
|
|
@ -221,6 +224,7 @@ class FileOutputDisplayTest(DisplayT):
|
|||
self.assertEqual(set_tags, exp[i])
|
||||
|
||||
def test_scrub_checklist_input_invalid(self):
|
||||
# pylint: disable=protected-access
|
||||
indices = [
|
||||
["0"],
|
||||
["4"],
|
||||
|
|
@ -233,11 +237,13 @@ class FileOutputDisplayTest(DisplayT):
|
|||
self.displayer._scrub_checklist_input(list_, self.tags), [])
|
||||
|
||||
def test_print_menu(self):
|
||||
# pylint: disable=protected-access
|
||||
# This is purely cosmetic... just make sure there aren't any exceptions
|
||||
self.displayer._print_menu("msg", self.choices)
|
||||
self.displayer._print_menu("msg", self.tags)
|
||||
|
||||
def test_wrap_lines(self):
|
||||
# pylint: disable=protected-access
|
||||
msg = ("This is just a weak test\n"
|
||||
"This function is only meant to be for easy viewing\n"
|
||||
"Test a really really really really really really really really "
|
||||
|
|
@ -247,6 +253,7 @@ class FileOutputDisplayTest(DisplayT):
|
|||
self.assertEqual(text.count(os.linesep), 3)
|
||||
|
||||
def test_get_valid_int_ans_valid(self):
|
||||
# pylint: disable=protected-access
|
||||
with mock.patch("__builtin__.raw_input", return_value="1"):
|
||||
self.assertEqual(
|
||||
self.displayer._get_valid_int_ans(1), (display_util.OK, 1))
|
||||
|
|
@ -257,6 +264,7 @@ class FileOutputDisplayTest(DisplayT):
|
|||
(display_util.OK, int(ans)))
|
||||
|
||||
def test_get_valid_int_ans_invalid(self):
|
||||
# pylint: disable=protected-access
|
||||
answers = [
|
||||
["0", "c"],
|
||||
["4", "one", "C"],
|
||||
|
|
@ -279,9 +287,9 @@ class SeparateListInputTest(unittest.TestCase):
|
|||
self.exp = ["a", "b", "c", "test"]
|
||||
|
||||
@classmethod
|
||||
def _call(cls, input):
|
||||
def _call(cls, input_):
|
||||
from letsencrypt.client.display.display_util import separate_list_input
|
||||
return separate_list_input(input)
|
||||
return separate_list_input(input_)
|
||||
|
||||
def test_commas(self):
|
||||
actual = self._call("a,b,c,test")
|
||||
|
|
@ -305,7 +313,7 @@ class SeparateListInputTest(unittest.TestCase):
|
|||
|
||||
class PlaceParensTest(unittest.TestCase):
|
||||
@classmethod
|
||||
def _call(cls, label):
|
||||
def _call(cls, label): # pylint: disable=protected-access
|
||||
from letsencrypt.client.display.display_util import _parens_around_char
|
||||
return _parens_around_char(label)
|
||||
|
||||
|
|
@ -319,4 +327,4 @@ class PlaceParensTest(unittest.TestCase):
|
|||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
unittest.main()
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
"""Test display.ops."""
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
|
|
@ -129,13 +130,15 @@ class ChooseNamesTest(unittest.TestCase):
|
|||
@mock.patch("letsencrypt.client.display.ops.util")
|
||||
def test_filter_names_cancel(self, mock_util):
|
||||
self.mock_install.get_all_names.return_value = set(["example.com"])
|
||||
mock_util().checklist.return_value = (display_util.CANCEL, ["example.com"])
|
||||
mock_util().checklist.return_value = (
|
||||
display_util.CANCEL, ["example.com"])
|
||||
|
||||
self.assertRaises(SystemExit, self._call, self.mock_install)
|
||||
|
||||
|
||||
class SuccessInstallationTest(unittest.TestCase):
|
||||
|
||||
# pylint: disable=too-few-public-methods
|
||||
"""Test the success installation message."""
|
||||
@classmethod
|
||||
def _call(cls, names):
|
||||
from letsencrypt.client.display.ops import success_installation
|
||||
|
|
@ -156,4 +159,4 @@ class SuccessInstallationTest(unittest.TestCase):
|
|||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
unittest.main()
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ def main(): # pylint: disable=too-many-statements,too-many-branches
|
|||
except errors.LetsEncryptMisconfigurationError as err:
|
||||
logging.fatal("Please fix your configuration before proceeding.%s"
|
||||
"The Authenticator exited with the following message: "
|
||||
"%s", (os.linesep, err))
|
||||
"%s", os.linesep, err)
|
||||
sys.exit(1)
|
||||
|
||||
# Use the same object if possible
|
||||
|
|
@ -114,7 +114,7 @@ def main(): # pylint: disable=too-many-statements,too-many-branches
|
|||
else:
|
||||
installer = client.determine_installer()
|
||||
|
||||
domains = ops.choose_names(installer) if args.domains is None else args.domains
|
||||
doms = ops.choose_names(installer) if args.domains is None else args.domains
|
||||
|
||||
# Prepare for init of Client
|
||||
if args.privkey is None:
|
||||
|
|
@ -133,11 +133,11 @@ def main(): # pylint: disable=too-many-statements,too-many-branches
|
|||
# but this code should be safe on all environments.
|
||||
cert_file = None
|
||||
if auth is not None:
|
||||
cert_file, chain_file = acme.obtain_certificate(domains)
|
||||
cert_file, chain_file = acme.obtain_certificate(doms)
|
||||
if installer is not None and cert_file is not None:
|
||||
acme.deploy_certificate(domains, privkey, cert_file, chain_file)
|
||||
acme.deploy_certificate(doms, privkey, cert_file, chain_file)
|
||||
if installer is not None:
|
||||
acme.enhance_config(domains, args.redirect)
|
||||
acme.enhance_config(doms, args.redirect)
|
||||
|
||||
|
||||
def display_eula():
|
||||
|
|
|
|||
Loading…
Reference in a new issue