django_socio_grpc.protobuf.generation_plugin

Module Contents

Classes

BaseGenerationPlugin

The base class to create generation plugins.

BaseAddFieldRequestGenerationPlugin

Util class to inherit for adding a field in a request proto message. By inerhit it and fill field_name, field_cardinality and field_type it will create a plugin that add a field without having to override any method.

FilterGenerationPlugin

Plugin to add the _filters field in the request ProtoMessage. See https://django-socio-grpc.readthedocs.io/en/stable/features/filters.html#djangofilterbackend

PaginationGenerationPlugin

Plugin to add the _pagination field in the request ProtoMessage. See https://django-socio-grpc.readthedocs.io/en/stable/features/pagination.html

AsListGenerationPlugin

Plugin allowing to encapsulate a message into an other message and put it as a repeated field to return multiple instance. Do not use directly, use one of it’s subclass RequestAsListGenerationPlugin, ResponseAsListGenerationPlugin or RequestAndResponseAsListGenerationPlugin

RequestAsListGenerationPlugin

Transform a request ProtoMessage in a list ProtoMessage

ResponseAsListGenerationPlugin

Transform a response ProtoMessage in a list ProtoMessage

RequestAndResponseAsListGenerationPlugin

Transform both request and response ProtoMessage in list ProtoMessage

ListGenerationPlugin

Transform both request and response ProtoMessage in list ProtoMessage

BaseEnumGenerationPlugin

InMessageEnumGenerationPlugin

InMessageWrappedEnumGenerationPlugin

GlobalScopeEnumGenerationPlugin

GlobalScopeWrappedEnumGenerationPlugin

Data

logger

API

django_socio_grpc.protobuf.generation_plugin.logger

‘getLogger(…)’

class django_socio_grpc.protobuf.generation_plugin.BaseGenerationPlugin

The base class to create generation plugins.

check_condition(service: type[django_socio_grpc.services.Service], request_message: django_socio_grpc.protobuf.proto_classes.ProtoMessage | str, response_message: django_socio_grpc.protobuf.proto_classes.ProtoMessage | str, message_name_constructor: django_socio_grpc.protobuf.message_name_constructor.MessageNameConstructor) bool

Method that allow to return without modifying the proto if some conditions are not met

transform_request_message(service: type[django_socio_grpc.services.Service], proto_message: django_socio_grpc.protobuf.proto_classes.ProtoMessage | str, message_name_constructor: django_socio_grpc.protobuf.message_name_constructor.MessageNameConstructor) django_socio_grpc.protobuf.proto_classes.ProtoMessage

The actual method that transform the request ProtoMessage

transform_response_message(service: type[django_socio_grpc.services.Service], proto_message: django_socio_grpc.protobuf.proto_classes.ProtoMessage | str, message_name_constructor: django_socio_grpc.protobuf.message_name_constructor.MessageNameConstructor) django_socio_grpc.protobuf.proto_classes.ProtoMessage

The actual method that transform the response ProtoMessage

run_validation_and_transform(service: type[django_socio_grpc.services.Service], request_message: django_socio_grpc.protobuf.proto_classes.ProtoMessage | str, response_message: django_socio_grpc.protobuf.proto_classes.ProtoMessage | str, message_name_constructor: django_socio_grpc.protobuf.message_name_constructor.MessageNameConstructor) tuple[django_socio_grpc.protobuf.proto_classes.ProtoMessage, django_socio_grpc.protobuf.proto_classes.ProtoMessage]

The main orchestrator method of the plugin. This is the first entrypoint. It check the confition setted by check_condition method and then call transform_request_message and transform_response_message

class django_socio_grpc.protobuf.generation_plugin.BaseAddFieldRequestGenerationPlugin(*args, **kwargs)

Bases: django_socio_grpc.protobuf.generation_plugin.BaseGenerationPlugin

Util class to inherit for adding a field in a request proto message. By inerhit it and fill field_name, field_cardinality and field_type it will create a plugin that add a field without having to override any method.

Initialization

field_name: str

None

field_type: str | django_socio_grpc.protobuf.proto_classes.ProtoMessage

None

field_cardinality: django_socio_grpc.protobuf.proto_classes.FieldCardinality

None

