コード例 #1
0
ファイル: ObjectRegistry.py プロジェクト: ufora/ufora
    def _computeDependentIds(self, objectId):
        objectDefinition = self.objectIdToObjectDefinition[objectId]

        if TypeDescription.isPrimitive(objectDefinition) or \
                isinstance(objectDefinition,
                           (TypeDescription.File, TypeDescription.RemotePythonObject,
                            TypeDescription.NamedSingleton, list,
                            TypeDescription.Unconvertible,
                            TypeDescription.PackedHomogenousData,
                            TypeDescription.UnresolvedVarWithPosition
                            )):
            return []
        elif isinstance(objectDefinition,
                        (TypeDescription.BuiltinExceptionInstance)):
            return [objectDefinition.argsId]
        elif isinstance(objectDefinition,
                        (TypeDescription.List, TypeDescription.Tuple)):
            return objectDefinition.memberIds
        elif isinstance(objectDefinition, (TypeDescription.FunctionDefinition,
                                           TypeDescription.ClassDefinition)):
            tr = objectDefinition.freeVariableMemberAccessChainsToId.values()
            tr.append(objectDefinition.sourceFileId)
            return tr
        elif isinstance(objectDefinition, TypeDescription.InstanceMethod):
            return [objectDefinition.instanceId]
        elif isinstance(objectDefinition,
                        TypeDescription.ClassInstanceDescription):
            tr = [objectDefinition.classId]
            tr.extend(self._computeDependentIds(objectDefinition.classId))
            classMemberIds = \
                objectDefinition.classMemberNameToClassMemberId.values()
            tr.extend(classMemberIds)

            return tr
        elif isinstance(objectDefinition, TypeDescription.Dict):
            return objectDefinition.keyIds + objectDefinition.valueIds
        elif isinstance(objectDefinition,
                        TypeDescription.WithBlockDescription):
            tr = objectDefinition.freeVariableMemberAccessChainsToId.values()
            tr.append(objectDefinition.sourceFileId)

            return tr
        else:
            assert False, "don't know what to do with %s" % type(
                objectDefinition)
コード例 #2
0
ファイル: ObjectRegistry.py プロジェクト: Sandy4321/ufora
    def _computeDependentIds(self, objectId):
        objectDefinition = self.objectIdToObjectDefinition[objectId]

        if TypeDescription.isPrimitive(objectDefinition) or \
                isinstance(objectDefinition,
                           (TypeDescription.File, TypeDescription.RemotePythonObject,
                            TypeDescription.NamedSingleton, list,
                            TypeDescription.Unconvertible)):
            return []
        elif isinstance(objectDefinition, (TypeDescription.BuiltinExceptionInstance)):
            return [objectDefinition.argsId]
        elif isinstance(objectDefinition, (TypeDescription.List, TypeDescription.Tuple)):
            return objectDefinition.memberIds
        elif isinstance(objectDefinition,
                        (TypeDescription.FunctionDefinition, TypeDescription.ClassDefinition)):
            tr = objectDefinition.freeVariableMemberAccessChainsToId.values()
            tr.append(objectDefinition.sourceFileId)
            return tr
        elif isinstance(objectDefinition, TypeDescription.InstanceMethod):
            return [objectDefinition.instanceId]
        elif isinstance(objectDefinition, TypeDescription.ClassInstanceDescription):
            tr = [objectDefinition.classId]
            tr.extend(
                self._computeDependentIds(
                    objectDefinition.classId
                    )
                )
            classMemberIds = \
                objectDefinition.classMemberNameToClassMemberId.values()
            tr.extend(classMemberIds)

            return tr
        elif isinstance(objectDefinition, TypeDescription.Dict):
            return objectDefinition.keyIds + objectDefinition.valueIds
        elif isinstance(objectDefinition, TypeDescription.WithBlockDescription):
            tr = objectDefinition.freeVariableMemberAccessChainsToId.values()
            tr.append(objectDefinition.sourceFileId)

            return tr
        else:
            assert False, "don't know what to do with %s" % type(objectDefinition)
