Browse Source

Configure Flake8 and resolve errors (#347)

* Add Flake8 config
* Fix Flake8 lints
* Add newsfile

Signed-off-by: Dan Callahan <danc@element.io>
Dan Callahan 2 years ago
parent
commit
cc72969681

+ 1 - 0
changelog.d/347.misc

@@ -0,0 +1 @@
+Configure Flake8 and resolve errors.

+ 4 - 0
setup.cfg

@@ -8,3 +8,7 @@ test = trial
 
 [trial]
 test_suite = tests
+
+[flake8]
+max-line-length = 88
+extend-ignore = E203,E501,F821 # TODO: Fix E501 and F821

+ 4 - 4
sydent/db/accounts.py

@@ -58,7 +58,7 @@ class AccountStore(object):
         :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 @@ class AccountStore(object):
         :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 @@ class AccountStore(object):
         :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 @@ class AccountStore(object):
         :type token: unicode
         """
         cur = self.sydent.db.cursor()
-        res = cur.execute(
+        cur.execute(
             "delete from tokens where token = ?",
             (token,),
         )

+ 3 - 3
sydent/db/sqlitedb.py

@@ -54,7 +54,7 @@ class SqliteDatabase:
             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 @@ class SqliteDatabase:
 
     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 @@ class SqliteDatabase:
         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,))

+ 1 - 1
sydent/db/terms.py

@@ -55,7 +55,7 @@ class TermsStore(object):
         :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),
         )

+ 0 - 1
sydent/http/federation_tls_options.py

@@ -19,7 +19,6 @@ from zope.interface import implementer
 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):

+ 2 - 2
sydent/http/httpclient.py

@@ -20,7 +20,7 @@ import logging
 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 @@ class HTTPClient(object):
         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)

+ 1 - 1
sydent/http/matrixfederationagent.py

@@ -30,7 +30,7 @@ from twisted.web.http import stringToDatetime
 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

+ 1 - 1
sydent/http/servlets/blindlysignstuffservlet.py

@@ -63,7 +63,7 @@ class BlindlySignStuffServlet(Resource):
                 "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")
 

+ 1 - 1
sydent/http/servlets/emailservlet.py

@@ -106,7 +106,7 @@ class EmailValidateCodeServlet(Resource):
         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."

+ 2 - 2
sydent/http/servlets/lookupservlet.py

@@ -22,7 +22,7 @@ from sydent.db.threepid_associations import GlobalAssociationStore
 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 @@ class LookupServlet(Resource):
             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

+ 1 - 2
sydent/http/servlets/registerservlet.py

@@ -19,10 +19,9 @@ from twisted.web.resource import Resource
 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

+ 1 - 1
sydent/http/servlets/replication.py

@@ -142,7 +142,7 @@ class ReplicationPushServlet(Resource):
                 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",

+ 0 - 1
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

+ 0 - 1
sydent/replication/__init__.py

@@ -1 +0,0 @@
-

+ 1 - 1
sydent/replication/peer.py

@@ -190,7 +190,7 @@ class RemotePeer(Peer):
         :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)

+ 0 - 2
sydent/util/emailutils.py

@@ -31,8 +31,6 @@ if six.PY2:
 else:
     from html import escape
 
-import email.utils
-
 from sydent.util import time_msec
 from sydent.util.tokenutils import generateAlphanumericTokenOfLength
 

+ 0 - 1
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

+ 1 - 5
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