How to use spade - 10 common examples

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 / spade / pyparsing.py View on Github external
_escapables = "tnrfbacdeghijklmopqsuvwxyz " + _bslash + "'" + '"'
_octDigits = "01234567"
_escapedChar = (Word(_bslash, _escapables, exact=2) |
                Word(_bslash, _octDigits, min=2, max=4))
_sglQuote = Literal("'")
_dblQuote = Literal('"')
dblQuotedString = Combine(_dblQuote + ZeroOrMore(CharsNotIn('\\"\n\r') | _escapedChar | '""') + _dblQuote).streamline().setName("string enclosed in double quotes")
sglQuotedString = Combine(_sglQuote + ZeroOrMore(CharsNotIn("\\'\n\r") | _escapedChar | "''") + _sglQuote).streamline().setName("string enclosed in single quotes")
quotedString = (dblQuotedString | sglQuotedString).setName("quotedString using single or double quotes")

# it's easy to get these comment structures wrong - they're very common, so may as well make them available
cStyleComment = Combine(Literal("/*") +
                        ZeroOrMore(CharsNotIn("*") | ("*" + ~Literal("/"))) +
                        Literal("*/")).streamline().setName("cStyleComment enclosed in /* ... */")
htmlComment = Combine(Literal("") + Literal("-").leaveWhitespace())) +
                      Literal("-->")).streamline().setName("htmlComment enclosed in ")
restOfLine = Optional(CharsNotIn("\n\r"), default="").setName("rest of line up to \\n").leaveWhitespace()
dblSlashComment = "//" + restOfLine
cppStyleComment = FollowedBy("/") + (dblSlashComment | cStyleComment)
javaStyleComment = cppStyleComment
pythonStyleComment = "#" + restOfLine
_noncomma = "".join([c for c in printables if c != ","])
_commasepitem = Combine(OneOrMore(Word(_noncomma) +
                                  Optional(Word(" \t") +
                                           ~Literal(",") + ~LineEnd()))).streamline().setName("commaItem")
commaSeparatedList = delimitedList(Optional(quotedString | _commasepitem, default="")).setName("commaSeparatedList")


if __name__ == "__main__":

    def test(teststring):
github javipalanca / spade / spade / pyparsing.py View on Github external
def makeHTMLTags(tagStr):
    """Helper to construct opening and closing tag expressions for HTML, given a tag name"""
    return _makeTags(tagStr, False)


def makeXMLTags(tagStr):
    """Helper to construct opening and closing tag expressions for XML, given a tag name"""
    return _makeTags(tagStr, True)

alphas8bit = srange(r"[\0xc0-\0xd6\0xd8-\0xf6\0xf8-\0xfe]")

_escapables = "tnrfbacdeghijklmopqsuvwxyz " + _bslash + "'" + '"'
_octDigits = "01234567"
_escapedChar = (Word(_bslash, _escapables, exact=2) |
                Word(_bslash, _octDigits, min=2, max=4))
_sglQuote = Literal("'")
_dblQuote = Literal('"')
dblQuotedString = Combine(_dblQuote + ZeroOrMore(CharsNotIn('\\"\n\r') | _escapedChar | '""') + _dblQuote).streamline().setName("string enclosed in double quotes")
sglQuotedString = Combine(_sglQuote + ZeroOrMore(CharsNotIn("\\'\n\r") | _escapedChar | "''") + _sglQuote).streamline().setName("string enclosed in single quotes")
quotedString = (dblQuotedString | sglQuotedString).setName("quotedString using single or double quotes")

# it's easy to get these comment structures wrong - they're very common, so may as well make them available
cStyleComment = Combine(Literal("/*") +
                        ZeroOrMore(CharsNotIn("*") | ("*" + ~Literal("/"))) +
                        Literal("*/")).streamline().setName("cStyleComment enclosed in /* ... */")
htmlComment = Combine(Literal("") + Literal("-").leaveWhitespace())) +
                      Literal("-->")).streamline().setName("htmlComment enclosed in ")
restOfLine = Optional(CharsNotIn("\n\r"), default="").setName("rest of line up to \\n").leaveWhitespace()
dblSlashComment = "//" + restOfLine
cppStyleComment = FollowedBy("/") + (dblSlashComment | cStyleComment)
javaStyleComment = cppStyleComment
github javipalanca / spade / spade / pyparsing.py View on Github external
return _makeTags(tagStr, True)

alphas8bit = srange(r"[\0xc0-\0xd6\0xd8-\0xf6\0xf8-\0xfe]")

_escapables = "tnrfbacdeghijklmopqsuvwxyz " + _bslash + "'" + '"'
_octDigits = "01234567"
_escapedChar = (Word(_bslash, _escapables, exact=2) |
                Word(_bslash, _octDigits, min=2, max=4))
_sglQuote = Literal("'")
_dblQuote = Literal('"')
dblQuotedString = Combine(_dblQuote + ZeroOrMore(CharsNotIn('\\"\n\r') | _escapedChar | '""') + _dblQuote).streamline().setName("string enclosed in double quotes")
sglQuotedString = Combine(_sglQuote + ZeroOrMore(CharsNotIn("\\'\n\r") | _escapedChar | "''") + _sglQuote).streamline().setName("string enclosed in single quotes")
quotedString = (dblQuotedString | sglQuotedString).setName("quotedString using single or double quotes")

# it's easy to get these comment structures wrong - they're very common, so may as well make them available
cStyleComment = Combine(Literal("/*") +
                        ZeroOrMore(CharsNotIn("*") | ("*" + ~Literal("/"))) +
                        Literal("*/")).streamline().setName("cStyleComment enclosed in /* ... */")
htmlComment = Combine(Literal("") + Literal("-").leaveWhitespace())) +
                      Literal("-->")).streamline().setName("htmlComment enclosed in ")
