django_socio_grpc.protobuf.proto_classes

Module Contents

Classes

ProtoComment

This class is used to represent a comment in a proto file. It allows adding a comment in a serializer field help_text.

ProtoField

Represents a field in a proto message.

ProtoEnumLocations

ProtoEnum

ProtoMessage

Represents a proto message with its fields and comments

RequestProtoMessage

ResponseProtoMessage

ProtoRpc

Represent a RPC method in a service

ProtoService

Represents a service in a proto file

ProtoFieldConvertible

Mixin to convert a class to a ProtoField

Functions

get_proto_type

Return the proto type of a field, fields can either implement a proto_type attribute or be a subclass of a known field type.

Data

logger

EmptyMessage

StructMessage

FIELDS_TO_PROTO_TYPES

PRIMITIVE_TYPES

TYPING_TO_PROTO_TYPES

API

django_socio_grpc.protobuf.proto_classes.logger

‘getLogger(…)’

class django_socio_grpc.protobuf.proto_classes.ProtoComment(comments)

This class is used to represent a comment in a proto file. It allows adding a comment in a serializer field help_text.

Initialization

__iter__()
__bool__()
class django_socio_grpc.protobuf.proto_classes.ProtoField

Represents a field in a proto message.

{comments}
{cardinality} {field_type} {name} = {index};
name: str

None

field_type: Union[str, ProtoMessage, ProtoEnum]

None

cardinality: django_socio_grpc.protobuf.typing.FieldCardinality

None

comments: list[str] | None

None

index: int

0

property field_type_str: str
property field_line: str
classmethod _get_cardinality(field: rest_framework.serializers.Field)
classmethod from_field_dict(field_dict: django_socio_grpc.protobuf.typing.FieldDict) django_socio_grpc.protobuf.proto_classes.ProtoField
classmethod from_field_dict_handle_str_field_type(field_type: str, field_name: str, cardinality: django_socio_grpc.protobuf.typing.FieldCardinality)
classmethod from_field(field: rest_framework.serializers.Field, to_message: collections.abc.Callable = None, parent_serializer: rest_framework.serializers.Serializer = None, name_if_recursive: str = None) django_socio_grpc.protobuf.proto_classes.ProtoField

to_message, parent_serializer, name_if_recursive only used if field is ListSerializer with a child being a Serializer

classmethod get_field_comments(field: rest_framework.serializers.Field)
classmethod from_serializer(field: rest_framework.serializers.Serializer, to_message: collections.abc.Callable, parent_serializer: rest_framework.serializers.Serializer = None, name_if_recursive: str = None) django_socio_grpc.protobuf.proto_classes.ProtoField

Create a ProtoField from a Serializer, which will be converted to a ProtoMessage with to_message

classmethod _extract_method_info(method)
classmethod _from_serializer_method_field(field: rest_framework.serializers.SerializerMethodField) django_socio_grpc.protobuf.proto_classes.ProtoField
class django_socio_grpc.protobuf.proto_classes.ProtoEnumLocations

Bases: enum.Enum

MESSAGE

1

GLOBAL

2

class django_socio_grpc.protobuf.proto_classes.ProtoEnum
enum: enum.Enum

None

wrap_in_message: bool

False

location: django_socio_grpc.protobuf.proto_classes.ProtoEnumLocations

None

property name: str
static get_enum_from_annotation(field: rest_framework.serializers.ChoiceField)
__eq__(other)
__hash__()
class django_socio_grpc.protobuf.proto_classes.ProtoMessage

Represents a proto message with its fields and comments

{comments}
message {name} {
    [{fields}]
}
name: str

None

fields: list[django_socio_grpc.protobuf.proto_classes.ProtoField]

‘dataclass_field(…)’

comments: list[str] | None

None

serializer: rest_framework.serializers.BaseSerializer | None

None

imported_from: str | None

None

get_all_messages() dict[str, django_socio_grpc.protobuf.proto_classes.ProtoMessage]
set_indices(indices: dict[int, str]) None

