django_socio_grpc.grpc_actions.actions
MyMixin(GRPCActionMixin, ): … @grpc_action(request=[], response=[]) … def MyDecoratedAction(self, request, context): … pass … … def MyAction(self, request, context): … pass … … def _dynamic_grpc_action_registry(service): … return { … “MyAction”: {request=[], request_name=service.req_name, response=[]} … } … … def _before_registration(service): … service.req_name = service.name
MyService(MyMixin): … @grpc_action(request=[], response=[]) … def MyServiceAction(self, request, context): … pass … … @grpc_action(request=[], response=[]) … def MySecondServiceAction(self, request, context): … pass … … def _before_registration(service): … service.req_name = “MyReqName”
GRPCAction registration lifecycle on class definition :
—> MyService parents and MyService _before_registration methods are called.
with MyService as the argument.
—> MyService parents and MyService _dynamic_grpc_action_registry methods are called
with MyService as the argument and their returned dict is merged with decorated actions data
from MyService abstract parents. This dict is then registered.
Module Contents
Classes
Functions
Register action function_name of mixin and register them if they are decorated (so already a GRPCAction) or transform them into a GRPCAction before registering them |
Data
API
- django_socio_grpc.grpc_actions.actions.logger
‘getLogger(…)’
- django_socio_grpc.grpc_actions.actions.RequestResponseType
None
- class django_socio_grpc.grpc_actions.actions.GRPCAction
- function: collections.abc.Callable[[django_socio_grpc.services.Service, Any, django_socio_grpc.request_transformer.grpc_internal_proxy.GRPCInternalProxyContext], Any]
None
- message_name_constructor_class: type[django_socio_grpc.protobuf.message_name_constructor.MessageNameConstructor]
None
- use_generation_plugins: list[django_socio_grpc.protobuf.generation_plugin.BaseGenerationPlugin]
‘field(…)’
- proto_rpc: django_socio_grpc.protobuf.proto_classes.ProtoRpc | None
‘field(…)’
- __post_init__()
- __set_name__(owner, name)
set name function is called automatically by python and allow us to retrieve the owner(Service) instance that we need for proto registration
- __hash__()
- __get__(obj, type=None)
- __call__(*args, **kwargs)
- get_action_params()
- make_proto_rpc(action_name: str, service: type[django_socio_grpc.services.Service]) django_socio_grpc.protobuf.proto_classes.ProtoRpc
- resolve_placeholders(service_class: type[django_socio_grpc.services.Service], action: str)
Iterate over the
GRPCActionattributes and resolve all the placeholder instancesClassic placeholder usage :
@grpc_action(request=MyRequestPlaceholder, response=MyResponsePlaceholder) def MyAction(self, request, context): …
MyRequestPlaceholderandMyResponsePlaceholderare placeholder instances which are resolved with the current service by this method, allowing us to set dynamic attributes to theGRPCAction.
- clone(**kwargs)
Clones the current
GRPCActioninstance overriding the given kwargs
- django_socio_grpc.grpc_actions.actions.register_action(cls, action_name: str, name: str | None = None, **kwargs)
Register action function_name of mixin and register them if they are decorated (so already a GRPCAction) or transform them into a GRPCAction before registering them
- class django_socio_grpc.grpc_actions.actions.GRPCActionMixin
Bases:
abc.ABC- _decorated_grpc_action_registry: dict[str, dict[str, Any]]
None
Registry of grpc actions declared in the class
- proto_service: django_socio_grpc.protobuf.proto_classes.ProtoService
None
- classmethod before_registration(service_class=None)
Call all the service parents
_before_registrationmethods
- classmethod get_parents_action_registry(service)
Returns all the grpc action registries (decorated and dynamic) of all the parent mixin
- classmethod get_class_action_registry(service)
Returns all the grpc action registries (decorated and dynamic) of the class
- classmethod get_action_parents()
Returns all the GRPCActionMixin parents of the class in mro order
- classmethod register_actions()
Call the
_before_registrationmethod of all the parents Then iterate over the action registry and register the grpc actions
- _before_registration()
This should be overriden in your service or mixin if you want a specific behavior for a mixin Method called before gRPC actions registration