コード例 #3
0
    def _convert(self, objectId, dependencyGraph, objectIdToObjectDefinition):
        objectDefinition = objectIdToObjectDefinition[objectId]
        logging.info("ObjectDefinition: %s", objectDefinition)

        if TypeDescription.isPrimitive(objectDefinition) or isinstance(
                objectDefinition, list):
            return self.convertPrimitive(objectDefinition)
        elif isinstance(objectDefinition, TypeDescription.RemotePythonObject):
            return self.convertRemotePythonObject(objectDefinition)
        elif isinstance(objectDefinition, TypeDescription.NamedSingleton):
            return self.convertNamedSingleton(objectDefinition)
        elif isinstance(objectDefinition,
                        TypeDescription.BuiltinExceptionInstance):
            return self.convertBuiltinExceptionInstance(objectDefinition)
        elif isinstance(objectDefinition,
                        (TypeDescription.FunctionDefinition,
                         TypeDescription.ClassDefinition,
                         TypeDescription.ClassInstanceDescription,
                         TypeDescription.InstanceMethod)):
            return (self.convertObjectWithDependencies(
                objectId, dependencyGraph, objectIdToObjectDefinition))
        elif isinstance(objectDefinition, TypeDescription.List):
            return (self.convertList(objectId, dependencyGraph,
                                     objectIdToObjectDefinition))
        elif isinstance(objectDefinition, TypeDescription.Tuple):
            return (self.convertTuple(objectId, dependencyGraph,
                                      objectIdToObjectDefinition))
        elif isinstance(objectDefinition, TypeDescription.Dict):
            return (self.convertDict(objectId, objectDefinition,
                                     dependencyGraph,
                                     objectIdToObjectDefinition))
        elif isinstance(objectDefinition,
                        TypeDescription.WithBlockDescription):
            return (self.convertObjectWithDependencies(
                objectId, dependencyGraph, objectIdToObjectDefinition))
        else:
            raise pyfora.PythonToForaConversionError(
                "don't know how to convert %s of type %s" %
                (objectDefinition, type(objectDefinition)))
コード例 #4
0
    def convertStronglyConnectedComponentWithOneNode(
            self, dependencyGraph, stronglyConnectedComponent,
            objectIdToObjectDefinition):
        objectId = stronglyConnectedComponent[0]

        objectDefinition = objectIdToObjectDefinition[objectId]

        if TypeDescription.isPrimitive(objectDefinition) or isinstance(
                objectDefinition, list):
            self.convertedValues[objectId] = self.convertPrimitive(
                objectDefinition)

        elif isinstance(objectDefinition, (TypeDescription.FunctionDefinition,
                                           TypeDescription.ClassDefinition)):
            self.convertStronglyConnectedComponentWithOneFunctionOrClass(
                objectId, objectDefinition, objectIdToObjectDefinition)

        elif isinstance(objectDefinition,
                        TypeDescription.ClassInstanceDescription):
            self.convertClassInstanceDescription(objectId, objectDefinition)

        elif isinstance(objectDefinition, TypeDescription.List):
            self.convertedValues[objectId] = self.convertList(
                objectId,
                self._computeRestrictedGraph(objectId, dependencyGraph),
                objectIdToObjectDefinition)

        elif isinstance(objectDefinition, TypeDescription.Tuple):
            self.convertedValues[objectId] = self.convertTuple(
                objectId,
                self._computeRestrictedGraph(objectId, dependencyGraph),
                objectIdToObjectDefinition)

        elif isinstance(objectDefinition, TypeDescription.Dict):
            self.convertedValues[objectId] = self.convertDict(
                objectId, objectDefinition,
                self._computeRestrictedGraph(objectId, dependencyGraph),
                objectIdToObjectDefinition)

        elif isinstance(objectDefinition, TypeDescription.File):
            self.convertedValues[objectId] = self.convertFile(objectDefinition)

        elif isinstance(objectDefinition, TypeDescription.RemotePythonObject):
            self.convertedValues[objectId] = self.convertRemotePythonObject(
                objectDefinition)

        elif isinstance(objectDefinition,
                        TypeDescription.BuiltinExceptionInstance):
            self.convertedValues[
                objectId] = self.convertBuiltinExceptionInstance(
                    objectDefinition)

        elif isinstance(objectDefinition, TypeDescription.NamedSingleton):
            self.convertedValues[objectId] = self.convertNamedSingleton(
                objectDefinition)

        elif isinstance(objectDefinition,
                        TypeDescription.WithBlockDescription):
            self.convertedValues[objectId] = self.convertWithBlock(
                objectId, objectDefinition, objectIdToObjectDefinition)

        elif isinstance(objectDefinition, TypeDescription.InstanceMethod):
            self.convertedValues[objectId] = self.convertInstanceMethod(
                objectId, objectDefinition, objectIdToObjectDefinition)

        else:
            assert False, "haven't gotten to this yet %s" % type(
                objectDefinition)
