Browse Source

Automatic formatting commit: 2020-04-09T21:54:06.621360

Getty Ritter 4 years ago
parent
commit
5358a3d14e
3 changed files with 16 additions and 10 deletions
  1. 14 9
      lc/app.py
  2. 1 1
      lc/config.py
  3. 1 0
      lc/error.py

+ 14 - 9
lc/app.py

@@ -26,21 +26,21 @@ class Endpoint:
 
         # try finding the token
         token = None
-        if (auth := flask.request.headers['Authorization']):
+        if (auth := flask.request.headers["Authorization"]) :
             token = auth.split()[1]
-        elif flask.session['auth']:
-            token = flask.session['auth']
+        elif flask.session["auth"]:
+            token = flask.session["auth"]
 
         if token and (payload := c.SERIALIZER.loads(token)):
-            if 'name' not in payload or 'password' not in payload:
+            if "name" not in payload or "password" not in payload:
                 return
 
             try:
-                u = m.User.by_slug(payload['name'])
+                u = m.User.by_slug(payload["name"])
             except e.LCException:
                 return
 
-            if u.authenticate(payload['password']):
+            if u.authenticate(payload["password"]):
                 self.user = u
 
     def require_authentication(self, name: user):
@@ -61,8 +61,10 @@ class Endpoint:
             if flask.request.method == "POST":
                 require_authentication()
                 return flask.jsonify(self.api_post(*args, **kwargs))
-            elif (flask.request.method in ["GET", "HEAD"] and
-                  flask.request.content_type == "application/json"):
+            elif (
+                flask.request.method in ["GET", "HEAD"]
+                and flask.request.content_type == "application/json"
+            ):
                 return flask.jsonify(self.api_get(*args, **kwargs))
         except e.LCException as exn:
             return ({"status": exn.http_code(), "error": str(exn)}, exn.http_code())
@@ -114,7 +116,10 @@ class GetUser(Endpoint):
         pg = int(flask.request.args.get("page", 0))
         links = u.get_links(page=pg)
         return render(
-            "main", title=f"user {u.name}", content=render("linklist", links=links), user=self.user,
+            "main",
+            title=f"user {u.name}",
+            content=render("linklist", links=links),
+            user=self.user,
         )
 
     def api_get(self, current_user, slug: str):

+ 1 - 1
lc/config.py

@@ -6,7 +6,7 @@ import playhouse.sqlite_ext
 
 DB = playhouse.sqlite_ext.SqliteExtDatabase(None)
 PER_PAGE = 50
-SERIALIZER = itsdangerous.URLSafeSerializer('TEMP KEY')
+SERIALIZER = itsdangerous.URLSafeSerializer("TEMP KEY")
 
 if sys.stderr.isatty():
 

+ 1 - 0
lc/error.py

@@ -35,6 +35,7 @@ class BadPassword(LCException):
     def __str__(self):
         return f"Wrong password for user {self.name}."
 
+
 @dataclass
 class NotImplemented(LCException):
     def __str__(self):