restOfLine = Optional(CharsNotIn("\n\r"), default="").setName("rest of line up to \\n").leaveWhitespace()
dblSlashComment = "//" + restOfLine
cppStyleComment = FollowedBy("/") + (dblSlashComment | cStyleComment)
javaStyleComment = cppStyleComment
pythonStyleComment = "#" + restOfLine
_noncomma = "".join([c for c in printables if c != ","])
_commasepitem = Combine(OneOrMore(Word(_noncomma) +
                                  Optional(Word(" \t") +
                                           ~Literal(",") + ~LineEnd()))).streamline().setName("commaItem")
commaSeparatedList = delimitedList(Optional(quotedString | _commasepitem, default="")).setName("commaSeparatedList")
github javipalanca / spade / spade / pyparsing.py View on Github external
_escapables = "tnrfbacdeghijklmopqsuvwxyz " + _bslash + "'" + '"'
_octDigits = "01234567"
_escapedChar = (Word(_bslash, _escapables, exact=2) |
                Word(_bslash, _octDigits, min=2, max=4))
_sglQuote = Literal("'")
_dblQuote = Literal('"')
dblQuotedString = Combine(_dblQuote + ZeroOrMore(CharsNotIn('\\"\n\r') | _escapedChar | '""') + _dblQuote).streamline().setName("string enclosed in double quotes")
sglQuotedString = Combine(_sglQuote + ZeroOrMore(CharsNotIn("\\'\n\r") | _escapedChar | "''") + _sglQuote).streamline().setName("string enclosed in single quotes")
quotedString = (dblQuotedString | sglQuotedString).setName("quotedString using single or double quotes")

# it's easy to get these comment structures wrong - they're very common, so may as well make them available
cStyleComment = Combine(Literal("/*") +
                        ZeroOrMore(CharsNotIn("*") | ("*" + ~Literal("/"))) +
                        Literal("*/")).streamline().setName("cStyleComment enclosed in /* ... */")
htmlComment = Combine(Literal("") + Literal("-").leaveWhitespace())) +
                      Literal("-->")).streamline().setName("htmlComment enclosed in ")
restOfLine = Optional(CharsNotIn("\n\r"), default="").setName("rest of line up to \\n").leaveWhitespace()
dblSlashComment = "//" + restOfLine
cppStyleComment = FollowedBy("/") + (dblSlashComment | cStyleComment)
javaStyleComment = cppStyleComment
pythonStyleComment = "#" + restOfLine
_noncomma = "".join([c for c in printables if c != ","])
_commasepitem = Combine(OneOrMore(Word(_noncomma) +
                                  Optional(Word(" \t") +
                                           ~Literal(",") + ~LineEnd()))).streamline().setName("commaItem")
commaSeparatedList = delimitedList(Optional(quotedString | _commasepitem, default="")).setName("commaSeparatedList")


if __name__ == "__main__":
github javipalanca / spade / tests / test_trace.py View on Github external
def test_filter_to_limit():
    cycle = itertools.cycle(range(3))
    trace = TraceStore(10)
    for i in range(5):
        msg = Message(
            body=str(i), to="{}@server".format(next(cycle)), sender="sender@server"
        )
        trace.append(msg)

    result = [x[1].body for x in trace.filter(to="0@server", limit=1)]
    assert result == ["3"]
github javipalanca / spade / tests / test_trace.py View on Github external
def test_all_limit():
    trace = TraceStore(10)
    for i in range(5):
        trace.append(i)
    all = trace.all(limit=2)
    events = [e[1] for e in all]

    assert events == [3, 4]
github javipalanca / spade / tests / test_trace.py View on Github external
def test_init():
    trace = TraceStore(10)

    assert trace.size == 10
    assert trace.store == []
github javipalanca / spade / examples / unittests / rpcTestCase.py View on Github external
def setUp(self):
        
        self.Aaid = spade.AID.aid("a@"+host,["xmpp://a@"+host])
        self.Baid = spade.AID.aid("b@"+host,["xmpp://b@"+host])

    	self.a = MyAgent("a@"+host, "secret")
    	self.a.start()
    	self.b = MyAgent("b@"+host, "secret")
    	#self.b.setDebugToScreen()
    	#self.a.setDebugToScreen()
    	self.b.start()
    	self.a.wui.start()
    	self.b.wui.start()
github javipalanca / spade / examples / unittests / aidTestCase.py View on Github external
def testCreateAid(self):
        aid = spade.AID.aid()
        
        self.assertEqual(aid.getName(),None)
        self.assertEqual(aid.getAddresses(),[])
        self.assertEqual(aid.getResolvers(),[])
        self.assertEqual(aid.getProperties(),[])

        aid.setName("aidname")
        self.assertEqual(aid.getName(),"aidname")
        aid.addAddress("address@server.com")
        self.assertEqual(len(aid.getAddresses()),1)
        self.assertEqual(aid.getAddresses()[0],"address@server.com")
        aid.addResolvers("resolver@server.com")
        self.assertEqual(len(aid.getResolvers()),1)
        self.assertEqual(aid.getResolvers()[0],"resolver@server.com")
        aid.addProperty("prop1")
        self.assertEqual(len(aid.getProperties()),1)
github javipalanca / spade / examples / unittests / dadTestCase.py View on Github external
def CreateDAD(s=""):
    dad = spade.DF.DfAgentDescription()
    aid = spade.AID.aid()
    aid.setName("aidname"+s)
    dad.setAID(aid)

    dad.addProtocol("protocol1"+s)
    dad.addOntologies("ontology1"+s)
    dad.addLanguage("language1"+s)
    dad.setLeaseTime(1000)
    dad.addScope("scope1"+s)

    return dad