web package

Submodules

web.web_door_opener module

class web.web_door_opener.WebDoorOpener(shutdown_event: Event, config: Configuration, loop, message_task_queue: Queue, camera_task_queue_async: Queue, door_open_task_queue: Queue)

Bases: object

static create_password_hash(input)

Generates a password hash using the generate_password_hash function.

Parameters:

input (str): The password to be hashed.

Returns:

str: The hashed password.

static custom_auth_required(f)

A decorator for custom authentication required function.

error_response_json(status, error, message) dict

Returns a standard error response json :param status: Http Status code :param error: Error Code text :param message: Error message :return: dictonary :rtype: dict

favicon()

A function to serve the favicon file by sending it from the static directory.

get_brwoser_session() bool

Check the user agent in the request headers to determine if it matches any of the specified browsers.

Returns:

bool: True if the user agent matches any of the specified browsers, False otherwise.

get_request_username() str

Get the username from the request. If the browser session is active, returns the username stored in the session or ‘anonymous’ if not found. If the browser session is not active, attempts to get the username from the request authorization. If the username is not found in the request authorization, returns ‘anonymous’.

Returns:

str: The username obtained from the session or request authorization, or ‘anonymous’ if not found.

handle_401_unauthenticated()

Generates a JSON response for a 401 Unauthorized error.

This function sets the status code of the response to 401, sets the ‘WWW-Authenticate’ header to ‘Basic realm=”Main”’, and sets the ‘Location’ header to the URL of the login page.

Returns:

The JSON response with the error details.

handle_bad_request(message: str)

A method to handle a bad request error response.

Parameters:

message – A string message describing the bad request error.

Returns:

JSON response with status 400, error details, and the status code 400.

Return type:

json

handle_exception(e)

Default error exception handler for any error response. Results in http status code 500 - internal server error :param e: Error :return: http json response :rtype: json

handle_not_found(error)

A method to handle the not found error response. :param error: Error object describing the not found error :return: JSON response with status 404 and error details :rtype: json

handle_success_response(status_text, status, message)

Handles to create a success json http response :param status_text: Http status code text :param status: http status code integer :param message: a response message or dict :return: json

index(*args, **kwargs)

A description of the entire function, its parameters, and its return types.

log_request_info()

Logs information about the incoming HTTP request.

This function checks if the request is made from a browser session. If it is, and the user is ‘anonymous’ and the endpoint is not ‘login’, ‘favicon’, or ‘static’, it redirects to the ‘login’ endpoint. If the user is ‘anonymous’ and there is no browser session, it handles the 401 Unauthenticated error.

After that, it logs the user, method, path, and request headers to the logger. It also logs the request data.

Parameters:

self (WebDoorOpener): The instance of the WebDoorOpener class.

Returns:

None: If the request is redirected or if the user is ‘anonymous’ and there is no browser session. redirect: If the user is ‘anonymous’ and the endpoint is not ‘login’, ‘favicon’, or ‘static’. handle_401_unauthenticated: If the user is ‘anonymous’ and there is no browser session.

log_response_info(response)

Logs the response information including user, method, path, status, headers, and response data.

login() str

Login method for interactive browser sessions :return: html login page as string :rtype: str

open(*args, **kwargs)

A description of the entire function, its parameters, and its return types.

run()

Runs the server in debug mode if the log level is set to “DEBUG”, otherwise runs the server in non-debug mode.

This function checks the value of self.str_log_level and sets self.app.debug accordingly. If the log level is “DEBUG”, the server is started in debug mode by setting self.app.debug to True. Otherwise, the server is started in non-debug mode by setting self.app.debug to False.

Parameters:

None

Returns:

None

setup_error_handlers()

Setup error handlers for the Flask application.

Registers error handlers for the Exception and NotFound exceptions. The handle_exception method is called when an Exception occurs, and the handle_not_found method is called when a NotFound exception occurs.

This method does not take any parameters.

This method does not return anything.

setup_logging()

Set up the logging configuration for the application.

This function configures the logging level of the application logger based on the value of self.log_level.

Parameters:

None

Returns:

None

setup_routes()

Setup routes for various URLs in the web application.

shutdown()

A description of the entire function, its parameters, and its return types.

transform_values(func)

Transforms the values of the web_user_dict dictionary in the config object using the provided func function.

Args:

func (function): The function to apply to each value in the dictionary.

Returns:

dict: A new dictionary with the transformed values.

verify_password(username, password)

Verify the provided username and password for authentication.

Parameters:

username (str): The username to be verified. password (str): The password corresponding to the username.

Returns:

str or None: The authenticated username if successful, None otherwise.

Module contents