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 __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)
class abbreviated_step(location_step): """ An object representing an abbreviated location step (XPath 1.0 grammar production 12: AbbreviatedStep) """ node_test = nodetests.node_type('node') predicates = None def __init__(self, abbrev): if abbrev == '.': axis = 'self' else: assert abbrev == '..' axis = 'parent' self.axis = axisspecifiers.axis_specifier(axis)
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)