def ancestor(self, class_keyword):
     """Find the first ancestor that matches the provided class_keyword
     Arguments:
         class_keyword[str]: A class keyword matching the type of class wanted
     """
     request = PdmObject_pb2.PdmParentObjectRequest(
         object=self._pb2_object, parent_keyword=class_keyword)
     return PdmObject(self._pdm_object_stub.GetAncestorPdmObject(request),
                      self._channel, self._project)
示例#2
0
def ancestor(self, class_definition):
    """Find the first ancestor that matches the provided class_keyword
    Arguments:
        class_definition[class]: A class definition matching the type of class wanted
    """
    assert(inspect.isclass(class_definition))

    class_keyword = class_definition.__name__

    request = PdmObject_pb2.PdmParentObjectRequest(
        object=self._pb2_object, parent_keyword=class_keyword)
    try:
        pb2_object = self._pdm_object_stub.GetAncestorPdmObject(request)
        child_class_definition = class_from_keyword(pb2_object.class_keyword)

        if child_class_definition is None:
            child_class_definition = class_definition

        pdm_object = child_class_definition(pb2_object=pb2_object, channel=self.channel())
        return pdm_object
    except grpc.RpcError as e:
        if e.code() == grpc.StatusCode.NOT_FOUND:
            return None
        raise e