How to use the spade.template.Template function in spade

To help you get started, we’ve selected a few spade examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github javipalanca / spade / tests / test_template.py View on Github external
def test_match_iand():
    t1 = Template()
    t1.sender = "sender1@host"
    t2 = Template()
    t2.to = "recv1@host"
    t2.metadata = {"performative": "query"}

    m1 = Message()
    m1.sender = "sender1@host"

    t1 &= t2
    assert not t1.match(m1)

    m2 = Message()
    m2.to = "recv1@host"
    m2.metadata = {"performative": "query"}

    assert not t1.match(m2)

    m3 = Message()
github javipalanca / spade / tests / test_template.py View on Github external
def test_match_ior():
    t1 = Template()
    t1.sender = "sender1@host"
    t2 = Template()
    t2.to = "recv1@host"
    t2.metadata = {"performative": "query"}

    m1 = Message()
    m1.sender = "sender1@host"

    t1 |= t2

    assert t1.match(m1)

    m2 = Message()
    m2.to = "recv1@host"
    m2.metadata = {"performative": "query"}
github javipalanca / spade / tests / test_template.py View on Github external
def test_match():
    template = Template()
    template.sender = "sender1@host"
    template.to = "recv1@host"
    template.body = "Hello World"
    template.thread = "thread-id"
    template.metadata = {"performative": "query"}

    message = Message()
    message.sender = "sender1@host"
    message.to = "recv1@host"
    message.body = "Hello World"
    message.thread = "thread-id"
    message.set_metadata("performative", "query")

    assert template.match(message)
github javipalanca / spade / tests / test_template.py View on Github external
def test_match_or():
    t1 = Template()
    t1.sender = "sender1@host"
    t2 = Template()
    t2.to = "recv1@host"
    t2.metadata = {"performative": "query"}

    m1 = Message()
    m1.sender = "sender1@host"

    assert (t1 | t2).match(m1)

    m2 = Message()
    m2.to = "recv1@host"
    m2.metadata = {"performative": "query"}

    assert (t1 | t2).match(m2)

    m3 = Message()
    m3.sender = "sender2@host"
github javipalanca / spade / tests / test_template.py View on Github external
def test_match_xor():
    t1 = Template()
    t1.sender = "sender1@host"
    t2 = Template()
    t2.to = "recv1@host"
    t2.metadata = {"performative": "query"}

    m1 = Message()
    m1.sender = "sender1@host"

    assert (t1 ^ t2).match(m1)

    m2 = Message()
    m2.to = "recv1@host"
    m2.metadata = {"performative": "query"}

    assert (t1 ^ t2).match(m2)

    m3 = Message()
    m3.sender = "sender2@host"
github javipalanca / spade / tests / test_template.py View on Github external
def test_match_false_to():
    template = Template()
    template.to = "recv1@host"

    message = Message()

    assert not template.match(message)

    message.to = "recv2@host"

    assert not template.match(message)
github javipalanca / spade / examples / web_interface.py View on Github external
def setup(self):
        self.web.start(templates_path="examples")
        template1 = Template(sender="agent0@fake_server")
        template2 = Template(sender="agent1@fake_server")
        template3 = Template(sender="agent2@fake_server")
        template4 = Template(sender="agent3@fake_server")

        # Create some dummy behaviours
        dummybehav = self.DummyBehav()
        self.add_behaviour(dummybehav, template=template1)
        periodbehav = self.DummyPeriodBehav(period=12.7)
        self.add_behaviour(periodbehav, template=template2)
        timeoutbehav = self.DummyTimeoutBehav(start_at=datetime.datetime.now())
        self.add_behaviour(timeoutbehav, template=template3)
        fsm_behav = self.DummyFSMBehav()
        self.add_behaviour(fsm_behav, template=template4)
        behavs = [dummybehav, periodbehav, timeoutbehav, fsm_behav]

        # Create some fake contacts
        self.add_fake_contact("agent0@fake_server", PresenceType.AVAILABLE)
        self.add_fake_contact(
github javipalanca / spade / examples / web_interface.py View on Github external
def setup(self):
        self.web.start(templates_path="examples")
        template1 = Template(sender="agent0@fake_server")
        template2 = Template(sender="agent1@fake_server")
        template3 = Template(sender="agent2@fake_server")
        template4 = Template(sender="agent3@fake_server")

        # Create some dummy behaviours
        dummybehav = self.DummyBehav()
        self.add_behaviour(dummybehav, template=template1)
        periodbehav = self.DummyPeriodBehav(period=12.7)
        self.add_behaviour(periodbehav, template=template2)
        timeoutbehav = self.DummyTimeoutBehav(start_at=datetime.datetime.now())
        self.add_behaviour(timeoutbehav, template=template3)
        fsm_behav = self.DummyFSMBehav()
        self.add_behaviour(fsm_behav, template=template4)
        behavs = [dummybehav, periodbehav, timeoutbehav, fsm_behav]

        # Create some fake contacts
github javipalanca / spade / examples / web_interface.py View on Github external
def setup(self):
        self.web.start(templates_path="examples")
        template1 = Template(sender="agent0@fake_server")
        template2 = Template(sender="agent1@fake_server")
        template3 = Template(sender="agent2@fake_server")
        template4 = Template(sender="agent3@fake_server")

        # Create some dummy behaviours
        dummybehav = self.DummyBehav()
        self.add_behaviour(dummybehav, template=template1)
        periodbehav = self.DummyPeriodBehav(period=12.7)
        self.add_behaviour(periodbehav, template=template2)
        timeoutbehav = self.DummyTimeoutBehav(start_at=datetime.datetime.now())
        self.add_behaviour(timeoutbehav, template=template3)
        fsm_behav = self.DummyFSMBehav()
        self.add_behaviour(fsm_behav, template=template4)
        behavs = [dummybehav, periodbehav, timeoutbehav, fsm_behav]

        # Create some fake contacts
        self.add_fake_contact("agent0@fake_server", PresenceType.AVAILABLE)
        self.add_fake_contact(
            "agent1@fake_server", PresenceType.AVAILABLE, show=PresenceShow.AWAY