transform_request_message(service: type[django_socio_grpc.services.Service], proto_message: django_socio_grpc.protobuf.proto_classes.ProtoMessage | str, message_name_constructor: django_socio_grpc.protobuf.message_name_constructor.MessageNameConstructor)
class django_socio_grpc.protobuf.generation_plugin.FilterGenerationPlugin(display_warning_message=True)

Bases: django_socio_grpc.protobuf.generation_plugin.BaseAddFieldRequestGenerationPlugin

Plugin to add the _filters field in the request ProtoMessage. See https://django-socio-grpc.readthedocs.io/en/stable/features/filters.html#djangofilterbackend

Initialization

field_name: str

‘_filters’

field_type: str | django_socio_grpc.protobuf.proto_classes.ProtoMessage

‘google.protobuf.Struct’

field_cardinality: django_socio_grpc.protobuf.proto_classes.FieldCardinality

None

check_condition(service: type[django_socio_grpc.services.Service], request_message: django_socio_grpc.protobuf.proto_classes.ProtoMessage | str, response_message: django_socio_grpc.protobuf.proto_classes.ProtoMessage | str, message_name_constructor: django_socio_grpc.protobuf.message_name_constructor.MessageNameConstructor) bool
class django_socio_grpc.protobuf.generation_plugin.PaginationGenerationPlugin(display_warning_message=True)

Bases: django_socio_grpc.protobuf.generation_plugin.BaseAddFieldRequestGenerationPlugin

Plugin to add the _pagination field in the request ProtoMessage. See https://django-socio-grpc.readthedocs.io/en/stable/features/pagination.html

Initialization

field_name: str

‘_pagination’

field_type: str | django_socio_grpc.protobuf.proto_classes.ProtoMessage

‘google.protobuf.Struct’

field_cardinality: django_socio_grpc.protobuf.proto_classes.FieldCardinality

None

check_condition(service: type[django_socio_grpc.services.Service], request_message: django_socio_grpc.protobuf.proto_classes.ProtoMessage | str, response_message: django_socio_grpc.protobuf.proto_classes.ProtoMessage | str, message_name_constructor: django_socio_grpc.protobuf.message_name_constructor.MessageNameConstructor) bool
class django_socio_grpc.protobuf.generation_plugin.AsListGenerationPlugin

Bases: django_socio_grpc.protobuf.generation_plugin.BaseGenerationPlugin

Plugin allowing to encapsulate a message into an other message and put it as a repeated field to return multiple instance. Do not use directly, use one of it’s subclass RequestAsListGenerationPlugin, ResponseAsListGenerationPlugin or RequestAndResponseAsListGenerationPlugin

list_field_name: str

‘results’

transform_message_to_list(service: type[django_socio_grpc.services.Service], proto_message: django_socio_grpc.protobuf.proto_classes.ProtoMessage | str, list_name: str) django_socio_grpc.protobuf.proto_classes.ProtoMessage
class django_socio_grpc.protobuf.generation_plugin.RequestAsListGenerationPlugin

Bases: django_socio_grpc.protobuf.generation_plugin.AsListGenerationPlugin

Transform a request ProtoMessage in a list ProtoMessage

transform_request_message(service: type[django_socio_grpc.services.Service], proto_message: django_socio_grpc.protobuf.proto_classes.ProtoMessage | str, message_name_constructor: django_socio_grpc.protobuf.message_name_constructor.MessageNameConstructor) django_socio_grpc.protobuf.proto_classes.ProtoMessage
class django_socio_grpc.protobuf.generation_plugin.ResponseAsListGenerationPlugin

Bases: django_socio_grpc.protobuf.generation_plugin.AsListGenerationPlugin

Transform a response ProtoMessage in a list ProtoMessage

transform_response_message(service: type[django_socio_grpc.services.Service], proto_message: django_socio_grpc.protobuf.proto_classes.ProtoMessage | str, message_name_constructor: django_socio_grpc.protobuf.message_name_constructor.MessageNameConstructor) django_socio_grpc.protobuf.proto_classes.ProtoMessage
class django_socio_grpc.protobuf.generation_plugin.RequestAndResponseAsListGenerationPlugin

Bases: django_socio_grpc.protobuf.generation_plugin.RequestAsListGenerationPlugin, django_socio_grpc.protobuf.generation_plugin.ResponseAsListGenerationPlugin

