GroupedMessage
ClassPrivateSource
gpm = GroupedMessage(
data: Sequence[str] | Warning | BaseException | 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.
Aliases
This class can be acquired by
import syncstream
syncstream.GroupedMessage
syncstream.base.GroupedMessage
Arguments
Argument | Type | Required | |
---|---|---|---|
data | Sequence[str] | Warning | BaseException | The grouped messages provider. The input value would be parsed as formatted lines. The parsed messages are compatible with serialization. |
Methods
serialize
jdata: SerializedMessage = gpm.serialize()
Serialize this message item into a JSON compatible dict.
Returns
Argument | Type | |
---|---|---|
jdata | SerializedMessage | The serialized dictionary. This dictionary could be converted back to GroupedMessage object by the deserialize method. |
deserialize
gpm: GroupedMessage = GroupedMessage.deserialize(
jdata: SerializedMessage | GroupedMessage
)
Deserialize the JSON compatible dict into this object.
Requires
Argument | Type | Required | |
---|---|---|---|
jdata | SerializedMessage | GroupedMessage | The serialized dictionary. This dictionary is JSON compatible, and could be transmitted by the web packages. If it is not a serialized dictionary, return as it is. |
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.