Mercurial > genshi > mirror
changeset 215:94120e6b0ce4 trunk
A couple of minor XPath fixes.
author | cmlenz |
---|---|
date | Fri, 01 Sep 2006 13:45:42 +0000 |
parents | ab407defd204 |
children | 636fe6766b4d |
files | markup/path.py markup/tests/path.py setup.py |
diffstat | 3 files changed, 21 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/markup/path.py +++ b/markup/path.py @@ -46,7 +46,6 @@ CHILD = 'child' DESCENDANT = 'descendant' DESCENDANT_OR_SELF = 'descendant-or-self' - NAMESPACE = 'namespace' SELF = 'self' def forname(cls, name): @@ -61,7 +60,6 @@ CHILD = Axis.CHILD DESCENDANT = Axis.DESCENDANT DESCENDANT_OR_SELF = Axis.DESCENDANT_OR_SELF -NAMESPACE = Axis.NAMESPACE SELF = Axis.SELF @@ -174,10 +172,9 @@ if matched: if cursor + 1 == size: # the last location step - if ignore_context or \ - kind is not START or \ - axis in (ATTRIBUTE, NAMESPACE, SELF) or \ - len(stack) > 2: + if ignore_context or kind is not START \ + or axis is ATTRIBUTE or axis is SELF \ + or len(stack) > 2: return matched else: cursor += 1 @@ -192,8 +189,8 @@ # the current element is closed... so we need to move the # cursor back to the previous closure and retest that # against the current element - backsteps = [step for step in steps[:cursor] - if step[0] in (DESCENDANT, DESCENDANT_OR_SELF)] + backsteps = [(k, d, p) for k, d, p in steps[:cursor] + if k is DESCENDANT or k is DESCENDANT_OR_SELF] backsteps.reverse() for axis, nodetest, predicates in backsteps: matched = nodetest(kind, data, pos, variables) @@ -276,12 +273,14 @@ def _location_path(self): steps = [] while True: - if self.cur_token == '//': - steps.append((DESCENDANT_OR_SELF, NodeTest(), [])) + if self.cur_token.startswith('/'): + if self.cur_token == '//': + steps.append((DESCENDANT_OR_SELF, NodeTest(), [])) + elif not steps: + raise PathSyntaxError('Absolute location paths not ' + 'supported', self.filename, + self.lineno) self.next_token() - elif self.cur_token == '/' and not steps: - raise PathSyntaxError('Absolute location paths not supported', - self.filename, self.lineno) axis, nodetest, predicates = self._location_step() if not axis: @@ -290,7 +289,6 @@ if self.at_end or not self.cur_token.startswith('/'): break - self.next_token() return steps @@ -894,7 +892,7 @@ def __call__(self, kind, data, pos, variables): return TEXT, variables.get(self.name), (None, -1, -1) def __repr__(self): - return str(self.number) + return str(self.name) # Operators
--- a/markup/tests/path.py +++ b/markup/tests/path.py @@ -110,7 +110,8 @@ self.assertEqual('Hey', path.select(xml).render()) path = Path('.//text()') - self.assertEqual('<Path "self::node()/child::text()">', repr(path)) + self.assertEqual('<Path "self::node()/descendant-or-self::node()/child::text()">', + repr(path)) self.assertEqual('Hey', path.select(xml).render()) def test_2step(self): @@ -123,10 +124,10 @@ xml = XML('<elem class="x"><span id="joe">Hey Joe</span></elem>') #self.assertEqual('x', Path('@*').select(xml).render()) #self.assertEqual('x', Path('./@*').select(xml).render()) - #self.assertEqual('xjoe', Path('//@*').select(xml).render()) + #self.assertEqual('xjoe', Path('.//@*').select(xml).render()) self.assertEqual('joe', Path('*/@*').select(xml).render()) - xml = XML('<elem><foo id="1"/>foo id="2"/></elem>') + xml = XML('<elem><foo id="1"/><foo id="2"/></elem>') #self.assertEqual('', Path('@*').select(xml).render()) #self.assertEqual('12', Path('foo/@*').select(xml).render())
--- a/setup.py +++ b/setup.py @@ -22,9 +22,9 @@ version = '0.3', description = 'Toolkit for stream-based generation of markup for the web', long_description = \ -'''Markup is a Python library that provides an integrated set of components for +"""Markup is a Python library that provides an integrated set of components for parsing, generating, and processing HTML or XML content in a uniform manner. -The major feature is a template language that is heavily inspired by Kid.''', +The major feature is a template language that is heavily inspired by Kid.""", author = 'Edgewall Software', author_email = 'info@edgewall.org', license = 'BSD', @@ -44,7 +44,8 @@ 'Topic :: Text Processing :: Markup :: HTML', 'Topic :: Text Processing :: Markup :: XML' ], - packages=['markup'], + keywords = ['python.templating.engines'], + packages = ['markup'], test_suite = 'markup.tests.suite', extras_require = {'plugin': ['setuptools>=0.6a2']},