-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
77de6f6
commit afd7387
Showing
14 changed files
with
222 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
"""Ping/pong messages.""" | ||
from dataclasses import dataclass | ||
from typing import Optional | ||
|
||
from .event import Event, Eventable | ||
|
||
_PING_TYPE = "ping" | ||
_PONG_TYPE = "pong" | ||
|
||
|
||
@dataclass | ||
class Ping(Eventable): | ||
"""Request pong message.""" | ||
|
||
text: Optional[str] = None | ||
"""Text to copy to response.""" | ||
|
||
@staticmethod | ||
def is_type(event_type: str) -> bool: | ||
return event_type == _PING_TYPE | ||
|
||
def event(self) -> Event: | ||
return Event( | ||
type=_PING_TYPE, | ||
data={"text": self.text}, | ||
) | ||
|
||
@staticmethod | ||
def from_event(event: Event) -> "Ping": | ||
return Ping(text=event.data.get("text")) | ||
|
||
|
||
@dataclass | ||
class Pong(Eventable): | ||
"""Response to ping message.""" | ||
|
||
text: Optional[str] = None | ||
"""Text copied from request.""" | ||
|
||
@staticmethod | ||
def is_type(event_type: str) -> bool: | ||
return event_type == _PONG_TYPE | ||
|
||
def event(self) -> Event: | ||
return Event( | ||
type=_PONG_TYPE, | ||
data={"text": self.text}, | ||
) | ||
|
||
@staticmethod | ||
def from_event(event: Event) -> "Pong": | ||
return Pong(text=event.data.get("text")) |
Oops, something went wrong.