diff options
-rw-r--r-- | python/qpid/address.py | 26 | ||||
-rw-r--r-- | python/qpid/tests/address.py | 32 |
2 files changed, 56 insertions, 2 deletions
diff --git a/python/qpid/address.py b/python/qpid/address.py index 5c675b8782..6228ac757b 100644 --- a/python/qpid/address.py +++ b/python/qpid/address.py @@ -24,6 +24,8 @@ l = Lexicon() LBRACE = l.define("LBRACE", r"\{") RBRACE = l.define("RBRACE", r"\}") +LBRACK = l.define("LBRACK", r"\[") +RBRACK = l.define("RBRACK", r"\]") COLON = l.define("COLON", r":") SEMI = l.define("SEMI", r";") SLASH = l.define("SLASH", r"/") @@ -128,8 +130,30 @@ class AddressParser(Parser): return tok2obj(self.eat()) elif self.matches(LBRACE): return self.map() + elif self.matches(LBRACK): + return self.list() else: - raise ParseError(self.next(), NUMBER, STRING, ID, LBRACE) + raise ParseError(self.next(), NUMBER, STRING, ID, LBRACE, LBRACK) + + def list(self): + self.eat(LBRACK) + + result = [] + + while True: + if self.matches(RBRACK): + break + else: + result.append(self.value()) + if self.matches(COMMA): + self.eat(COMMA) + elif self.matches(RBRACK): + break + else: + raise ParseError(self.next(), COMMA, RBRACK) + + self.eat(RBRACK) + return result def parse(addr): return AddressParser(lex(addr)).parse() diff --git a/python/qpid/tests/address.py b/python/qpid/tests/address.py index f772425e42..7c101eee5e 100644 --- a/python/qpid/tests/address.py +++ b/python/qpid/tests/address.py @@ -145,7 +145,7 @@ class AddressTests(ParserBase, Test): def testBadOptions3(self): self.invalid("name/subject; { key:", - "expecting (NUMBER, STRING, ID, LBRACE), got EOF " + "expecting (NUMBER, STRING, ID, LBRACE, LBRACK), got EOF " "line:1,20:name/subject; { key:") def testBadOptions4(self): @@ -167,3 +167,33 @@ class AddressTests(ParserBase, Test): self.invalid("name/subject; { key: value } asdf", "expecting EOF, got ID('asdf') " "line:1,29:name/subject; { key: value } asdf") + + def testList1(self): + self.valid("name/subject; { key: [] }", "name", "subject", {"key": []}) + + def testList2(self): + self.valid("name/subject; { key: ['one'] }", "name", "subject", {"key": ['one']}) + + def testList3(self): + self.valid("name/subject; { key: [1, 2, 3] }", "name", "subject", + {"key": [1, 2, 3]}) + + def testList4(self): + self.valid("name/subject; { key: [1, [2, 3], 4] }", "name", "subject", + {"key": [1, [2, 3], 4]}) + + def testBadList1(self): + self.invalid("name/subject; { key: [ }", "expecting (NUMBER, STRING, ID, LBRACE, LBRACK), " + "got RBRACE('}') line:1,23:name/subject; { key: [ }") + + def testBadList2(self): + self.invalid("name/subject; { key: [ 1 }", "expecting (COMMA, RBRACK), " + "got RBRACE('}') line:1,25:name/subject; { key: [ 1 }") + + def testBadList3(self): + self.invalid("name/subject; { key: [ 1 2 }", "expecting (COMMA, RBRACK), " + "got NUMBER('2') line:1,25:name/subject; { key: [ 1 2 }") + + def testBadList4(self): + self.invalid("name/subject; { key: [ 1 2 ] }", "expecting (COMMA, RBRACK), " + "got NUMBER('2') line:1,25:name/subject; { key: [ 1 2 ] }") |