Пример #1
0
def decodeProperty(p):
    if isinstance(p, str):
        v = json_loads_byteified(p)
    else:
        v = p
    if len(v['values']) > 0:
        return param.Property(v['key'], decode(v['values'], v['type']))
    else:
        return param.Property(v['key'], getTypeFromStr(v['type']).__class__)
Пример #2
0
    def test_deserializePropertyMap(self):
        params = {}
        params["MyDict"] = param.Property("MyDict", dict)
        params["MyFloat"] = param.Property("MyFloat", float)
        params = utils.deserializePropertyMap(
            utils.serializePropertyMap(params))
        properties = [p.printState() for p in params.values()]
        self.assertEqual(['MyDict:[]', 'MyFloat:[]'], properties)

        params["MyFloat"].value = 1.0
        properties = [p.printState() for p in params.values()]
        self.assertEqual(['MyDict:[]', 'MyFloat:[1.0]'], properties)
Пример #3
0
    def test_serializePropertyMap(self):
        params = {}
        params["MyDict"] = param.Property("MyDict", dict)
        s_property_map = utils.serializePropertyMap(params)
        expected = ('[key: "MyDict"\n' 'dataValue: "[]"\n' 'dataType: "dict"]')

        self.assertEqual(expected, str(s_property_map))

        params = {}
        params["MyString"] = param.Property("MyString", "String")
        s_property_map = utils.serializePropertyMap(params)
        expected = ('[key: "MyString"\n'
                    'dataValue: "[\\"String\\"]"\n'
                    'dataType: "str"]')

        self.assertEqual(expected, str(s_property_map))
Пример #4
0
def deserializePropertyMap(msg):
    """
    >>> params = {}
    >>> params["MyDict"] = param.Property("MyDict", dict)
    >>> params["MyFloat"] = param.Property("MyFloat", float)
    >>> params = deserializePropertyMap(serializePropertyMap(params))
    >>> for p in params.values(): p.printState()
    'MyDict:[]'
    'MyFloat:[]'
    >>> params["MyFloat"].value = 1.0
    >>> for p in params.values(): p.printState()
    'MyDict:[]'
    'MyFloat:[1.0]'
    """
    p_map = {}
    for p in msg:
        dataValue = json_loads_byteified(p.dataValue)
        if len(dataValue) > 0:
            p_map[p.key] = param.Property(p.key, decode(dataValue, p.dataType))
        else:
            p_map[p.key] = param.Property(p.key, getTypeFromStr(p.dataType).__class__)
    return p_map