コード例 #5
0
ファイル: Converter.py プロジェクト: ufora/ufora
    def convertStronglyConnectedComponentWithOneNode(self,
                                                     dependencyGraph,
                                                     stronglyConnectedComponent,
                                                     objectIdToObjectDefinition):
        objectId = stronglyConnectedComponent[0]

        objectDefinition = objectIdToObjectDefinition[objectId]

        if TypeDescription.isPrimitive(objectDefinition) or isinstance(objectDefinition, list):
            self.convertedValues[objectId] = self.convertPrimitive(objectDefinition)

        elif isinstance(objectDefinition, (TypeDescription.FunctionDefinition,
                                           TypeDescription.ClassDefinition)):
            if isinstance(objectDefinition, TypeDescription.ClassDefinition):
                for baseId in objectDefinition.baseClassIds:
                    if baseId not in self.convertedValues:
                        self._convert(baseId,
                                      dependencyGraph,
                                      objectIdToObjectDefinition)
                    assert baseId in self.convertedValues
            self.convertStronglyConnectedComponentWithOneFunctionOrClass(
                objectId,
                objectDefinition,
                objectIdToObjectDefinition
                )

        elif isinstance(objectDefinition, TypeDescription.ClassInstanceDescription):
            self.convertClassInstanceDescription(
                objectId,
                objectDefinition
                )

        elif isinstance(objectDefinition, TypeDescription.List):
            self.convertedValues[objectId] = self.convertList(
                objectId,
                self._computeRestrictedGraph(
                    objectId,
                    dependencyGraph
                    ),
                objectIdToObjectDefinition
                )

        elif isinstance(objectDefinition, TypeDescription.Tuple):
            self.convertedValues[objectId] = self.convertTuple(
                objectId,
                self._computeRestrictedGraph(
                    objectId,
                    dependencyGraph
                    ),
                objectIdToObjectDefinition
                )

        elif isinstance(objectDefinition, TypeDescription.Dict):
            self.convertedValues[objectId] = self.convertDict(
                objectId,
                objectDefinition,
                self._computeRestrictedGraph(
                    objectId,
                    dependencyGraph
                    ),
                objectIdToObjectDefinition
                )

        elif isinstance(objectDefinition, TypeDescription.File):
            self.convertedValues[objectId] = self.convertFile(objectDefinition)

        elif isinstance(objectDefinition, TypeDescription.RemotePythonObject):
            self.convertedValues[objectId] = self.convertRemotePythonObject(objectDefinition)

        elif isinstance(objectDefinition, TypeDescription.BuiltinExceptionInstance):
            self.convertedValues[objectId] = self.convertBuiltinExceptionInstance(objectDefinition)

        elif isinstance(objectDefinition, TypeDescription.NamedSingleton):
            self.convertedValues[objectId] = self.convertNamedSingleton(objectDefinition)

        elif isinstance(objectDefinition, TypeDescription.WithBlockDescription):
            self.convertWithBlock(objectId,
                                  objectDefinition,
                                  objectIdToObjectDefinition)

        elif isinstance(objectDefinition, TypeDescription.InstanceMethod):
            self.convertedValues[objectId] = self.convertInstanceMethod(objectId,
                                                                        objectIdToObjectDefinition)

        elif isinstance(objectDefinition, TypeDescription.Unconvertible):
            self.convertUnconvertibleValue(objectId, objectDefinition.module_path)

        elif isinstance(objectDefinition, TypeDescription.PackedHomogenousData):
            self.convertedValues[objectId] = self.convertPackedHomogenousDataAsList(
                    objectId,
                    objectIdToObjectDefinition
                    )
        elif isinstance(objectDefinition, TypeDescription.UnresolvedVarWithPosition):
            self.convertedValues[objectId] = self.convertUnresolvedVarWithPosition(
                objectId,
                objectDefinition
                )
        else:
            assert False, "haven't gotten to this yet %s" % type(objectDefinition)
