# HG changeset patch
# User hodgestar
# Date 1395320516 0
# Node ID d7ede0cf4735ae2d3407f06c2e101b8c4fd573dc
# Parent 63c0a3911ab8ff00f2e1ba202c3f68d8f49049bf
Merge r1269 from trunk (fix for selecting namespaced attributes).
diff --git a/genshi/path.py b/genshi/path.py
--- a/genshi/path.py
+++ b/genshi/path.py
@@ -1008,7 +1008,7 @@
qname = QName('%s}%s' % (namespaces.get(self.prefix), self.name))
if kind is START:
if self.principal_type is ATTRIBUTE and qname in data[1]:
- return Attrs([(self.name, data[1].get(self.name))])
+ return Attrs([(qname, data[1].get(qname))])
else:
return data[0] == qname
def __repr__(self):
diff --git a/genshi/tests/path.py b/genshi/tests/path.py
--- a/genshi/tests/path.py
+++ b/genshi/tests/path.py
@@ -14,6 +14,7 @@
import doctest
import unittest
+from genshi.core import Attrs, QName
from genshi.input import XML
from genshi.path import Path, PathParser, PathSyntaxError, GenericStrategy, \
SingleStepStrategy, SimplePathStrategy
@@ -630,6 +631,25 @@
'/descendant::b/descendant::c', input=xml,
output='')
+ def test_attr_selection(self):
+ xml = XML('')
+ path = Path('foo/@bar')
+ result = path.select(xml)
+ self.assertEqual(list(result), [
+ Attrs([(QName('bar'), u'abc')])
+ ])
+
+ def test_attr_selection_with_namespace(self):
+ xml = XML(
+ ''
+ ''
+ '')
+ path = Path('foo/@ns1:bar')
+ result = path.select(xml, namespaces={'ns1': 'http://example.com'})
+ self.assertEqual(list(result), [
+ Attrs([(QName('http://example.com}bar'), u'abc')])
+ ])
+
def _test_support(self, strategy_class, text):
path = PathParser(text, None, -1).parse()[0]
return strategy_class.supports(path)