pylib/uxml/uxpath/__init__.py
def qquery(xml_thing, xpath_thing, vars=None, funcs=None):
    '''
    Quick query. Convenience for using the MicroXPath engine.
    Give it some XML and an expression and it will yield the results. No fuss.
    
    xml_thing - bytes or string, or amara3.xml.tree node
    xpath_thing - string or parsed XPath expression
    vars - optional mapping of variables, name to value
    funcs - optional mapping of functions, name to function object
    
    >>> from amara3.uxml.uxpath import qquery
    >>> results = qquery(b'<a>1<b>2</b>3</a>', 'a/text()'))
    >>> next(results).xml_value
    '1'
    >>> next(results).xml_value
    '3'
    '''
    root = None
    if isinstance(xml_thing, nodetype):
        root = xml_thing
    elif isinstance(xml_thing, str):
        tb = tree.treebuilder()
        root = tb.parse(xml_thing)
    elif isinstance(xml_thing, bytes):
        tb = tree.treebuilder()
        #Force UTF-8
        root = tb.parse(xml_thing.decode('utf-8'))
    if not root: return
    if isinstance(xpath_thing, str):
        parsed_expr = parse(xpath_thing)
    ctx = context(root, variables=vars, functions=funcs)
    result = parsed_expr.compute(ctx)
    yield from result
def qquery(xml_thing, xpath_thing, vars=None, funcs=None):
    '''
    Quick query. Convenience for using the MicroXPath engine.
    Give it some XML and an expression and it will yield the results. No fuss.
    
    xml_thing - bytes or string, or amara3.xml.tree node
    xpath_thing - string or parsed XPath expression
    vars - optional mapping of variables, name to value
    funcs - optional mapping of functions, name to function object
    
    >>> from amara3.uxml.uxpath import qquery
    >>> results = qquery(b'<a>1<b>2</b>3</a>', 'a/text()'))
    >>> next(results).xml_value
    '1'
    >>> next(results).xml_value
    '3'
    '''
    root = None
    if isinstance(xml_thing, nodetype):
        root = xml_thing
    elif isinstance(xml_thing, str):
        tb = tree.treebuilder()
        root = tb.parse(xml_thing)
    elif isinstance(xml_thing, bytes):
        tb = tree.treebuilder()
        #Force UTF-8
        root = tb.parse(xml_thing.decode('utf-8'))
    if not root: return
    if isinstance(xpath_thing, str):
        parsed_expr = parse(xpath_thing)
    ctx = context(root, variables=vars, functions=funcs)
    result = parsed_expr.compute(ctx)
    yield from result
Quick query. Convenience for using the MicroXPath engine.
    Give it some XML and an expression and it will yield the results. No fuss.
    
    xml_thing - bytes or string, or amara3.xml.tree node
    xpath_thing - string or parsed XPath expression
    vars - optional mapping of variables, name to value
    funcs - optional mapping of functions, name to function object
    
    >>> from amara3.uxml.uxpath import qquery
    >>> results = qquery(b'<a>1<b>2</b>3</a>', 'a/text()'))
    >>> next(results).xml_value
    '1'
    >>> next(results).xml_value
    '3'