summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorRafael H. Schloming <rhs@apache.org>2009-11-13 15:59:54 +0000
committerRafael H. Schloming <rhs@apache.org>2009-11-13 15:59:54 +0000
commit53d1cf10d13f65c3ae8b953fa6de5e8cc377042c (patch)
tree79b2ebd34de2bc6df2a6417064804cddfb2c3614 /python
parent4e476344c551c4c25e27047316690ee5b80dcefb (diff)
downloadqpid-python-53d1cf10d13f65c3ae8b953fa6de5e8cc377042c.tar.gz
fixed unicode and hex escapes to allow a-fA-F, and added tests
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@835893 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'python')
-rw-r--r--python/qpid/address.py6
-rw-r--r--python/qpid/tests/address.py40
2 files changed, 39 insertions, 7 deletions
diff --git a/python/qpid/address.py b/python/qpid/address.py
index 6ad6f23255..93336763f4 100644
--- a/python/qpid/address.py
+++ b/python/qpid/address.py
@@ -40,7 +40,7 @@ COMMA = Type("COMMA", r",")
NUMBER = Type("NUMBER", r'[+-]?[0-9]*\.?[0-9]+')
ID = Type("ID", r'[a-zA-Z_][a-zA-Z0-9_]*')
STRING = Type("STRING", r""""(?:[^\\"]|\\.)*"|'(?:[^\\']|\\.)*'""")
-ESC = Type("ESC", r"\\[^ux]|\\x[0-9][0-9]|\\u[0-9][0-9][0-9][0-0]")
+ESC = Type("ESC", r"\\[^ux]|\\x[0-9a-fA-F][0-9a-fA-F]|\\u[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]")
SYM = Type("SYM", r"[.#*%@$^!+-]")
WSPACE = Type("WSPACE", r"[ \n\r\t]+")
EOF = Type("EOF")
@@ -106,8 +106,10 @@ def tok2str(tok):
if tok.type is STRING:
return eval(tok.value)
elif tok.type is ESC:
- if tok.value[1] in ("x", "u"):
+ if tok.value[1] == "x":
return eval('"%s"' % tok.value)
+ elif tok.value[1] == "u":
+ return eval('u"%s"' % tok.value)
else:
return tok.value[1]
else:
diff --git a/python/qpid/tests/address.py b/python/qpid/tests/address.py
index 9ce073ee7f..75ce7b8e92 100644
--- a/python/qpid/tests/address.py
+++ b/python/qpid/tests/address.py
@@ -48,7 +48,8 @@ class AddressTests(Test):
"foo.bar", "baz.qux:moo:arf", {"key": "value"})
def testOptionsTrailingComma(self):
- self.valid("name/subject; {key: value,}", "name", "subject", {"key": "value"})
+ self.valid("name/subject; {key: value,}", "name", "subject",
+ {"key": "value"})
def testSemiSubject(self):
self.valid("foo.bar/'baz.qux;moo:arf'; {key: value}",
@@ -66,15 +67,44 @@ class AddressTests(Test):
"baz.qux.{moo,arf", {"key": "value"})
def testSlashQuote(self):
- self.valid("foo.bar\\/baz.qux.{moo,arf; {key: value}", "foo.bar/baz.qux.{moo,arf",
+ self.valid("foo.bar\\/baz.qux.{moo,arf; {key: value}",
+ "foo.bar/baz.qux.{moo,arf",
None, {"key": "value"})
- def testSlashEsc(self):
- self.valid("foo.bar\\x00baz.qux.{moo,arf; {key: value}", "foo.bar\x00baz.qux.{moo,arf",
+ def testSlashHexEsc1(self):
+ self.valid("foo.bar\\x00baz.qux.{moo,arf; {key: value}",
+ "foo.bar\x00baz.qux.{moo,arf",
None, {"key": "value"})
+ def testSlashHexEsc2(self):
+ self.valid("foo.bar\\xffbaz.qux.{moo,arf; {key: value}",
+ "foo.bar\xffbaz.qux.{moo,arf",
+ None, {"key": "value"})
+
+ def testSlashHexEsc3(self):
+ self.valid("foo.bar\\xFFbaz.qux.{moo,arf; {key: value}",
+ "foo.bar\xFFbaz.qux.{moo,arf",
+ None, {"key": "value"})
+
+ def testSlashUnicode1(self):
+ self.valid("foo.bar\\u1234baz.qux.{moo,arf; {key: value}",
+ u"foo.bar\u1234baz.qux.{moo,arf", None, {"key": "value"})
+
+ def testSlashUnicode2(self):
+ self.valid("foo.bar\\u0000baz.qux.{moo,arf; {key: value}",
+ u"foo.bar\u0000baz.qux.{moo,arf", None, {"key": "value"})
+
+ def testSlashUnicode3(self):
+ self.valid("foo.bar\\uffffbaz.qux.{moo,arf; {key: value}",
+ u"foo.bar\uffffbaz.qux.{moo,arf", None, {"key": "value"})
+
+ def testSlashUnicode4(self):
+ self.valid("foo.bar\\uFFFFbaz.qux.{moo,arf; {key: value}",
+ u"foo.bar\uFFFFbaz.qux.{moo,arf", None, {"key": "value"})
+
def testNoName(self):
- self.invalid("; {key: value}", "unexpected token SEMI(';') line:1,0:; {key: value}")
+ self.invalid("; {key: value}",
+ "unexpected token SEMI(';') line:1,0:; {key: value}")
def testEmpty(self):
self.invalid("", "unexpected token EOF line:1,0:")