@@ -318,7 +318,7 @@ async def lifespan(app: FastAPI) -> AsyncGenerator[None]:
318318 if row ["allowed_chat_ids" ]:
319319 try :
320320 allowed = set (json .loads (row ["allowed_chat_ids" ]))
321- except ( json .JSONDecodeError , TypeError ) :
321+ except json .JSONDecodeError , TypeError :
322322 logger .warning (f"Skipping session with corrupted allowed_chat_ids for { row ['username' ]} " )
323323 continue
324324 _sessions [row ["token" ]] = SessionData (
@@ -498,8 +498,11 @@ async def _create_session(username: str, role: str, allowed_chat_ids: set[int] |
498498 now = time .time ()
499499 token = secrets .token_urlsafe (32 )
500500 _sessions [token ] = SessionData (
501- username = username , role = role , allowed_chat_ids = allowed_chat_ids ,
502- created_at = now , last_accessed = now ,
501+ username = username ,
502+ role = role ,
503+ allowed_chat_ids = allowed_chat_ids ,
504+ created_at = now ,
505+ last_accessed = now ,
503506 )
504507
505508 # Persist to database
@@ -563,7 +566,7 @@ async def _resolve_session(auth_cookie: str) -> SessionData | None:
563566 if row ["allowed_chat_ids" ]:
564567 try :
565568 allowed = set (json .loads (row ["allowed_chat_ids" ]))
566- except ( json .JSONDecodeError , TypeError ) :
569+ except json .JSONDecodeError , TypeError :
567570 logger .warning (f"Corrupted allowed_chat_ids for session { row ['username' ]} , denying access" )
568571 return None
569572
@@ -759,7 +762,7 @@ async def login(request: Request):
759762 if viewer ["allowed_chat_ids" ]:
760763 try :
761764 allowed = set (json .loads (viewer ["allowed_chat_ids" ]))
762- except ( json .JSONDecodeError , TypeError ) :
765+ except json .JSONDecodeError , TypeError :
763766 allowed = None
764767
765768 token = await _create_session (username , "viewer" , allowed )
@@ -1259,8 +1262,7 @@ async def internal_push(request: Request):
12591262
12601263 allowed = False
12611264 if client_host and (
1262- client_host in ("127.0.0.1" , "localhost" , "::1" )
1263- or client_host .startswith (("172." , "10." , "192.168." ))
1265+ client_host in ("127.0.0.1" , "localhost" , "::1" ) or client_host .startswith (("172." , "10." , "192.168." ))
12641266 ):
12651267 allowed = True
12661268
@@ -1436,7 +1438,7 @@ async def create_viewer(request: Request, user: UserContext = Depends(require_ma
14361438 if allowed_chat_ids is not None :
14371439 try :
14381440 chat_ids_json = json .dumps ([int (cid ) for cid in allowed_chat_ids ])
1439- except ( ValueError , TypeError ) :
1441+ except ValueError , TypeError :
14401442 raise HTTPException (status_code = 400 , detail = "Invalid chat ID format" )
14411443
14421444 account = await db .create_viewer_account (
@@ -1491,7 +1493,7 @@ async def update_viewer(viewer_id: int, request: Request, user: UserContext = De
14911493 else :
14921494 try :
14931495 updates ["allowed_chat_ids" ] = json .dumps ([int (cid ) for cid in allowed ])
1494- except ( ValueError , TypeError ) :
1496+ except ValueError , TypeError :
14951497 raise HTTPException (status_code = 400 , detail = "Invalid chat ID format" )
14961498
14971499 if "is_active" in data :
0 commit comments