コード例 #6
0
ファイル: Converter.py プロジェクト: ufora/ufora
 def _convert(self, objectId, dependencyGraph, objectIdToObjectDefinition):
     objectDefinition = objectIdToObjectDefinition[objectId]
     if TypeDescription.isPrimitive(objectDefinition) or isinstance(objectDefinition, list):
         return self.convertPrimitive(objectDefinition)
     elif isinstance(objectDefinition, TypeDescription.RemotePythonObject):
         return self.convertRemotePythonObject(objectDefinition)
     elif isinstance(objectDefinition, TypeDescription.NamedSingleton):
         return self.convertNamedSingleton(objectDefinition)
     elif isinstance(objectDefinition, TypeDescription.BuiltinExceptionInstance):
         return self.convertBuiltinExceptionInstance(
             objectDefinition
             )
     elif isinstance(objectDefinition,
                     (TypeDescription.FunctionDefinition,
                      TypeDescription.ClassDefinition,
                      TypeDescription.ClassInstanceDescription,
                      TypeDescription.InstanceMethod)
                    ):
         return (
             self.convertObjectWithDependencies(
                 objectId,
                 dependencyGraph,
                 objectIdToObjectDefinition
                 )
             )
     elif isinstance(objectDefinition, TypeDescription.List):
         return (
             self.convertList(
                 objectId,
                 dependencyGraph,
                 objectIdToObjectDefinition
                 )
             )
     elif isinstance(objectDefinition, TypeDescription.PackedHomogenousData):
         return (
             self.convertPackedHomogenousDataAsList(
                 objectId,
                 objectIdToObjectDefinition
                 )
             )
     elif isinstance(objectDefinition, TypeDescription.Tuple):
         return (
             self.convertTuple(
                 objectId,
                 dependencyGraph,
                 objectIdToObjectDefinition
                 )
             )
     elif isinstance(objectDefinition, TypeDescription.Dict):
         return (
             self.convertDict(
                 objectId,
                 objectDefinition,
                 dependencyGraph,
                 objectIdToObjectDefinition
                 )
             )
     elif isinstance(objectDefinition, TypeDescription.WithBlockDescription):
         return (
             self.convertObjectWithDependencies(
                 objectId,
                 dependencyGraph,
                 objectIdToObjectDefinition
                 )
             )
     elif isinstance(objectDefinition, TypeDescription.Unconvertible):
         return self.convertUnconvertibleValue(objectId, objectDefinition.module_path)
     elif isinstance(objectDefinition, TypeDescription.UnresolvedVarWithPosition):
         return self.convertUnresolvedVarWithPosition(objectId, objectDefinition)
     else:
         raise pyfora.PythonToForaConversionError(
             "don't know how to convert %s of type %s" % (
                 objectDefinition, type(objectDefinition)
                 )
             )
