This is an automated email from the ASF dual-hosted git repository.

sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-ponymail-foal.git


The following commit(s) were added to refs/heads/master by this push:
     new 51cd0cf  Pylint fixes
51cd0cf is described below

commit 51cd0cfbba6404022f8aea17c386502c7791b32b
Author: Sebb <[email protected]>
AuthorDate: Fri May 14 22:50:06 2021 +0100

    Pylint fixes
---
 server/plugins/aaa.py          | 15 ++++-----------
 server/plugins/background.py   |  1 -
 server/plugins/defuzzer.py     |  2 +-
 server/plugins/formdata.py     | 12 ++++++------
 server/plugins/mbox.py         | 16 +++++++---------
 server/plugins/oauthGeneric.py |  2 +-
 server/plugins/oauthGithub.py  |  3 +--
 server/plugins/oauthGoogle.py  |  2 +-
 server/plugins/session.py      |  1 -
 9 files changed, 21 insertions(+), 33 deletions(-)

diff --git a/server/plugins/aaa.py b/server/plugins/aaa.py
index 6c31780..07ee695 100644
--- a/server/plugins/aaa.py
+++ b/server/plugins/aaa.py
@@ -28,19 +28,12 @@ def can_access_email(session: 
plugins.session.SessionObject, email) -> bool:
     # If public email, it can always be accessed
     if not email.get("private"):
         return True
-    else:
-        # If user can access the list, they can read the email
-        if can_access_list(session, email.get("list_raw")):
-            return True
-        # If no access to list and email is private, deny access to email.
-        else:
-            return False
+    # If user can access the list, they can read the email
+    return can_access_list(session, email.get("list_raw"))
 
-
-def can_access_list(session: plugins.session.SessionObject, listid) -> bool:
+def can_access_list(session: plugins.session.SessionObject, _listid) -> bool:
     """Determine if a list can be accessed by the current user"""
     # If logged in via a known oauth, we assume access for now...TO BE CHANGED
     if session.credentials and session.credentials.authoritative:
         return True
-    else:
-        return False
+    return False
diff --git a/server/plugins/background.py b/server/plugins/background.py
index f70e411..0211c43 100644
--- a/server/plugins/background.py
+++ b/server/plugins/background.py
@@ -4,7 +4,6 @@ import re
 import sys
 import time
 
-from elasticsearch import AsyncElasticsearch
 from elasticsearch_dsl import Search
 
 import plugins.configuration
diff --git a/server/plugins/defuzzer.py b/server/plugins/defuzzer.py
index 7999fba..9c22edc 100644
--- a/server/plugins/defuzzer.py
+++ b/server/plugins/defuzzer.py
@@ -40,7 +40,7 @@ def defuzz(formdata: dict, nodate: bool = False) -> dict:
     if "s" in formdata and "e" in formdata:
         syear, smonth = formdata["s"].split("-")
         eyear, emonth = formdata["e"].split("-")
-        estart, eend = calendar.monthrange(int(eyear), int(emonth))
+        _estart, eend = calendar.monthrange(int(eyear), int(emonth))
         daterange = {
             "gt": "%04u/%02u/01 00:00:00" % (int(syear), int(smonth)),
             "lt": "%04u/%02u/%02u 23:59:59" % (int(eyear), int(emonth), eend),
diff --git a/server/plugins/formdata.py b/server/plugins/formdata.py
index 71cb8fa..a445e22 100644
--- a/server/plugins/formdata.py
+++ b/server/plugins/formdata.py
@@ -30,8 +30,8 @@ async def parse_formdata(body_type, request: 
aiohttp.web.BaseRequest) -> dict:
                             js, dict
                         )  # json data MUST be an dictionary object, {...}
                         indata.update(js)
