producti_gestio.decorator package¶
producti_gestio.decorator module¶
producti_gestio.decorator¶
That’s the decorator part of the module. It is a simple way to create a new web-server without using directly the producti_gestio.server.server class.
producti_gestio.decorator.wrapper¶
It defines a new class with decorator-magic-methods, that will be called by the function that points to it.
The user-defined function, that’s how we’ll call the function that will be passed as the handler function, will be passed to a new Decorator instance with all of the user-passed parameters, that we’ll call configuration.
You can also use producti_gestio.handlers.handler
instead of this Decorator
.
This decorator is intended to be used when there’s one handler function. The function that is decorated using this class will become the server-creator function (calling it will create the server).
Here an example:
import producti_gestio @producti_gestio.Decorator # Use the Decorator def my_server(**kwargs): print('Creating the server') def my_function(**kwargs): return { 'response_code': 200, 'response': { 'ok': True, 'message': 'Hello world!' } } return my_function # Return the handler function my_server(allow_get=True) # Create and start the server instance
You can also use the producti_gestio.core.check()
function to use Filters
.
-
class
producti_gestio.decorator.wrapper.
Decorator
(call: <function NewType.<locals>.new_type at 0x7f5865686840>)¶ Bases:
object
The Decorator class that launch automatically the server and uses the user-defined function.
It has got just magic methods.
-
__call__
(**kwargs) → bool¶ It launches the server and sets the handler function.
Parameters: kwargs – The chosen configuration. See producti_gestio.server.Server
.Returns: True if all went well, False if not Return type: bool
-
__init__
(call: <function NewType.<locals>.new_type at 0x7f5865686840>)¶ It sets the server-creator function and creates the instance. Before setting the function, it checks if it is callable or not, and the response depends on that.
Parameters: call (handler_function) – The user-defined function Raises: NotAFunction
– It throws a NotAFunction exception if the given parameter is not a function
-
__repr__
() → str¶ It returns a representation of the object.
Returns: A representation of the object Return type: str
-
server
= None¶
-