示例#1
0
class Class(threading.Thread):
    def __init__(self, name, API):
        threading.Thread.__init__(self)
        self.name = name
        self.ipc = DynamicObject({})
        self.ipc.extend(API)

        # make all functions accessible by default
        for key in vars(self.ipc):
            setattr(self, key, getattr(self.ipc, key))

        # overwriting functions for convenience (and security) - abstracting the 'self' out
        def registerOutput(tag, defaults):
            self.ipc.registerOutput(self, tag, defaults)

        self.registerOutput = registerOutput

        def output(tag, value):
            return self.ipc.output(self, tag, value)

        self.output = output

        def message(msg):
            return self.ipc.message(self, msg)

        self.message = message
示例#2
0
class Class (threading.Thread):
    def __init__(self, name, API):
        threading.Thread.__init__(self)
        self.name = name
        self.ipc = DynamicObject({})
        self.ipc.extend(API)
        
        # make all functions accessible by default
        for key in vars(self.ipc):
            setattr(self, key, getattr(self.ipc, key))

        # overwriting functions for convenience (and security) - abstracting the 'self' out
        def registerOutput (tag, defaults):
            self.ipc.registerOutput(self, tag, defaults)
        self.registerOutput = registerOutput

        def output (tag, value):
            return self.ipc.output(self, tag, value)
        self.output = output

        def message (msg):
            return self.ipc.message(self, msg)
        self.message = message
示例#3
0
print("")

# access like a dictionary / map
print("# access like a dictionary / map")
print(obj["a"])
print("")

# update / create field like a dictionary / map
print("# update / create field like a dictionary / map")
obj["d"] = 8
print(obj)
print("")

# extend object with dictionary - only affects values specified
print("# update object - only affects values specified")
obj.extend({"a": 10, "e": False})
print(obj)
print("")

# extend object with another DynamicObject
print("# extend object with another DynamicObject")
obj2 = DynamicObject({"a": 999, "w": True})
obj.extend(obj2)
print(obj)
print("")

# nested objects
print("# nested objects")
obj.f = DynamicObject({"x": 1, "y": 2, "z": 3})
print(obj)
print("")
示例#4
0
print("")

# access like a dictionary / map
print("# access like a dictionary / map")
print(obj["a"])
print("")

# update / create field like a dictionary / map
print("# update / create field like a dictionary / map")
obj["d"] = 8
print(obj)
print("")

# extend object with dictionary - only affects values specified
print("# update object - only affects values specified")
obj.extend({"a": 10, "e": False})
print(obj)
print("")

# extend object with another DynamicObject
print("# extend object with another DynamicObject")
obj2 = DynamicObject({"a": 999, "w": True})
obj.extend(obj2)
print(obj)
print("")

# nested objects
print("# nested objects")
obj.f = DynamicObject({"x": 1, "y": 2, "z": 3})
print(obj)
print("")