Mercurial > genshi > mirror
changeset 1045:d7ede0cf4735 stable-0.6.x tip
Merge r1269 from trunk (fix for selecting namespaced attributes).
author | hodgestar |
---|---|
date | Thu, 20 Mar 2014 13:01:56 +0000 |
parents | 63c0a3911ab8 |
children | |
files | genshi/path.py genshi/tests/path.py |
diffstat | 2 files changed, 21 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- 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):
--- 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('<root><foo bar="abc"></foo></root>') + 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( + '<root xmlns:ns1="http://example.com">' + '<foo ns1:bar="abc"></foo>' + '</root>') + 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)