File: ParsedRelativeLocationPath.py

package info (click to toggle)
python-xml 0.8.4-10.1%2Blenny1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 4,972 kB
  • ctags: 10,628
  • sloc: python: 46,730; ansic: 14,354; xml: 968; makefile: 201; sh: 20
file content (51 lines) | stat: -rw-r--r-- 1,464 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
########################################################################
#
# File Name:   ParsedRelativeLocationPath.py
#
#
"""
A Parsed Token that represents a relative location path in the parsed result tree.
WWW: http://4suite.org/XPATH        e-mail: support@4suite.org

Copyright (c) 2000-2001 Fourthought Inc, USA.   All Rights Reserved.
See  http://4suite.org/COPYRIGHT  for license and copyright information
"""

class ParsedRelativeLocationPath:
    def __init__(self, left, right):
        self._left = left
        self._right = right
        return

    def evaluate(self, context):
        rt = self._left.select(context)
        if type(rt) != type([]):
            raise Exception("Expected node set from relative expression.  Got %s"%str(rt))

        origState = context.copyNodePosSize()

        result = []
        l = len(rt)
        for ctr in range(l):
            n = rt[ctr]
            context.setNodePosSize((n, ctr+1, l))
            result.extend(self._right.select(context))

        context.setNodePosSize(origState)

        return result
    select = evaluate

    def pprint(self, indent=''):
        print indent + str(self)
        self._left.pprint(indent + '  ')
        self._right.pprint(indent + '  ')

    def __str__(self):
        return '<RelativeLocationPath at %x: %s>' % (
            id(self),
            repr(self),
            )

    def __repr__(self):
        return repr(self._left) + '/' + repr(self._right)