コード例 #7
0
ファイル: Converter.py プロジェクト: Sandy4321/ufora
    def convertStronglyConnectedComponentWithOneNode(self,
                                                     dependencyGraph,
                                                     stronglyConnectedComponent,
                                                     objectIdToObjectDefinition):
        objectId = stronglyConnectedComponent[0]

        objectDefinition = objectIdToObjectDefinition[objectId]

        if TypeDescription.isPrimitive(objectDefinition) or isinstance(objectDefinition, list):
            self.convertedValues[objectId] = self.convertPrimitive(objectDefinition)

        elif isinstance(objectDefinition, (TypeDescription.FunctionDefinition,
                                           TypeDescription.ClassDefinition)):
            if isinstance(objectDefinition, TypeDescription.ClassDefinition):
                for baseId in objectDefinition.baseClassIds:
                    if baseId not in self.convertedValues:
                        self._convert(baseId,
                                      dependencyGraph,
                                      objectIdToObjectDefinition)
                    assert baseId in self.convertedValues
            self.convertStronglyConnectedComponentWithOneFunctionOrClass(
                objectId,
                objectDefinition,
                objectIdToObjectDefinition
                )

        elif isinstance(objectDefinition, TypeDescription.ClassInstanceDescription):
            self.convertClassInstanceDescription(
                objectId,
                objectDefinition
                )

        elif isinstance(objectDefinition, TypeDescription.List):
            self.convertedValues[objectId] = self.convertList(
                objectId,
                self._computeRestrictedGraph(
                    objectId,
                    dependencyGraph
                    ),
                objectIdToObjectDefinition
                )

        elif isinstance(objectDefinition, TypeDescription.Tuple):
            self.convertedValues[objectId] = self.convertTuple(
                objectId,
                self._computeRestrictedGraph(
                    objectId,
                    dependencyGraph
                    ),
                objectIdToObjectDefinition
                )

        elif isinstance(objectDefinition, TypeDescription.Dict):
            self.convertedValues[objectId] = self.convertDict(
                objectId,
                objectDefinition,
                self._computeRestrictedGraph(
                    objectId,
                    dependencyGraph
                    ),
                objectIdToObjectDefinition
                )

        elif isinstance(objectDefinition, TypeDescription.File):
            self.convertedValues[objectId] = self.convertFile(objectDefinition)

        elif isinstance(objectDefinition, TypeDescription.RemotePythonObject):
            self.convertedValues[objectId] = self.convertRemotePythonObject(objectDefinition)

        elif isinstance(objectDefinition, TypeDescription.BuiltinExceptionInstance):
            self.convertedValues[objectId] = self.convertBuiltinExceptionInstance(objectDefinition)

        elif isinstance(objectDefinition, TypeDescription.NamedSingleton):
            self.convertedValues[objectId] = self.convertNamedSingleton(objectDefinition)

        elif isinstance(objectDefinition, TypeDescription.WithBlockDescription):
            self.convertWithBlock(objectId,
                                  objectDefinition,
                                  objectIdToObjectDefinition)

        elif isinstance(objectDefinition, TypeDescription.InstanceMethod):
            self.convertedValues[objectId] = self.convertInstanceMethod(objectId,
                                                                        objectIdToObjectDefinition)

        elif isinstance(objectDefinition, TypeDescription.Unconvertible):
            self.convertedValues[objectId] = Symbol_unconvertible

        else:
            assert False, "haven't gotten to this yet %s" % type(objectDefinition)
コード例 #8
0
ファイル: Converter.py プロジェクト: Sandy4321/ufora
 def _convert(self, objectId, dependencyGraph, objectIdToObjectDefinition):
     objectDefinition = objectIdToObjectDefinition[objectId]
     if TypeDescription.isPrimitive(objectDefinition) or isinstance(objectDefinition, list):
         return self.convertPrimitive(objectDefinition)
     elif isinstance(objectDefinition, TypeDescription.RemotePythonObject):
         return self.convertRemotePythonObject(objectDefinition)
     elif isinstance(objectDefinition, TypeDescription.NamedSingleton):
         return self.convertNamedSingleton(objectDefinition)
     elif isinstance(objectDefinition, TypeDescription.BuiltinExceptionInstance):
         return self.convertBuiltinExceptionInstance(
             objectDefinition
             )
     elif isinstance(objectDefinition,
                     (TypeDescription.FunctionDefinition,
                      TypeDescription.ClassDefinition,
                      TypeDescription.ClassInstanceDescription,
                      TypeDescription.InstanceMethod)
                    ):
         return (
             self.convertObjectWithDependencies(
                 objectId,
                 dependencyGraph,
                 objectIdToObjectDefinition
                 )
             )
     elif isinstance(objectDefinition, TypeDescription.List):
         return (
             self.convertList(
                 objectId,
                 dependencyGraph,
                 objectIdToObjectDefinition
                 )
             )
     elif isinstance(objectDefinition, TypeDescription.Tuple):
         return (
             self.convertTuple(
                 objectId,
                 dependencyGraph,
                 objectIdToObjectDefinition
                 )
             )
     elif isinstance(objectDefinition, TypeDescription.Dict):
         return (
             self.convertDict(
                 objectId,
                 objectDefinition,
                 dependencyGraph,
                 objectIdToObjectDefinition
                 )
             )
     elif isinstance(objectDefinition, TypeDescription.WithBlockDescription):
         return (
             self.convertObjectWithDependencies(
                 objectId,
                 dependencyGraph,
                 objectIdToObjectDefinition
                 )
             )
     elif isinstance(objectDefinition, TypeDescription.Unconvertible):
         return self.convertUnconvertibleValue(objectId)
     else:
         raise pyfora.PythonToForaConversionError(
             "don't know how to convert %s of type %s" % (
                 objectDefinition, type(objectDefinition)
                 )
             )