Changeset - 88b94840f125
[Not reviewed]
default
0 3 0
Dennis Fink - 3 years ago 2022-07-19 22:16:34
dennis.fink@c3l.lu
Add more typing
3 files changed with 9 insertions and 8 deletions:
0 comments (0 inline, 0 general)
spaceapi/auth.py
Show inline comments
 
from hmac import compare_digest
 
from typing import Optional
 
from typing import Optional, cast
 

	
 
from flask import current_app
 
from flask_httpauth import HTTPBasicAuth, HTTPDigestAuth
 
@@ -11,7 +11,7 @@ httpauth = HTTPDigestAuth()
 
@httpauth.get_password
 
def get_pw(username: str) -> Optional[str]:
 
    if username in current_app.config["HTTP_DIGEST_AUTH_USERS"]:
 
        return current_app.config["HTTP_DIGEST_AUTH_USERS"][username]
 
        return cast(str, current_app.config["HTTP_DIGEST_AUTH_USERS"][username])
 
    return None
 

	
 

	
spaceapi/sensors.py
Show inline comments
 
import json
 
from typing import Any, Dict, cast
 

	
 
import jsonschema
 
from flask import Blueprint, abort, current_app, jsonify, request
 
from flask import Blueprint, Response, abort, current_app, jsonify, request
 
from pkg_resources import resource_filename
 

	
 
from .auth import httpauth
 
@@ -16,12 +17,12 @@ ALLOWED_SENSORS_KEYS = json.load(
 

	
 
@sensors_views.route("/set/<key>", methods=["POST"])
 
@httpauth.login_required
 
def set_sensors(key):
 
def set_sensors(key: str) -> Response:
 

	
 
    active = ActiveStatusv14()
 

	
 
    if key in ALLOWED_SENSORS_KEYS and key in active["sensors"]:
 
        data = request.json
 
        data = cast(Dict[str, Any], request.json)
 
        try:
 
            try:
 
                jsonschema.validate(data, ALLOWED_SENSORS_KEYS[key])
spaceapi/utils.py
Show inline comments
 
@@ -54,11 +54,11 @@ RADIATON_SUBKEYS = frozenset(("alpha", "
 

	
 

	
 
class Singleton:
 
    def __new__(cls, *args, **kwargs):
 
    def __new__(cls, *args: Any, **kwargs: Any) -> Any:
 
        key = str(hash(cls))
 

	
 
        if not hasattr(cls, "_instance_dict"):
 
            cls._instance_dict = {}
 
            cls._instance_dict = {}  # type: Dict[str, Any]
 

	
 
        if key not in cls._instance_dict:
 
            cls._instance_dict[key] = super().__new__(cls, *args, **kwargs)
 
@@ -67,7 +67,7 @@ class Singleton:
 

	
 

	
 
class ActiveStatusv14(Singleton, dict):
 
    def __init__(self):
 
    def __init__(self) -> None:
 
        self.default_json_file = default_json_file_v14
 
        self.last_state_file = last_state_file_v14
 

	
0 comments (0 inline, 0 general)