def _match_patterns(self,patterns): """Internal method to match a list of patterns against the mailbox. If message matches any of the patterns, that message is removed from the mailbox and returned along with the pattern it matched. If message doesn't match any pattern then None,None is returned. """ for i, message in enumerate(self._mailbox): for pattern in patterns: if shape.is_shaped(message, pattern): del self._mailbox[i] return pattern, message return None,None
def respond_exception(self, orig_message, exception): if not shape.is_shaped(orig_message, CALL_PATTERN): raise InvalidCallMessage(str(orig_message)) orig_message['address'].cast({'response':orig_message['call'], 'exception':exception})
def respond_invalid_method(self, orig_message, method): if not shape.is_shaped(orig_message, CALL_PATTERN): raise InvalidCallMessage(str(orig_message)) orig_message['address'].cast({'response':orig_message['call'], 'invalid_method':method})
def respond(self, orig_message, response=None): if not shape.is_shaped(orig_message, CALL_PATTERN): raise InvalidCallMessage(str(orig_message)) orig_message['address'].cast({'response':orig_message['call'], 'message':response})