summaryrefslogtreecommitdiff
path: root/qpid/python
diff options
context:
space:
mode:
authorRafael H. Schloming <rhs@apache.org>2007-07-24 22:16:45 +0000
committerRafael H. Schloming <rhs@apache.org>2007-07-24 22:16:45 +0000
commitb1a136bc3613c685c278ef9940a562ee75388fc3 (patch)
tree39b200aa41cab04d987ba34bca9bf6019e9e7a34 /qpid/python
parent9b3a523d044be6ae5e88a96a4513b05a48d4feb6 (diff)
downloadqpid-python-b1a136bc3613c685c278ef9940a562ee75388fc3.tar.gz
Made attributes queryable.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@559241 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/python')
-rw-r--r--qpid/python/mllib/dom.py29
1 files changed, 20 insertions, 9 deletions
diff --git a/qpid/python/mllib/dom.py b/qpid/python/mllib/dom.py
index 9b1740055b..80f1f2a409 100644
--- a/qpid/python/mllib/dom.py
+++ b/qpid/python/mllib/dom.py
@@ -145,14 +145,6 @@ class Tag(Node):
if name == k:
return v
- def __getitem__(self, name):
- if name and name[0] == "@":
- return self.get_attr(name[1:])
- else:
- for nd in self.query[name]:
- return nd
- return self.get_attr(name)
-
def dispatch(self, f):
try:
method = getattr(f, "do_" + self.name)
@@ -203,6 +195,9 @@ class Filter(View):
elif predicate[0] == "#":
type = predicate[1:]
self.predicate = lambda x: x.is_type(type)
+ elif predicate[0] == "@":
+ name = predicate[1:]
+ self.predicate = lambda x: x[0] == name
else:
self.predicate = lambda x: isinstance(x, Tag) and x.name == predicate
@@ -231,6 +226,19 @@ class Children(View):
for child in nd.children:
yield child
+class Attributes(View):
+
+ def __iter__(self):
+ for nd in self.source:
+ for a in nd.attrs:
+ yield a
+
+class Values(View):
+
+ def __iter__(self):
+ for name, value in self.source:
+ yield value
+
class Query(View):
def __iter__(self):
@@ -245,6 +253,9 @@ class Query(View):
query = self.source
for p in path:
- query = Query(Filter(p, Flatten(Children(query))))
+ if isinstance(p, basestring) and p[0] == "@":
+ query = Values(Filter(p, Attributes(query)))
+ else:
+ query = Query(Filter(p, Flatten(Children(query))))
return query