WhakerPy 0.8

https://sourceforge.net/projects/whakerpy/

Module whakerpy.webapp

Class WebSiteApplication

Description

Create and run a webapp applications.

Allows to create a server and a response system in order to use HTTPD like a communication system between a web-browser and a Python API.

The localhost port is randomly assigned.

Constructor

HTTPD Server initialization.

Create the application for a Web Front-End based on HTTPD protocol.

Parameters
  • server_cls
View Source
def __init__(self, server_cls):
    """HTTPD Server initialization.

    Create the application for a Web Front-End based on HTTPD protocol.

    """
    self.__location = 'localhost'
    httpd_port = random.randrange(80, 99)
    self.__port = httpd_port + httpd_port * 100
    self.__server = None
    server_address = (self.__location, self.__port)
    self.__server = server_cls(server_address, HTTPDHandler)
    self.__server.create_pages()

Public functions

client_url

Return the client URL of this server.

View Source
def client_url(self) -> str:
    """Return the client URL of this server."""
    return 'http://{:s}:{:d}/'.format(self.__location, self.__port)

run

Run the application with a main loop.

Returns
  • (int) Exit status (0=normal)
View Source
def run(self) -> int:
    """Run the application with a main loop.

        :return: (int) Exit status (0=normal)

        """
    try:
        self.__server.serve_forever()
    except KeyboardInterrupt:
        self.__server.shutdown()
    return 0