summaryrefslogtreecommitdiffstats
path: root/xml/xpath/ParsedAbsoluteLocationPath.py
blob: 65e4169b0b8d04a6e020ed56d9a0eefc868a11b6 (plain) (blame)
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
########################################################################
#
# File Name:   ParsedAbsoluteLocationPath.py
#
#
"""
A Parsed Token that represents a absolute location path in the parsed 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 ParsedAbsoluteLocationPath:
    def __init__(self, child):
        self._child = child

    def evaluate(self, context):
        root = context.node.ownerDocument or context.node

        if self._child is None:
            return [root]

        origState = context.copyNodePosSize()
        context.setNodePosSize((root,1,1))
        rt = self._child.select(context)
        context.setNodePosSize(origState)

        return rt
    select = evaluate
    
    def pprint(self, indent=''):
        print indent + str(self)
        self._child and self._child.pprint(indent + '  ')


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

    def __repr__(self):
        return '/' + (self._child and repr(self._child) or '')