Transform both request and response ProtoMessage in list ProtoMessage

class django_socio_grpc.protobuf.generation_plugin.ListGenerationPlugin

Bases: django_socio_grpc.protobuf.generation_plugin.RequestAsListGenerationPlugin, django_socio_grpc.protobuf.generation_plugin.ResponseAsListGenerationPlugin

Transform both request and response ProtoMessage in list ProtoMessage

request: bool

False

response: bool

False

transform_response_message(service: type[django_socio_grpc.services.Service], proto_message: django_socio_grpc.protobuf.proto_classes.ProtoMessage | str, message_name_constructor: django_socio_grpc.protobuf.message_name_constructor.MessageNameConstructor) django_socio_grpc.protobuf.proto_classes.ProtoMessage
transform_request_message(service: type[django_socio_grpc.services.Service], proto_message: django_socio_grpc.protobuf.proto_classes.ProtoMessage | str, message_name_constructor: django_socio_grpc.protobuf.message_name_constructor.MessageNameConstructor) django_socio_grpc.protobuf.proto_classes.ProtoMessage
class django_socio_grpc.protobuf.generation_plugin.BaseEnumGenerationPlugin

Bases: django_socio_grpc.protobuf.generation_plugin.BaseGenerationPlugin

non_annotated_generation: bool

False

transform_request_message(service: type[django_socio_grpc.services.Service], proto_message: django_socio_grpc.protobuf.proto_classes.ProtoMessage | str, message_name_constructor: django_socio_grpc.protobuf.message_name_constructor.MessageNameConstructor)
handle_serializer(proto_message: django_socio_grpc.protobuf.proto_classes.ProtoMessage)

Handle enum generation for a ProtoMessage that has a serializer.

An enum can be generated either from:

  • An Annotated Enum (e.g. Annotated[models.CharField, MyTextChoices])

  • A ChoiceField with string choices (e.g. [“CHOICE_1”, “CHOICE_2”]) if non_annotated_generation is True

handle_field_dict(proto_message: django_socio_grpc.protobuf.proto_classes.ProtoMessage)
transform_response_message(service: type[django_socio_grpc.services.Service], proto_message: django_socio_grpc.protobuf.proto_classes.ProtoMessage | str, message_name_constructor: django_socio_grpc.protobuf.message_name_constructor.MessageNameConstructor) django_socio_grpc.protobuf.proto_classes.ProtoMessage
abstract set_field_type(field: django_socio_grpc.protobuf.proto_classes.ProtoField, enum: enum.Enum)
choice_field_contain_buildable_enum(field: rest_framework.serializers.ChoiceField) bool
check_annotated_enum_coherence(enum: enum.Enum, field: rest_framework.serializers.ChoiceField)
build_enum_from_choice_field(field: rest_framework.serializers.ChoiceField)
get_enum_from_choice_field(field: rest_framework.serializers.ChoiceField) enum.Enum | None
class django_socio_grpc.protobuf.generation_plugin.InMessageEnumGenerationPlugin

Bases: django_socio_grpc.protobuf.generation_plugin.BaseEnumGenerationPlugin

set_field_type(field: django_socio_grpc.protobuf.proto_classes.ProtoField, enum: enum.Enum)
class django_socio_grpc.protobuf.generation_plugin.InMessageWrappedEnumGenerationPlugin

Bases: django_socio_grpc.protobuf.generation_plugin.BaseEnumGenerationPlugin

set_field_type(field: django_socio_grpc.protobuf.proto_classes.ProtoField, enum: enum.Enum)
class django_socio_grpc.protobuf.generation_plugin.GlobalScopeEnumGenerationPlugin

Bases: django_socio_grpc.protobuf.generation_plugin.BaseEnumGenerationPlugin

set_field_type(field: django_socio_grpc.protobuf.proto_classes.ProtoField, enum: enum.Enum)
class django_socio_grpc.protobuf.generation_plugin.GlobalScopeWrappedEnumGenerationPlugin

Bases: django_socio_grpc.protobuf.generation_plugin.BaseEnumGenerationPlugin

set_field_type(field: django_socio_grpc.protobuf.proto_classes.ProtoField, enum: enum.Enum)