Пример #1
0
def decodeXMLValue(xmlValue):
    "Converts a python value returned by xmlrpc to a SPARK value"
    if isinstance(xmlValue, UNCHANGED_TYPES):
        return xmlValue
    elif xmlValue == None:
        return sparkNULL()
    elif isinstance(xmlValue, types.DictType):
        functor = xmlValue.get(FUNCTOR)
        if functor is not None:
            args = xmlValue.get(ARGS)
            if args is None:
                raise LowError("Missing %r element for structure"%ARGS)
            return Structure(Symbol(functor), decodeXMLValues(args))
        sym = xmlValue.get(SYM)
        if sym is not None:
            return Symbol(sym)
        var = xmlValue.get(VAR)
        if var is not None:
            return Variable(var)
        # default
        return dictMap(xmlValue, decodeXMLValue)
    elif isinstance(xmlValue, types.ListType):
        return decodeXMLValues(xmlValue)
    elif isinstance(xmlValue, types.TupleType):
        return decodeXMLValues(xmlValue)
    else:
        raise LowError("Cannot convert value of type %r from XML"%xmlValue.__class__)
Пример #2
0
def encodeXMLValue(sparkValue):
    "Converts a SPARK value to a python value that can be passed by XML"
    if isinstance(sparkValue, UNCHANGED_TYPES):
        return sparkValue
    if sparkValue == sparkNULL():
        return None
    elif isStructure(sparkValue):
        d = mapDict(sparkValue, encodeXMLValue)
        if d != None:
            return d
        else:
            # Use FUNCTOR/ARGS notation
            return {FUNCTOR:sparkValue.functor.name,
                    ARGS:encodeXMLValues(sparkValue)}
    elif isList(sparkValue):
        return encodeXMLValues(sparkValue)
    elif isSymbol(sparkValue):
        return {SYM:sparkValue.name}
    elif isVariable(sparkValue):
        return {VAR:sparkValue.name}
    else:
        raise LowError("Cannot convert python type %r to XML"%sparkValue.__class__)
Пример #3
0
def mapToSpark(**keyargs):
    "Given a set of keyword parameters representing a map, return the SPARK map object"
    return dictMap(keyargs)


def mapFromSpark(obj):
    "Given a SPARK map, return the correponding Python dict (or None if not a map)"
    try:
        return mapDict(obj)
    except:
        return None


_converter = XPS(
    sparkNULL(),  # nullValue
    True,  # useDouble
    False,  # useLong
    True,  # useBoolean
    mapToSpark,  # toSpark
    mapFromSpark  # fromSpark
)

toXPS = _converter.toXps
fromXPS = _converter.toSpark

S_XPS = Symbol("spark.io.xps.XPS")


def startXPSServer(agent):
    XPSSolver.setSparkSolver(SPARKSolver(agent))
Пример #4
0
def mapToSpark(**keyargs):
    "Given a set of keyword parameters representing a map, return the SPARK map object"
    return dictMap(keyargs)


def mapFromSpark(obj):
    "Given a SPARK map, return the correponding Python dict (or None if not a map)"
    try:
        return mapDict(obj)
    except:
        return None


_converter = XPS(
    sparkNULL(),  # nullValue
    True,  # useDouble
    False,  # useLong
    True,  # useBoolean
    mapToSpark,  # toSpark
    mapFromSpark,  # fromSpark
)

toXPS = _converter.toXps
fromXPS = _converter.toSpark


S_XPS = Symbol("spark.io.xps.XPS")


def startXPSServer(agent):