From 643ac4ad2d7b145b334052eaa5c5a13255bfd677 Mon Sep 17 00:00:00 2001 From: Dan Callahan Date: Fri, 28 May 2021 22:04:45 +0100 Subject: [PATCH] Fix Flake8 lints Signed-off-by: Dan Callahan --- sydent/db/accounts.py | 8 ++++---- sydent/db/sqlitedb.py | 6 +++--- sydent/db/terms.py | 2 +- sydent/http/federation_tls_options.py | 1 - sydent/http/httpclient.py | 4 ++-- sydent/http/matrixfederationagent.py | 2 +- sydent/http/servlets/blindlysignstuffservlet.py | 2 +- sydent/http/servlets/emailservlet.py | 2 +- sydent/http/servlets/lookupservlet.py | 4 ++-- sydent/http/servlets/registerservlet.py | 3 +-- sydent/http/servlets/replication.py | 2 +- sydent/http/servlets/threepidunbindservlet.py | 1 - sydent/replication/__init__.py | 1 - sydent/replication/peer.py | 2 +- sydent/util/emailutils.py | 2 -- tests/test_blacklisting.py | 1 - tests/test_email.py | 6 +----- 17 files changed, 19 insertions(+), 30 deletions(-) diff --git a/sydent/db/accounts.py b/sydent/db/accounts.py index 140e170d..52b0cb85 100644 --- a/sydent/db/accounts.py +++ b/sydent/db/accounts.py @@ -58,7 +58,7 @@ def storeAccount(self, user_id, creation_ts, consent_version): :type consent_version: str or None """ cur = self.sydent.db.cursor() - res = cur.execute( + cur.execute( "insert or ignore into accounts (user_id, created_ts, consent_version) " "values (?, ?, ?)", (user_id, creation_ts, consent_version), @@ -76,7 +76,7 @@ def setConsentVersion(self, user_id, consent_version): :type consent_version: unicode or None """ cur = self.sydent.db.cursor() - res = cur.execute( + cur.execute( "update accounts set consent_version = ? where user_id = ?", (consent_version, user_id), ) @@ -92,7 +92,7 @@ def addToken(self, user_id, token): :type token: unicode """ cur = self.sydent.db.cursor() - res = cur.execute( + cur.execute( "insert into tokens (user_id, token) values (?, ?)", (user_id, token), ) @@ -106,7 +106,7 @@ def delToken(self, token): :type token: unicode """ cur = self.sydent.db.cursor() - res = cur.execute( + cur.execute( "delete from tokens where token = ?", (token,), ) diff --git a/sydent/db/sqlitedb.py b/sydent/db/sqlitedb.py index fb685742..8630d227 100644 --- a/sydent/db/sqlitedb.py +++ b/sydent/db/sqlitedb.py @@ -54,7 +54,7 @@ def _createSchema(self): try: logger.info("Importing %s", scriptPath) c.executescript(fp.read()) - except: + except Exception: logger.error("Error importing %s", scriptPath) raise fp.close() @@ -212,7 +212,7 @@ def _upgradeSchema(self): def _getSchemaVersion(self): cur = self.db.cursor() - res = cur.execute("PRAGMA user_version") + cur.execute("PRAGMA user_version") row = cur.fetchone() return row[0] @@ -220,4 +220,4 @@ def _setSchemaVersion(self, ver): cur = self.db.cursor() # NB. pragma doesn't support variable substitution so we # do it in python (as a decimal so we don't risk SQL injection) - res = cur.execute("PRAGMA user_version = %d" % (ver,)) + cur.execute("PRAGMA user_version = %d" % (ver,)) diff --git a/sydent/db/terms.py b/sydent/db/terms.py index bb8d1942..6e27715a 100644 --- a/sydent/db/terms.py +++ b/sydent/db/terms.py @@ -55,7 +55,7 @@ def addAgreedUrls(self, user_id, urls): :type urls: list[unicode] """ cur = self.sydent.db.cursor() - res = cur.executemany( + cur.executemany( "insert or ignore into accepted_terms_urls (user_id, url) values (?, ?)", ((user_id, u) for u in urls), ) diff --git a/sydent/http/federation_tls_options.py b/sydent/http/federation_tls_options.py index a830ed0e..56ef283f 100644 --- a/sydent/http/federation_tls_options.py +++ b/sydent/http/federation_tls_options.py @@ -19,7 +19,6 @@ from twisted.internet import ssl from twisted.internet.interfaces import IOpenSSLClientConnectionCreator from twisted.internet.abstract import isIPAddress, isIPv6Address -from twisted.internet._sslverify import ClientTLSOptions def _tolerateErrors(wrapped): diff --git a/sydent/http/httpclient.py b/sydent/http/httpclient.py index 7366d707..b4251920 100644 --- a/sydent/http/httpclient.py +++ b/sydent/http/httpclient.py @@ -20,7 +20,7 @@ from io import BytesIO from twisted.internet import defer -from twisted.web.client import FileBodyProducer, Agent, readBody +from twisted.web.client import FileBodyProducer, Agent from twisted.web.http_headers import Headers from sydent.http.blacklisting_reactor import BlacklistingReactorWrapper @@ -60,7 +60,7 @@ def get_json(self, uri, max_size=None): try: # json.loads doesn't allow bytes in Python 3.5 json_body = json_decoder.decode(body.decode("UTF-8")) - except Exception as e: + except Exception: logger.exception("Error parsing JSON from %s", uri) raise defer.returnValue(json_body) diff --git a/sydent/http/matrixfederationagent.py b/sydent/http/matrixfederationagent.py index 91c2ee53..cbdf8893 100644 --- a/sydent/http/matrixfederationagent.py +++ b/sydent/http/matrixfederationagent.py @@ -30,7 +30,7 @@ from twisted.web.http_headers import Headers from twisted.web.iweb import IAgent -from sydent.http.httpcommon import BodyExceededMaxSize, read_body_with_max_size +from sydent.http.httpcommon import read_body_with_max_size from sydent.http.srvresolver import SrvResolver, pick_server_from_list from sydent.util import json_decoder from sydent.util.ttlcache import TTLCache diff --git a/sydent/http/servlets/blindlysignstuffservlet.py b/sydent/http/servlets/blindlysignstuffservlet.py index b79b8bf1..401363a5 100644 --- a/sydent/http/servlets/blindlysignstuffservlet.py +++ b/sydent/http/servlets/blindlysignstuffservlet.py @@ -63,7 +63,7 @@ def render_POST(self, request): "ed25519", "0", private_key_base64 ) signed = signedjson.sign.sign_json(to_sign, self.server_name, private_key) - except: + except Exception: logger.exception("signing failed") raise MatrixRestError(500, "M_UNKNOWN", "Internal Server Error") diff --git a/sydent/http/servlets/emailservlet.py b/sydent/http/servlets/emailservlet.py index fe380c2e..2850fe09 100644 --- a/sydent/http/servlets/emailservlet.py +++ b/sydent/http/servlets/emailservlet.py @@ -106,7 +106,7 @@ def render_GET(self, request): resp = None try: resp = self.do_validate_request(request) - except: + except Exception: pass if resp and "success" in resp and resp["success"]: msg = "Verification successful! Please return to your Matrix client to continue." diff --git a/sydent/http/servlets/lookupservlet.py b/sydent/http/servlets/lookupservlet.py index 03465fcf..a4b1e6d0 100644 --- a/sydent/http/servlets/lookupservlet.py +++ b/sydent/http/servlets/lookupservlet.py @@ -22,7 +22,7 @@ import logging import signedjson.sign -from sydent.http.servlets import get_args, jsonwrap, send_cors, MatrixRestError +from sydent.http.servlets import get_args, jsonwrap, send_cors from sydent.util import json_decoder @@ -61,7 +61,7 @@ def render_GET(self, request): return {} sgassoc = json_decoder.decode(sgassoc) - if not self.sydent.server_name in sgassoc["signatures"]: + if self.sydent.server_name not in sgassoc["signatures"]: # We have not yet worked out what the proper trust model should be. # # Maybe clients implicitly trust a server they talk to (and so we diff --git a/sydent/http/servlets/registerservlet.py b/sydent/http/servlets/registerservlet.py index b39799fb..f233774d 100644 --- a/sydent/http/servlets/registerservlet.py +++ b/sydent/http/servlets/registerservlet.py @@ -19,10 +19,9 @@ from twisted.internet import defer import logging -import json from six.moves import urllib -from sydent.http.servlets import get_args, jsonwrap, deferjsonwrap, send_cors +from sydent.http.servlets import get_args, deferjsonwrap, send_cors from sydent.http.httpclient import FederationHttpClient from sydent.users.tokens import issueToken from sydent.util.stringutils import is_valid_matrix_server_name diff --git a/sydent/http/servlets/replication.py b/sydent/http/servlets/replication.py index 7081a1f4..351e2cd9 100644 --- a/sydent/http/servlets/replication.py +++ b/sydent/http/servlets/replication.py @@ -142,7 +142,7 @@ def render_POST(self, request): logger.info( "Stored association origin ID %s from %s", originId, peer.servername ) - except: + except Exception: failedIds.append(originId) logger.warn( "Failed to verify signed association from %s with origin ID %s", diff --git a/sydent/http/servlets/threepidunbindservlet.py b/sydent/http/servlets/threepidunbindservlet.py index a72b1850..2848324b 100644 --- a/sydent/http/servlets/threepidunbindservlet.py +++ b/sydent/http/servlets/threepidunbindservlet.py @@ -16,7 +16,6 @@ # limitations under the License. from __future__ import absolute_import -import json import logging from sydent.hs_federation.verifier import NoAuthenticationError, InvalidServerName diff --git a/sydent/replication/__init__.py b/sydent/replication/__init__.py index 8b137891..e69de29b 100644 --- a/sydent/replication/__init__.py +++ b/sydent/replication/__init__.py @@ -1 +0,0 @@ - diff --git a/sydent/replication/peer.py b/sydent/replication/peer.py index f4ab39e7..7bb50933 100644 --- a/sydent/replication/peer.py +++ b/sydent/replication/peer.py @@ -190,7 +190,7 @@ def verifySignedAssociation(self, assoc): :param assoc: A signed association. :type assoc: dict[any, any] """ - if not "signatures" in assoc: + if "signatures" not in assoc: raise NoSignaturesException() key_ids = signedjson.sign.signature_ids(assoc, self.servername) diff --git a/sydent/util/emailutils.py b/sydent/util/emailutils.py index 24d20783..ea3376cc 100644 --- a/sydent/util/emailutils.py +++ b/sydent/util/emailutils.py @@ -31,8 +31,6 @@ else: from html import escape -import email.utils - from sydent.util import time_msec from sydent.util.tokenutils import generateAlphanumericTokenOfLength diff --git a/tests/test_blacklisting.py b/tests/test_blacklisting.py index e91c5d2a..9f8032a5 100644 --- a/tests/test_blacklisting.py +++ b/tests/test_blacklisting.py @@ -14,7 +14,6 @@ from mock import patch -from netaddr import IPSet from twisted.internet import defer from twisted.internet.error import DNSLookupError from twisted.test.proto_helpers import StringTransport diff --git a/tests/test_email.py b/tests/test_email.py index a1d06212..58929737 100644 --- a/tests/test_email.py +++ b/tests/test_email.py @@ -13,14 +13,10 @@ # limitations under the License. import os.path -from mock import Mock, patch +from mock import patch -from twisted.web.client import Response from twisted.trial import unittest -from sydent.db.invite_tokens import JoinTokenStore -from sydent.http.httpclient import FederationHttpClient -from sydent.http.servlets.store_invite_servlet import StoreInviteServlet from tests.utils import make_request, make_sydent