Skip to content

websocket

T = TypeVar('T') module-attribute

Packet dataclass

Bases: Serializable

Packet class represents a message that is sent through the websocket.

Source code in shared/websocket.py
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
@dataclass
class Packet(Serializable):
    """
    Packet class represents a message that is sent through the websocket.
    """
    type: str
    """The type of the packet."""
    data: Generic[T] = None
    """The data field is the actual data that is sent through the websocket."""

    def to_dict(self, dict_factory: Type[Dict] = dict, recurse: bool = True) -> Dict:
        return {
            'type': str(self.type),
            'data': self.data.to_dict() if isinstance(self.data, Serializable) else self.data,
        }

data: Generic[T] = None class-attribute

The data field is the actual data that is sent through the websocket.

type: str class-attribute

The type of the packet.

to_dict(dict_factory=dict, recurse=True)

Source code in shared/websocket.py
19
20
21
22
23
def to_dict(self, dict_factory: Type[Dict] = dict, recurse: bool = True) -> Dict:
    return {
        'type': str(self.type),
        'data': self.data.to_dict() if isinstance(self.data, Serializable) else self.data,
    }