GroupedMessage
ClassPrivateSource
gpm = syncstream.base.GroupedMessage(
data: Sequence[str] | Warning | Exception | None = None,
)
A group of messages.
Used for wrapping muliple str lines (info), a warning object, or an exception object.
This class would be used by mproc.LineProcMirror and host.LineHostMirror automatically. In most cases, users do not need to use this class directly.
Arguments
Requires
| Argument | Type | Required | |
|---|---|---|---|
data | Sequence[str] | Warning | Exception | The grouped messages provider. The input value would be parsed as formatted lines. The parsed messages are compatible with serialization. |
Methods
serialize
jdata: dict[str, Any] = gpm.serialize()
Serialize this message item into a JSON compatible dict.
Returns
| Argument | Type | |
|---|---|---|
jdata | dict[str, Any] | The serialized dictionary. This dictionary could be converted back to GroupedMessage object by the deserialize method. |
deserialize
gpm: GroupedMessage = GroupedMessage.deserialize(jdata: dict[str, Any])
Deserialize the JSON compatible dict into this object.
Requires
| Argument | Type | Required | |
|---|---|---|---|
jdata | dict[str, Any] | The serialized dictionary. This dictionary is JSON compatible, and could be transmitted by the web packages. |
Returns
| Argument | Type | |
|---|---|---|
gpm | GroupedMessage | The deserialized object. This object could be converted to formatted strings by str(gpm). |
Example
Catch the error traceback as gruped messages
- Codes
- Results
use_grouped_messages.py
from syncstream.base import GroupedMessage
try:
raise ImportError('A testing exception object.')
except ImportError as error:
gpm = GroupedMessage(error)
print(gpm)
Traceback (most recent call last):
File "C:\Documents (no sync)\GitHub\sync-stream\alpha\test.py", line 4, in <module>
raise ImportError('A testing exception object.')
ImportError: A testing exception object.