def __init__(self, obj, cb): self.obj = obj # Scrub your object, label it as a method, send it out methods = scrubber.scrub(dictify(obj)) methods['method'] = 'methods' #output callback self.cb(json.dumps(methods))
def scrub(node): # I want to dictify vanilla objects only. # wtf_is(node.value) if wtf_is(node.value)["is_a"] == [types.ObjectType]: node.set(dictify(node.value)) # I want to scrub out functions here. if isinstance(node.value, types.FunctionType) or isinstance(node.value, types.MethodType): # register the function/method into the lut, get an id (key). fname = self.lut.register(node.value) # Adds function and path to callbacks list callbacks.append((fname, node.path)) node.set("[function]")
def scrub(self, args): callbacks = [] if wtf_is(args)["is_a"] == [types.ObjectType]: scrubbed = dictify(args) else: scrubbed = args[:] @walk(scrubbed) def scrub(node): # I want to dictify vanilla objects only. # wtf_is(node.value) if wtf_is(node.value)["is_a"] == [types.ObjectType]: node.set(dictify(node.value)) # I want to scrub out functions here. if isinstance(node.value, types.FunctionType) or isinstance(node.value, types.MethodType): # register the function/method into the lut, get an id (key). fname = self.lut.register(node.value) # Adds function and path to callbacks list callbacks.append((fname, node.path)) node.set("[function]") # Some trickery with the "arguments" field. May not suffice. return {"arguments": [scrubbed] if type(scrubbed) == dict else list(scrubbed), "callbacks": dict(callbacks)}