Module graia.broadcast.entities.event
Expand source code
from typing import Type, Optional
from pydantic.dataclasses import dataclass
from iterwrapper import IterWrapper
from pydantic.main import BaseModel, ModelMetaclass
import copy
class EventMeta(ModelMetaclass):
def __new__(mcls, name, bases, mapping, **kwargs):
if any(
IterWrapper(bases)
.filter(lambda x: getattr(x, "__base_event__", False))
.collect(list)
):
if not mapping.__contains__("__base_event__"):
mapping["__base_event__"] = False
if not mapping.get("Dispatcher") and name != "BaseEvent":
raise AttributeError(
"a event class must have a dispatcher called 'Dispatcher'"
)
r = super().__new__(
mcls,
name,
(BaseModel, *bases) if name == "BaseEvent" else bases,
mapping,
**kwargs
)
if mapping.get("type"):
r.type = mapping.get("type")
if name != "BaseEvent":
r.update_forward_refs()
r.Dispatcher = mapping["Dispatcher"]
return r
class BaseEvent(metaclass=EventMeta):
class Config:
arbitrary_types_allowed = True
from .dispatcher import BaseDispatcher
Classes
class BaseEvent (**data: Any)
-
Create a new model by parsing and validating input data from keyword arguments.
Raises ValidationError if the input data cannot be parsed to form a valid model.
Expand source code
class BaseEvent(metaclass=EventMeta): class Config: arbitrary_types_allowed = True
Ancestors
- pydantic.main.BaseModel
- pydantic.utils.Representation
Subclasses
- MiraiEvent
- ApplicationLaunched
- ApplicationLaunchedBlocking
- ApplicationShutdowned
- InvaildRequest
- RemoteException
- SessionRefreshFailed
- SessionRefreshed
- ExceptionThrowed
- EmptyEvent
Class variables
var Config
class EventMeta (*args, **kwargs)
-
Metaclass for defining Abstract Base Classes (ABCs).
Use this metaclass to create an ABC. An ABC can be subclassed directly, and then acts as a mix-in class. You can also register unrelated concrete classes (even built-in classes) and unrelated ABCs as 'virtual subclasses' – these and their descendants will be considered subclasses of the registering ABC by the built-in issubclass() function, but the registering ABC won't show up in their MRO (Method Resolution Order) nor will method implementations defined by the registering ABC be callable (not even via super()).
Expand source code
class EventMeta(ModelMetaclass): def __new__(mcls, name, bases, mapping, **kwargs): if any( IterWrapper(bases) .filter(lambda x: getattr(x, "__base_event__", False)) .collect(list) ): if not mapping.__contains__("__base_event__"): mapping["__base_event__"] = False if not mapping.get("Dispatcher") and name != "BaseEvent": raise AttributeError( "a event class must have a dispatcher called 'Dispatcher'" ) r = super().__new__( mcls, name, (BaseModel, *bases) if name == "BaseEvent" else bases, mapping, **kwargs ) if mapping.get("type"): r.type = mapping.get("type") if name != "BaseEvent": r.update_forward_refs() r.Dispatcher = mapping["Dispatcher"] return r
Ancestors
- pydantic.main.ModelMetaclass
- abc.ABCMeta
- builtins.type