File size: 709 Bytes
4398510
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from typing import Any
from enum import Enum, auto
from types import SimpleNamespace
from dataclasses import dataclass, FrozenInstanceError


class WSGKind(Enum):
    ADD_WSG = auto()
    RESET = auto()


class FrozenSimpleNamespace(SimpleNamespace):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)

    def __setattr__(self, name: str, value: Any) -> None:
        raise FrozenInstanceError(f"cannot assign to field '{name}'")


@dataclass(frozen=True)
class Action:
    """
    The Action object contains the payload of information.
    """

    kind: WSGKind
    payload: dict

    def __post_init__(self):
        super().__setattr__("payload", FrozenSimpleNamespace(**self.payload))