Set the field index that is writed in the proto file while trying to keep the same order that the one passed in the incides parameter :param indices: dictionnary mapping the field number with the field name that we want to keep order too. Usually it come from the lecture of the previous proto file before it is generated again

classmethod create(value: type[rest_framework.serializers.BaseSerializer] | list[django_socio_grpc.protobuf.typing.FieldDict] | str | None, name: str) Union[django_socio_grpc.protobuf.proto_classes.ProtoMessage, str]
classmethod from_field_dicts(fields: list[django_socio_grpc.protobuf.typing.FieldDict], name: str) django_socio_grpc.protobuf.proto_classes.ProtoMessage
classmethod from_serializer(serializer: type[rest_framework.serializers.BaseSerializer], name: str | None = None) django_socio_grpc.protobuf.proto_classes.ProtoMessage
classmethod skip_field(field: rest_framework.serializers.Field | rest_framework.serializers.BaseSerializer, pk_name: str) bool
__getitem__(key: str) django_socio_grpc.protobuf.proto_classes.ProtoField
__contains__(key: str) bool
class django_socio_grpc.protobuf.proto_classes.RequestProtoMessage

Bases: django_socio_grpc.protobuf.proto_classes.ProtoMessage

suffix: ClassVar

None

classmethod skip_field(field: rest_framework.serializers.Field | rest_framework.serializers.BaseSerializer, pk_name: str) bool

Skip fields that are read_only on Request

class django_socio_grpc.protobuf.proto_classes.ResponseProtoMessage

Bases: django_socio_grpc.protobuf.proto_classes.ProtoMessage

suffix: ClassVar

None

classmethod skip_field(field: rest_framework.serializers.Field | rest_framework.serializers.BaseSerializer, pk_name: str) bool

Skip fields that are write_only on Response

django_socio_grpc.protobuf.proto_classes.EmptyMessage

‘ProtoMessage(…)’

django_socio_grpc.protobuf.proto_classes.StructMessage

‘ProtoMessage(…)’

class django_socio_grpc.protobuf.proto_classes.ProtoRpc

Represent a RPC method in a service

rpc {name}({request_stream?} {request.name}) returns ({response_stream?} {response.name}) {}
name: str

None

request: django_socio_grpc.protobuf.proto_classes.ProtoMessage | str

None

response: django_socio_grpc.protobuf.proto_classes.ProtoMessage | str

None

request_stream: bool

False

response_stream: bool

False

property request_name: str
property response_name: str
get_all_messages() dict[str, django_socio_grpc.protobuf.proto_classes.ProtoMessage]
class django_socio_grpc.protobuf.proto_classes.ProtoService

Represents a service in a proto file

service {name} {
    [{rpcs}]
}
name: str

None

rpcs: list[django_socio_grpc.protobuf.proto_classes.ProtoRpc]

‘dataclass_field(…)’

add_rpc(rpc: django_socio_grpc.protobuf.proto_classes.ProtoRpc)
get_all_messages() dict[str, django_socio_grpc.protobuf.proto_classes.ProtoMessage]
django_socio_grpc.protobuf.proto_classes.get_proto_type(field: django.db.models.Field | rest_framework.serializers.Field, default='string') str

Return the proto type of a field, fields can either implement a proto_type attribute or be a subclass of a known field type.

django_socio_grpc.protobuf.proto_classes.FIELDS_TO_PROTO_TYPES

None

django_socio_grpc.protobuf.proto_classes.PRIMITIVE_TYPES

None

django_socio_grpc.protobuf.proto_classes.TYPING_TO_PROTO_TYPES

None

class django_socio_grpc.protobuf.proto_classes.ProtoFieldConvertible

Bases: abc.ABC

Mixin to convert a class to a ProtoField

abstract to_proto_field(proto_field_cls: type[django_socio_grpc.protobuf.proto_classes.ProtoField], **kwargs) django_socio_grpc.protobuf.proto_classes.ProtoField