MCPcopy Create free account
hub / github.com/microsoft/debugpy / Event

Class Event

src/debugpy/common/messaging.py:529–601  ·  view source on GitHub ↗

Represents an incoming event. https://microsoft.github.io/debug-adapter-protocol/specification#event It is guaranteed that body is a MessageDict associated with this Event, and so are all the nested dicts in it. If "body" was missing or null in JSON, body is an empty dict. To

Source from the content-addressed store, hash-verified

527
528
529class Event(Message):
530 """Represents an incoming event.
531
532 https://microsoft.github.io/debug-adapter-protocol/specification#event
533
534 It is guaranteed that body is a MessageDict associated with this Event, and so
535 are all the nested dicts in it. If "body" was missing or null in JSON, body is
536 an empty dict.
537
538 To handle the event, JsonMessageChannel tries to find a handler for this event in
539 JsonMessageChannel.handlers. Given event="X", if handlers.X_event exists, then it
540 is the specific handler for this event. Otherwise, handlers.event must exist, and
541 it is the generic handler for this event. A missing handler is a fatal error.
542
543 No further incoming messages are processed until the handler returns, except for
544 responses to requests that have wait_for_response() invoked on them.
545
546 To report failure to handle the event, the handler must raise an instance of
547 MessageHandlingError that applies_to() the Event object it was handling. Any such
548 failure is logged, after which the message loop moves on to the next message.
549
550 Helper methods Message.isnt_valid() and Message.cant_handle() can be used to raise
551 the appropriate exception type that applies_to() the Event object.
552 """
553
554 def __init__(self, channel, seq, event, body, json=None):
555 super().__init__(channel, seq, json)
556
557 self.event = event
558
559 if isinstance(body, MessageDict) and hasattr(body, "associate_with"):
560 body.associate_with(self)
561 self.body = body
562
563 def describe(self):
564 return f"#{self.seq} event {json.repr(self.event)} from {self.channel}"
565
566 @property
567 def payload(self):
568 return self.body
569
570 @staticmethod
571 def _parse(channel, message_dict):
572 seq = message_dict("seq", int)
573 event = message_dict("event", str)
574 body = message_dict("body", _payload)
575 message = Event(channel, seq, event, body, json=message_dict)
576 channel._enqueue_handlers(message, message._handle)
577
578 def _handle(self):
579 channel = self.channel
580 handler = channel._get_handler_for("event", self.event)
581 try:
582 try:
583 result = handler(self)
584 assert (
585 result is None
586 ), f"Handler {util.srcnameof(handler)} tried to respond to {self.describe()}."

Callers 1

_parseMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…