def _registerList(self, objectId, list_): """ `_registerList`: register a `list` instance with `self.objectRegistry`. Recursively call `walkPyObject` on the values in the list. """ if all(isPrimitive(val) for val in list_): self._registerPrimitive(objectId, list_) else: memberIds = [self.walkPyObject(val) for val in list_] self._objectRegistry.defineList(objectId=objectId, memberIds=memberIds)
def _registerList(self, objectId, list_): """ `_registerList`: register a `list` instance with `self.objectRegistry`. Recursively call `walkPyObject` on the values in the list. """ if all(isPrimitive(val) for val in list_): self._registerPrimitive(objectId, list_) else: memberIds = [self.walkPyObject(val) for val in list_] self._objectRegistry.defineList( objectId=objectId, memberIds=memberIds )
def _walkPyObject(self, pyObject, objectId): if isinstance(pyObject, RemotePythonObject.RemotePythonObject): self._registerRemotePythonObject(objectId, pyObject) elif isinstance(pyObject, Future.Future): #it would be better to register the future and do a second pass of walking self._walkPyObject(pyObject.result(), objectId) elif isinstance(pyObject, _FileDescription): self._registerFileDescription(objectId, pyObject) elif isinstance(pyObject, Exception) and pyObject.__class__ in \ NamedSingletons.pythonSingletonToName: self._registerBuiltinExceptionInstance(objectId, pyObject) elif isinstance(pyObject, (type, type(isinstance))) and \ pyObject in NamedSingletons.pythonSingletonToName: self._registerNamedSingleton( objectId, NamedSingletons.pythonSingletonToName[pyObject] ) elif isinstance(pyObject, PyforaWithBlock.PyforaWithBlock): self._registerWithBlock(objectId, pyObject) elif isinstance(pyObject, _Unconvertible): self._registerUnconvertible(objectId) elif isinstance(pyObject, tuple): self._registerTuple(objectId, pyObject) elif isinstance(pyObject, list): self._registerList(objectId, pyObject) elif isinstance(pyObject, dict): self._registerDict(objectId, pyObject) elif isPrimitive(pyObject): self._registerPrimitive(objectId, pyObject) elif PyforaInspect.isfunction(pyObject): self._registerFunction(objectId, pyObject) elif PyforaInspect.isclass(pyObject): self._registerClass(objectId, pyObject) elif isinstance(pyObject, instancemethod): self._registerInstanceMethod(objectId, pyObject) elif isClassInstance(pyObject): self._registerClassInstance(objectId, pyObject) else: assert False, "don't know what to do with %s" % pyObject
def _walkPyObject(self, pyObject, objectId): if isinstance(pyObject, RemotePythonObject.RemotePythonObject): self._registerRemotePythonObject(objectId, pyObject) elif isinstance(pyObject, Future.Future): #it would be better to register the future and do a second pass of walking self._walkPyObject(pyObject.result(), objectId) elif isinstance(pyObject, _FileDescription): self._registerFileDescription(objectId, pyObject) elif isinstance(pyObject, Exception) and pyObject.__class__ in \ NamedSingletons.pythonSingletonToName: self._registerBuiltinExceptionInstance(objectId, pyObject) elif isinstance(pyObject, (type, type(isinstance))) and \ pyObject in NamedSingletons.pythonSingletonToName: self._registerNamedSingleton( objectId, NamedSingletons.pythonSingletonToName[pyObject]) elif isinstance(pyObject, PyforaWithBlock.PyforaWithBlock): self._registerWithBlock(objectId, pyObject) elif isinstance(pyObject, _Unconvertible): self._registerUnconvertible(objectId) elif isinstance(pyObject, tuple): self._registerTuple(objectId, pyObject) elif isinstance(pyObject, list): self._registerList(objectId, pyObject) elif isinstance(pyObject, dict): self._registerDict(objectId, pyObject) elif isPrimitive(pyObject): self._registerPrimitive(objectId, pyObject) elif PyforaInspect.isfunction(pyObject): self._registerFunction(objectId, pyObject) elif PyforaInspect.isclass(pyObject): self._registerClass(objectId, pyObject) elif isinstance(pyObject, instancemethod): self._registerInstanceMethod(objectId, pyObject) elif isClassInstance(pyObject): self._registerClassInstance(objectId, pyObject) else: assert False, "don't know what to do with %s" % pyObject
def walkPyObject(self, pyObject): """ `walkPyObject`: recursively traverse a live python object, registering its "pieces" with an `ObjectRegistry` (`self.objectRegistry`). Note that we use python `id`s for caching in this class, which means it cannot be used in cases where `id`s might get reused (recall they are just memory addresses). `objectId`s are assigned to all pieces of the python object. Returns: An `int`, the `objectId` of the root python object. """ if id(pyObject) in self._pyObjectIdToObjectId: return self._pyObjectIdToObjectId[id(pyObject)] if id(pyObject) in self._convertedObjectCache: pyObject = self._convertedObjectCache[id(pyObject)] elif self._purePythonClassMapping.canMap(pyObject): pureInstance = self._purePythonClassMapping.mappableInstanceToPure( pyObject) self._convertedObjectCache[id(pyObject)] = pureInstance pyObject = pureInstance objectId = self._allocateId(pyObject) if isinstance(pyObject, RemotePythonObject.RemotePythonObject): self._registerRemotePythonObject(objectId, pyObject) elif isinstance(pyObject, _FileDescription): self._registerFileDescription(objectId, pyObject) elif isinstance(pyObject, Exception) and pyObject.__class__ in \ NamedSingletons.pythonSingletonToName: self._registerBuiltinExceptionInstance(objectId, pyObject) elif isinstance(pyObject, (type, type(isinstance))) and \ pyObject in NamedSingletons.pythonSingletonToName: self._registerNamedSingleton( objectId, NamedSingletons.pythonSingletonToName[pyObject]) elif isinstance(pyObject, PyforaWithBlock.PyforaWithBlock): self._registerWithBlock(objectId, pyObject) elif isinstance(pyObject, tuple): self._registerTuple(objectId, pyObject) elif isinstance(pyObject, list): self._registerList(objectId, pyObject) elif isinstance(pyObject, dict): self._registerDict(objectId, pyObject) elif isPrimitive(pyObject): self._registerPrimitive(objectId, pyObject) elif PyforaInspect.isfunction(pyObject): self._registerFunction(objectId, pyObject) elif PyforaInspect.isclass(pyObject): self._registerClass(objectId, pyObject) elif isinstance(pyObject, instancemethod): self._registerInstanceMethod(objectId, pyObject) elif isClassInstance(pyObject): self._registerClassInstance(objectId, pyObject) else: assert False, "don't know what to do with %s" % pyObject return objectId
def walkPyObject(self, pyObject): """ `walkPyObject`: recursively traverse a live python object, registering its "pieces" with an `ObjectRegistry` (`self.objectRegistry`). Note that we use python `id`s for caching in this class, which means it cannot be used in cases where `id`s might get reused (recall they are just memory addresses). `objectId`s are assigned to all pieces of the python object. Returns: An `int`, the `objectId` of the root python object. """ if id(pyObject) in self._pyObjectIdToObjectId: return self._pyObjectIdToObjectId[id(pyObject)] if id(pyObject) in self._convertedObjectCache: pyObject = self._convertedObjectCache[id(pyObject)] elif self._purePythonClassMapping.canMap(pyObject): pureInstance = self._purePythonClassMapping.mappableInstanceToPure( pyObject ) self._convertedObjectCache[id(pyObject)] = pureInstance pyObject = pureInstance objectId = self._allocateId(pyObject) if isinstance(pyObject, RemotePythonObject.RemotePythonObject): self._registerRemotePythonObject(objectId, pyObject) elif isinstance(pyObject, _FileDescription): self._registerFileDescription(objectId, pyObject) elif isinstance(pyObject, Exception) and pyObject.__class__ in \ NamedSingletons.pythonSingletonToName: self._registerBuiltinExceptionInstance(objectId, pyObject) elif isinstance(pyObject, (type, type(isinstance))) and \ pyObject in NamedSingletons.pythonSingletonToName: self._registerNamedSingleton( objectId, NamedSingletons.pythonSingletonToName[pyObject] ) elif isinstance(pyObject, PyforaWithBlock.PyforaWithBlock): self._registerWithBlock(objectId, pyObject) elif isinstance(pyObject, tuple): self._registerTuple(objectId, pyObject) elif isinstance(pyObject, list): self._registerList(objectId, pyObject) elif isinstance(pyObject, dict): self._registerDict(objectId, pyObject) elif isPrimitive(pyObject): self._registerPrimitive(objectId, pyObject) elif PyforaInspect.isfunction(pyObject): self._registerFunction(objectId, pyObject) elif PyforaInspect.isclass(pyObject): self._registerClass(objectId, pyObject) elif isinstance(pyObject, instancemethod): self._registerInstanceMethod(objectId, pyObject) elif isClassInstance(pyObject): self._registerClassInstance(objectId, pyObject) else: assert False, "don't know what to do with %s" % pyObject return objectId