From 60f7a56d5ad00e79aebd0ee46918872e41959433 Mon Sep 17 00:00:00 2001 From: Ferry Boender Date: Mon, 7 Sep 2020 18:08:23 +0200 Subject: [PATCH] Fix linting issues (py3) --- build.sla | 2 +- src/daemon.py | 9 ++++----- src/formconfig.py | 1 - src/formdefinition.py | 5 +++-- src/scriptform.py | 9 +++++---- src/webapp.py | 4 ++-- src/webserver.py | 1 - 7 files changed, 15 insertions(+), 16 deletions(-) diff --git a/build.sla b/build.sla index cb1ae2a..4b2087c 100644 --- a/build.sla +++ b/build.sla @@ -22,7 +22,7 @@ test () { # Code quality linting (pylint) cd $ROOTDIR - cd src && pylint --reports=n -dR -d star-args -d no-member *.py || true + cd src && pylint --reports=n -dR -d subprocess-popen-preexec-fn -d invalid-name -d star-args -d no-member *.py || true cd $ROOTDIR } diff --git a/src/daemon.py b/src/daemon.py index e2264e6..747ac03 100644 --- a/src/daemon.py +++ b/src/daemon.py @@ -15,7 +15,6 @@ class DaemonError(Exception): """ Default error for Daemon class. """ - pass class Daemon(object): # pragma: no cover @@ -97,7 +96,8 @@ class Daemon(object): # pragma: no cover return None try: - pid = int(file(self.pid_file, 'r').read().strip()) + with open(self.pid_file, "r") as fh: + pid = int(fh.read().strip()) except ValueError: return None @@ -137,9 +137,8 @@ class Daemon(object): # pragma: no cover pid = os.fork() if pid > 0: self.log.info("PID = %s", pid) - pidfile = file(self.pid_file, 'w') - pidfile.write(str(pid)) - pidfile.close() + with open(self.pid_file, "w") as fh: + fh.write(str(pid)) sys.exit(0) # End parent atexit.register(self._cleanup) diff --git a/src/formconfig.py b/src/formconfig.py index cc9f3a6..a3c26e5 100644 --- a/src/formconfig.py +++ b/src/formconfig.py @@ -13,7 +13,6 @@ class FormConfigError(Exception): """ Default error for FormConfig errors """ - pass class FormConfig(object): diff --git a/src/formdefinition.py b/src/formdefinition.py index 7def906..4e0e7aa 100644 --- a/src/formdefinition.py +++ b/src/formdefinition.py @@ -10,8 +10,9 @@ import runscript class ValidationError(Exception): - """Default exception for Validation errors""" - pass + """ + Default exception for Validation errors + """ class FormDefinition(object): diff --git a/src/scriptform.py b/src/scriptform.py index 843d325..0767400 100755 --- a/src/scriptform.py +++ b/src/scriptform.py @@ -12,7 +12,6 @@ import json import logging import threading import hashlib -import socket if hasattr(sys, 'dont_write_bytecode'): sys.dont_write_bytecode = True @@ -68,7 +67,8 @@ class ScriptForm(object): if 'static_dir' in config: static_dir = config['static_dir'] if 'custom_css' in config: - custom_css = file(config['custom_css'], 'r').read() + with open(config["custom_css"], "r") as fh: + custom_css = fh.read() if 'users' in config: users = config['users'] for form in config['forms']: @@ -186,10 +186,11 @@ def main(): # pragma: no cover if plain_pw != getpass.getpass('Repeat password: '): sys.stderr.write("Passwords do not match.\n") sys.exit(1) - sys.stdout.write(hashlib.sha256(plain_pw.encode('utf8')).hexdigest() + '\n') + sha = hashlib.sha256(plain_pw.encode('utf8')).hexdigest() + sys.stdout.write("{}\n".format(sha)) sys.exit(0) else: - if not options.action_stop and len(args) < 1: + if not options.action_stop and not args: parser.error("Insufficient number of arguments") if not options.action_stop and not options.action_start: options.action_start = True diff --git a/src/webapp.py b/src/webapp.py index 45b25a2..bb0e5ab 100644 --- a/src/webapp.py +++ b/src/webapp.py @@ -3,7 +3,6 @@ The webapp part of Scriptform, which takes care of serving requests and handling them. """ -import cgi import html import logging import tempfile @@ -214,7 +213,8 @@ class ScriptFormWebApp(RequestHandler): if auth_header is not None: # Validate the username and password auth_unpw = auth_header.split(' ', 1)[1].encode('utf-8') - username, password = base64.b64decode(auth_unpw).decode('utf-8').split(":", 1) + username, password = \ + base64.b64decode(auth_unpw).decode('utf-8').split(":", 1) pw_hash = hashlib.sha256(password.encode('utf-8')).hexdigest() if username in form_config.users and \ pw_hash == form_config.users[username]: diff --git a/src/webserver.py b/src/webserver.py index 276efb1..76d38b7 100644 --- a/src/webserver.py +++ b/src/webserver.py @@ -29,7 +29,6 @@ class ThreadedHTTPServer(ThreadingMixIn, HTTPServer): """ Base class for multithreaded HTTP servers. """ - pass class RequestHandler(BaseHTTPRequestHandler):