Exemple #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)
Exemple #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)
Exemple #3
0
 def __init__(self, abbrev):
     if abbrev == ".":
         axis = "self"
     else:
         assert abbrev == ".."
         axis = "parent"
     self.axis = axisspecifiers.axis_specifier(axis)
Exemple #4
0
 def __init__(self, abbrev):
     if abbrev == '.':
         axis = 'self'
     else:
         assert abbrev == '..'
         axis = 'parent'
     self.axis = axisspecifiers.axis_specifier(axis)
Exemple #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
Exemple #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
def test_ancestor_axis():
    assert list(axis_specifier('ancestor').select(CHILD1)) == [ROOT, DOC]
def test_child_axis():
    assert list(axis_specifier('child').select(CHILD2)) == list(CHILD2)
def test_following_axis():
    assert list(axis_specifier('following').select(CHILD3)) == (
        [CHILD3.xml_following_sibling, LANG] + list(LANG) + [LANG.xml_following_sibling, PI2])
def test_descendant_axis():
    assert list(axis_specifier('descendant').select(CHILD1)) == list(CHILD1)
def test_descendant_or_self_axis():
    assert list(axis_specifier('descendant-or-self').select(CHILD1)) == [CHILD1] + list(CHILD1)
Exemple #12
0
def test_ancestor_or_self_axis():
    assert list(axis_specifier('ancestor-or-self').select(CHILD1)) == [
        CHILD1, ROOT, DOC
    ]
def test_ancestor_or_self_axis():
    assert list(axis_specifier('ancestor-or-self').select(CHILD1)) == [CHILD1, ROOT, DOC]
Exemple #14
0
def test_descendant_axis():
    assert list(axis_specifier('descendant').select(CHILD1)) == list(CHILD1)
Exemple #15
0
def test_descendant_or_self_axis():
    assert list(axis_specifier('descendant-or-self').select(
        CHILD1)) == [CHILD1] + list(CHILD1)
Exemple #16
0
def test_ancestor_axis():
    assert list(axis_specifier('ancestor').select(CHILD1)) == [ROOT, DOC]
Exemple #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])
Exemple #18
0
def test_child_axis():
    assert list(axis_specifier('child').select(CHILD2)) == list(CHILD2)