示例#1
0
def parse_om_file(fname):
    """ Parses OpenMath XML from a file.

    Parses the file contents and calls the decoder on the root
    of the tree produced.

    :param fname: The path to the file containing the XML data
    :returns: The object represented by the file contents
    """
    tree = ET.parse(fname)
    root = tree.getroot()
    omobj = parse_om_root(root)
    return omobj
示例#2
0
def parse_om_string(omstring):
    """ Parses OpenMath XML from a string.

    Parses the string contents and calls the decoder on the root
    of the tree produced.

    :params omstring: The string representation of the XML data.
    :returns: The object represented by the XML from the string.
    """
    root = ET.fromstring(omstring)
    try:
         omobj = parse_om_root(root)
    except(UnsupportedCDError,UnexpectedSymbolError) as err:
         return str(err)
    return omobj
示例#3
0
def evaluate_om_string(omstring, vars={}):
    """ Evaluates OpenMath XML Strings

    Parses the string contents and calls the evaluator on the 
    root of the tree produced.

    :params omstring: The string representation of the XML data.
    :params vars: A dictionary containing any variables required
    """
    try:
        root = ET.fromstring(omstring)
        omobj = parse_om_root(root)
        result = omobj.eval()
    except (DivideByZeroError, UnexpectedSymbolError,
            UnsupportedCDError,InvalidArgsError) as err:
        return str(err)

    return result