producti_gestio.core package

producti_gestio.core

That’s the core part of the module. It is used to handle the requests and call the user-defined function.

producti_gestio.core.check

producti_gestio.core.check

It checks if a request is valid using Filters.

producti_gestio.core.check.check(filters: object = None) → <built-in function callable>

This function is used to check if a request is valid using filters.

It could be used only when the Server is using the function mode (alias using decorator, not handlers).

Here an example:

from producti_gestio import Server, check, Decorator, Filters

@producti_gestio.Decorator # Using this Decorator, the next function will become the server-creator function
def my_server(**kwargs):
    print("Initializing the server")

    @producti_gestio.check(Filters.get) # Using this Decorator, the handler function will check for the requirements (using Filters)
    def my_function(**kwargs):
        return {
            'response_code': 200, # The response code
            'response': {
                'ok': True,
                'message': 'Hello world!'
            }
        }

    return my_function

my_server(allow_get=True) # Create and start the server instance using threads

while True:
    pass
Parameters:
  • func (callable) – The native handler function
  • filters (Filter or None) – A Filter object or a None type
  • filters – object or None: (Default value = None)
Returns:

A callable object

Return type:

callable

producti_gestio.core.request_handler module

producti_gestio.core.request_handler

It handles the requests checking the configuration, then pass all parameters and headers to the user-defined function.

A request handler must have these requirements:

  • Have a do_GET function
  • Have a do_POST function

When a Server instance is started, the request handler will get the configuration under self.configuration and the handlers under self.handlers.

class producti_gestio.core.request_handler.RequestHandler(request, client_address, server)

Bases: http.server.BaseHTTPRequestHandler

The RequestHandler class is used to handle all requests, after they are checked using the configuration.

It has got two needed methods: do_GET and do_POST, they will be called by the HTTPServer classes, based on the type of the request.

Actually, HEAD and PUT request methods are not supported.

configuration = {'allow_get': False, 'allow_post': True, 'debug': False, 'function': <function RequestHandler.<lambda> at 0x7f58656868c8>, 'ip': '127.0.0.1', 'port': 8000}
do_GET() → bool

The GET requests handler, it checks if GET is allowed as method and then parse the request and pass it to a defined function and return a response.

Returns:True if the request succeeded, False if not or GET is not allowed.
Return type:bool
do_POST() → bool

The POST requests handler, it checks if POST is allowed as method and then parse the request and pass it to a defined function and return a response.

Returns:True if the request succeeeded, False if not or POST is not allowed.
Return type:bool
do_request(request_infos: dict) → bool

The do_request function is used to get a response from the handler function or from one of the Handlers and send it to the user.

Parameters:request_infos (dict) – A dictionary that will be passed to the Handler function or the Handler.
Returns:True if all went right, otherwise False.
Return type:bool
handlers = []
parse_post() → <function NewType.<locals>.new_type at 0x7f58656867b8>

The POST parameters parser. It checks the self.headers dictionary, its content-type and if it is ‘multipart/form-data’ or ‘application/x-www-form-urlencoded’, then parses the POST parameters.

Returns:POST parameters in a dictionary, where the keys are the parameter names and the values are their values.
Return type:dict
use_handler = False