# HG changeset patch
# User hodgestar
# Date 1395320490 0
# Node ID ddb9354ad555e7e94234f3ff041d7c379a4d68a6
# Parent cddcb39ce5dd3a381180234c9995a3c9335a911c
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)