跳转至

util

用于 Ariadne 数据模型的工具类.

AriadneBaseModel 🔗

Bases: BaseModel

Ariadne 一切数据模型的基类.

Source code in graia/ariadne/model/util.py
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
class AriadneBaseModel(BaseModel):
    """Ariadne 一切数据模型的基类."""

    def __init__(self, **data: Any) -> None:
        """初始化模型. 直接向 pydantic 转发."""
        super().__init__(**data)

    def dict(
        self,
        *,
        include: Union[None, "AbstractSetIntStr", "MappingIntStrAny"] = None,
        exclude: Union[None, "AbstractSetIntStr", "MappingIntStrAny"] = None,
        by_alias: bool = False,
        skip_defaults: bool = False,
        exclude_unset: bool = False,
        exclude_defaults: bool = False,
        exclude_none: bool = False,
        to_camel: bool = False,
    ) -> "DictStrAny":
        """转化为字典, 直接向 pydantic 转发."""
        _, *_ = by_alias, exclude_none, skip_defaults
        data = super().dict(
            include=include,  # type: ignore
            exclude=exclude,  # type: ignore
            by_alias=True,
            exclude_unset=exclude_unset,
            exclude_defaults=exclude_defaults,
            exclude_none=True,
        )
        if to_camel:
            data = {snake_to_camel(k): v for k, v in data.items()}
        return data

    class Config(BaseConfig):
        """Ariadne BaseModel 设置"""

        extra = Extra.allow
        arbitrary_types_allowed = True
        copy_on_model_validation = "none"
        json_encoders = {
            datetime: lambda dt: int(dt.timestamp()),
        }

Config 🔗

Bases: BaseConfig

Ariadne BaseModel 设置

Source code in graia/ariadne/model/util.py
47
48
49
50
51
52
53
54
55
class Config(BaseConfig):
    """Ariadne BaseModel 设置"""

    extra = Extra.allow
    arbitrary_types_allowed = True
    copy_on_model_validation = "none"
    json_encoders = {
        datetime: lambda dt: int(dt.timestamp()),
    }

__init__ 🔗

__init__(**data: Any) -> None

初始化模型. 直接向 pydantic 转发.

Source code in graia/ariadne/model/util.py
17
18
19
def __init__(self, **data: Any) -> None:
    """初始化模型. 直接向 pydantic 转发."""
    super().__init__(**data)

dict 🔗

dict(
    *,
    include: Union[None, AbstractSetIntStr, MappingIntStrAny] = None,
    exclude: Union[None, AbstractSetIntStr, MappingIntStrAny] = None,
    by_alias: bool = False,
    skip_defaults: bool = False,
    exclude_unset: bool = False,
    exclude_defaults: bool = False,
    exclude_none: bool = False,
    to_camel: bool = False
) -> DictStrAny

转化为字典, 直接向 pydantic 转发.

Source code in graia/ariadne/model/util.py
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
def dict(
    self,
    *,
    include: Union[None, "AbstractSetIntStr", "MappingIntStrAny"] = None,
    exclude: Union[None, "AbstractSetIntStr", "MappingIntStrAny"] = None,
    by_alias: bool = False,
    skip_defaults: bool = False,
    exclude_unset: bool = False,
    exclude_defaults: bool = False,
    exclude_none: bool = False,
    to_camel: bool = False,
) -> "DictStrAny":
    """转化为字典, 直接向 pydantic 转发."""
    _, *_ = by_alias, exclude_none, skip_defaults
    data = super().dict(
        include=include,  # type: ignore
        exclude=exclude,  # type: ignore
        by_alias=True,
        exclude_unset=exclude_unset,
        exclude_defaults=exclude_defaults,
        exclude_none=True,
    )
    if to_camel:
        data = {snake_to_camel(k): v for k, v in data.items()}
    return data

AriadneOptions 🔗

Bases: TypedDict

Ariadne 内部的选项存储

Source code in graia/ariadne/model/util.py
58
59
60
61
62
63
class AriadneOptions(TypedDict):
    """Ariadne 内部的选项存储"""

    installed_log: NotRequired[Literal[True]]
    inject_bypass_listener: NotRequired[Literal[True]]
    default_account: NotRequired[int]