Skip to main content
Version: 0.3.x

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​

ArgumentTypeRequired
Description
dataSequence[str] | Warning | ExceptionThe 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​

ArgumentType
Description
jdatadict[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​

ArgumentTypeRequired
Description
jdatadict[str, Any]The serialized dictionary. This dictionary is JSON compatible, and could be transmitted by the web packages.

Returns​

ArgumentType
Description
gpmGroupedMessageThe deserialized object. This object could be converted to formatted strings by str(gpm).

Example​

Catch the error traceback as gruped messages​

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)