-                    except ValueError:
-                        raise ValueError(ERRONEOUS_PAYLOAD)
+                    except ValueError as e:
+                        raise ValueError(ERRONEOUS_PAYLOAD) from e
                 elif body_type == "form":
                     if (
                         request.headers.get("content-type", "").lower()
@@ -40,8 +40,8 @@ async def parse_formdata(body_type, request: 
aiohttp.web.BaseRequest) -> dict:
                         try:
                             for key, val in urllib.parse.parse_qsl(body):
                                 indata[key] = val
-                        except ValueError:
-                            raise ValueError(ERRONEOUS_PAYLOAD)
+                        except ValueError as e:
+                            raise ValueError(ERRONEOUS_PAYLOAD) from e
                     # If multipart, turn our body into a BytesIO object and 
use multipart on it
                     elif (
                         "multipart/form-data"
@@ -59,8 +59,8 @@ async def parse_formdata(body_type, request: 
aiohttp.web.BaseRequest) -> dict:
                                         len(body),
                                     ):
                                         indata[part.name] = part.value
-                                except ValueError:
-                                    raise ValueError(ERRONEOUS_PAYLOAD)
+                                except ValueError as e:
+                                    raise ValueError(ERRONEOUS_PAYLOAD) from e
             finally:
                 pass
     return indata
diff --git a/server/plugins/mbox.py b/server/plugins/mbox.py
index 73095d0..4ecb2be 100644
--- a/server/plugins/mbox.py
+++ b/server/plugins/mbox.py
@@ -76,9 +76,8 @@ def extract_name(addr):
     m = re.match(r"^([^<]+)\s*<(.+)>$", addr)
     if m:
         return [m.group(1), m.group(2)]
-    else:
-        addr = addr.strip("<>")
-        return [addr, addr]
+    addr = addr.strip("<>")
+    return [addr, addr]
 
 
 def anonymize(doc):
@@ -89,7 +88,7 @@ def anonymize(doc):
         ptr = doc["_source"]
 
     if "from" in ptr:
-        frname, fremail = extract_name(ptr["from"])
+        _frname, fremail = extract_name(ptr["from"])
         ptr["md5"] = hashlib.md5(
             bytes(fremail.lower(), encoding="ascii", errors="replace")
         ).hexdigest()
@@ -124,8 +123,7 @@ async def find_parent(session, doc: typing.Dict[str, str]):
         # Did we find something, and can the user access it?
         if not newdoc or not plugins.aaa.can_access_email(session, newdoc):
             break
-        else:
-            doc = newdoc
+        doc = newdoc
     return doc
 
 
@@ -148,7 +146,7 @@ async def fetch_children(session, pdoc, counter=0, 
pdocs=None, short=False):
             continue
         if plugins.aaa.can_access_email(session, doc):
             if doc["mid"] not in pdocs:
-                mykids, myemails, pdocs = await fetch_children(
+                mykids, _myemails, pdocs = await fetch_children(
                     session, doc, counter, pdocs, short=short
                 )
                 if short:
@@ -282,6 +280,7 @@ def get_list(session, listid, fr=None, to=None, 
limit=10000):
     """
     Loads emails from a specified list.
     If fr and to are not specified, loads the last 30 days.
+    TODO: use fr and to
     """
     res = session.DB.ES.search(
         index=session.DB.dbs.mbox,
@@ -366,8 +365,7 @@ def is_public(session: plugins.session.SessionObject, 
listname):
         listname = f"{lname}@{ldomain}"
     if listname in session.server.data.lists:
         return not session.server.data.lists[listname]["private"]
-    else:
-        return False  # Default to not public
+    return False  # Default to not public
 
 
 async def get_list_stats(session, maxage="90d", admin=False):
diff --git a/server/plugins/oauthGeneric.py b/server/plugins/oauthGeneric.py
index 78b1e74..47711a5 100644
--- a/server/plugins/oauthGeneric.py
+++ b/server/plugins/oauthGeneric.py
@@ -3,7 +3,7 @@ import re
 import aiohttp.client
 
 
-async def process(formdata, session, server):
+async def process(formdata, _session, _server):
     js = None
     m = re.match(r"https?://(.+)/", formdata["oauth_token"])
     if m:
diff --git a/server/plugins/oauthGithub.py b/server/plugins/oauthGithub.py
index e724d89..315fe7c 100644
--- a/server/plugins/oauthGithub.py
+++ b/server/plugins/oauthGithub.py
@@ -8,13 +8,12 @@
       github_client_secret: bcfdgefa572564576
 """
 
-import re
 import aiohttp.client
 import plugins.server
 import typing
 
 
-async def process(formdata, session, server: plugins.server.BaseServer) -> 
typing.Optional[dict]:
+async def process(formdata, _session, server: plugins.server.BaseServer) -> 
typing.Optional[dict]:
     formdata["client_id"] = server.config.oauth.github_client_id
     formdata["client_secret"] = server.config.oauth.github_client_secret
     headers = {"Accept": "application/json"}
diff --git a/server/plugins/oauthGoogle.py b/server/plugins/oauthGoogle.py
index f3aa001..1078ea9 100644
--- a/server/plugins/oauthGoogle.py
+++ b/server/plugins/oauthGoogle.py
@@ -12,7 +12,7 @@ import plugins.server
 import plugins.session
 
 
-async def process(formdata, session, server: plugins.server.BaseServer):
+async def process(formdata, _session, server: plugins.server.BaseServer):
     js = None
     request = google.auth.transport.urllib3.Request()
     # This is a synchronous process, so we offload it to an async runner in 
order to let the main loop continue.
diff --git a/server/plugins/session.py b/server/plugins/session.py
index b119a45..ad5562d 100644
--- a/server/plugins/session.py
+++ b/server/plugins/session.py
@@ -27,7 +27,6 @@ import aiohttp.web
 import plugins.database
 import plugins.server
 import copy
-import typing
 
 FOAL_MAX_SESSION_AGE = 86400 * 7  # Max 1 week between visits before voiding a 
session
 FOAL_SAVE_SESSION_INTERVAL = 3600  # Update sessions on disk max once per hour

Reply via email to