Ejemplo n.º 1
0
 def __init__(self, path):
     assert isinstance(path, relative_location_path)
     self._steps = path._steps
     # `a//b` is the same as `a/descendant::b` if `b` uses the `child`
     # axis and has no (positional) predicates
     step = path._steps[0]
     if not step.predicates and isinstance(step.axis, axisspecifiers.child_axis):
         axis = axisspecifiers.axis_specifier("descendant")
         path._steps[0] = location_step(axis, step.node_test)
     else:
         axis = axisspecifiers.axis_specifier("descendant-or-self")
         node_test = nodetests.node_type("node")
         abbrev = location_step(axis, node_test)
         self._steps.insert(0, abbrev)
Ejemplo n.º 2
0
 def __init__(self, path):
     assert isinstance(path, relative_location_path)
     self._steps = path._steps
     # `a//b` is the same as `a/descendant::b` if `b` uses the `child`
     # axis and has no (positional) predicates
     step = path._steps[0]
     if not step.predicates and isinstance(step.axis,
                                           axisspecifiers.child_axis):
         axis = axisspecifiers.axis_specifier('descendant')
         path._steps[0] = location_step(axis, step.node_test)
     else:
         axis = axisspecifiers.axis_specifier('descendant-or-self')
         node_test = nodetests.node_type('node')
         abbrev = location_step(axis, node_test)
         self._steps.insert(0, abbrev)
Ejemplo n.º 3
0
 def __init__(self, abbrev):
     if abbrev == ".":
         axis = "self"
     else:
         assert abbrev == ".."
         axis = "parent"
     self.axis = axisspecifiers.axis_specifier(axis)
Ejemplo n.º 4
0
 def __init__(self, abbrev):
     if abbrev == '.':
         axis = 'self'
     else:
         assert abbrev == '..'
         axis = 'parent'
     self.axis = axisspecifiers.axis_specifier(axis)
Ejemplo n.º 5
0
 def __init__(self, expression, sep, path):
     if sep == '//':
         from amara.xpath.locationpaths import \
             relative_location_path, location_step
         from amara.xpath.locationpaths.axisspecifiers import axis_specifier
         from amara.xpath.locationpaths.nodetests import node_type
         assert isinstance(path, relative_location_path), repr(path)
         step = location_step(axis_specifier('descendant-or-self'),
                              node_type('node'))
         path._steps.insert(0, step)
     self._expression = expression
     self._path = path
     return
Ejemplo n.º 6
0
 def __init__(self, expression, sep, path):
     if sep == '//':
         from amara.xpath.locationpaths import \
             relative_location_path, location_step
         from amara.xpath.locationpaths.axisspecifiers import axis_specifier
         from amara.xpath.locationpaths.nodetests import node_type
         assert isinstance(path, relative_location_path), repr(path)
         step = location_step(axis_specifier('descendant-or-self'), 
                              node_type('node'))
         path._steps.insert(0, step)
     self._expression = expression
     self._path = path
     return
Ejemplo n.º 7
0
def test_ancestor_axis():
    assert list(axis_specifier('ancestor').select(CHILD1)) == [ROOT, DOC]
Ejemplo n.º 8
0
def test_child_axis():
    assert list(axis_specifier('child').select(CHILD2)) == list(CHILD2)
Ejemplo n.º 9
0
def test_following_axis():
    assert list(axis_specifier('following').select(CHILD3)) == (
        [CHILD3.xml_following_sibling, LANG] + list(LANG) + [LANG.xml_following_sibling, PI2])
Ejemplo n.º 10
0
def test_descendant_axis():
    assert list(axis_specifier('descendant').select(CHILD1)) == list(CHILD1)
Ejemplo n.º 11
0
def test_descendant_or_self_axis():
    assert list(axis_specifier('descendant-or-self').select(CHILD1)) == [CHILD1] + list(CHILD1)
Ejemplo n.º 12
0
def test_ancestor_or_self_axis():
    assert list(axis_specifier('ancestor-or-self').select(CHILD1)) == [
        CHILD1, ROOT, DOC
    ]
Ejemplo n.º 13
0
def test_ancestor_or_self_axis():
    assert list(axis_specifier('ancestor-or-self').select(CHILD1)) == [CHILD1, ROOT, DOC]
Ejemplo n.º 14
0
def test_descendant_axis():
    assert list(axis_specifier('descendant').select(CHILD1)) == list(CHILD1)
Ejemplo n.º 15
0
def test_descendant_or_self_axis():
    assert list(axis_specifier('descendant-or-self').select(
        CHILD1)) == [CHILD1] + list(CHILD1)
Ejemplo n.º 16
0
def test_ancestor_axis():
    assert list(axis_specifier('ancestor').select(CHILD1)) == [ROOT, DOC]
Ejemplo n.º 17
0
def test_following_axis():
    assert list(axis_specifier('following').select(CHILD3)) == (
        [CHILD3.xml_following_sibling, LANG] + list(LANG) +
        [LANG.xml_following_sibling, PI2])
Ejemplo n.º 18
0
def test_child_axis():
    assert list(axis_specifier('child').select(CHILD2)) == list(CHILD2)