Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Address flake8 linting/formatting issues #19

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/bgsexception.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def __init__(self, message, original_exception=None):
super().__init__(message)
self.original_exception = original_exception


class BgsNotFoundException(BgsException):
"""
Not Found Exception
Expand Down
2 changes: 2 additions & 0 deletions src/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
HEADER_CORRELATION_ID = "OSC-DM-Correlation-ID"
USERNAME_UNKNOWN = "unknown"


class LoggingMiddleware(BaseHTTPMiddleware):
"""
FastAPI middleware is used to add processing to
Expand Down Expand Up @@ -157,6 +158,7 @@ async def stream_response(self, send: Send):
def body(self):
return b"".join(self.body_chunks).decode("utf-8")


def _safe_decode(data):
try:
return data.decode('utf-8')
Expand Down
7 changes: 3 additions & 4 deletions src/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

import uvicorn as uvicorn
import yaml
from fastapi import FastAPI, HTTPException
from fastapi import FastAPI

import state

Expand Down Expand Up @@ -55,6 +55,7 @@
app = FastAPI()
app.add_middleware(LoggingMiddleware)


@app.on_event("startup")
async def startup_event():
"""
Expand Down Expand Up @@ -191,8 +192,6 @@ async def _repeat_every(interval_sec, func, *args):
await asyncio.sleep(interval_sec)




#####
# MAINLINE
#####
Expand Down Expand Up @@ -250,4 +249,4 @@ async def _repeat_every(interval_sec, func, *args):
except Exception as e:
logger.info(f"Stopping service, exception:{e}")
finally:
logger.info(f"Terminating service")
logger.info("Terminating service")
3 changes: 2 additions & 1 deletion src/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"""
global_state = {}

def gstate(name: str, value: any=None):

def gstate(name: str, value: any = None):
"""
Global state manager for registration state

Expand Down
14 changes: 8 additions & 6 deletions src/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@
# Created: 2024-04-15 by [email protected]

import logging
from typing import Any, Dict, List, Optional
from typing import Any, Dict, Optional

import httpx

from bgsexception import BgsException, BgsNotFoundException
from bgsexception import BgsException

LOGGING_FORMAT = "%(asctime)s - %(levelname)s - %(message)s"
logging.basicConfig(level=logging.INFO, format=LOGGING_FORMAT)
logger = logging.getLogger(__name__)


async def httprequest(host: str, port: int, service: str, method: str,
data: Optional[Any]=None, obj: Optional[Dict]=None,
files: Optional[Any]=None, headers: Optional[Dict]=None) -> Any:
data: Optional[Any] = None, obj: Optional[Dict] = None,
files: Optional[Any] = None, headers: Optional[Dict] = None) -> Any:
"""
Generic request function using the ASYNC httpx library.

Expand Down Expand Up @@ -79,9 +80,10 @@ async def httprequest(host: str, port: int, service: str, method: str,
logger.error(msg)
raise BgsException(msg)


def shttprequest(host: str, port: int, service: str, method: str,
data: Optional[Any]=None, obj: Optional[Dict]=None,
files: Optional[Any]=None, headers: Optional[Dict]=None) -> Any:
data: Optional[Any] = None, obj: Optional[Dict] = None,
files: Optional[Any] = None, headers: Optional[Dict] = None) -> Any:
"""
Generic request function using the SYNCHRONOUS requests library.

Expand Down
Loading