Esempio n. 1
0
    def detail(worker: BaseWorker, protocol_tuple: tuple) -> "Protocol":
        """This function reconstructs a Protocol object given its attributes in the form of a tuple.
        Args:
            worker: the worker doing the deserialization
            protocol_tuple: a tuple holding the attributes of the Protocol
        Returns:
            protocol: a Protocol object
        """

        id, tags, description, plans_reference, workers_resolved = map(
            lambda o: sy.serde._detail(worker, o), protocol_tuple
        )

        plans = []
        for owner_id, plan_id in plans_reference:
            if workers_resolved:
                plan_owner = worker.get_worker(owner_id, fail_hard=True)
                plan_pointer = worker.request_search(plan_id, location=plan_owner)[0]
                worker.register_obj(plan_pointer)
                plans.append((plan_owner, plan_pointer))
            else:
                try:
                    plan_owner = worker.get_worker(owner_id, fail_hard=True)
                    plan_pointer = worker.request_search(plan_id, location=plan_owner)[0]
                    plan = plan_pointer.get()
                except WorkerNotFoundException:
                    plan = worker.get_obj(plan_id)
                plans.append((worker.id, plan))

        protocol = sy.Protocol(plans=plans, id=id, owner=worker, tags=tags, description=description)

        return protocol
Esempio n. 2
0
    def detail(worker: BaseWorker, simple_obj):
        """Create an object of type DocPointer from the reduced representation in `simple_obj`.

        Args:
            worker (BaseWorker): The worker on which the new DocPointer object is to be created.
            simple_obj (tuple): A tuple resulting from the serialized then deserialized returned tuple
                from the `_simplify` static method above.

        Returns:
            DocPointer: a DocPointer object, pointing to a Doc object
        """

        # Get the typle elements
        (
            location_id,
            id_at_location,
            id,
            garbage_collect_data,
            tags,
            description,
        ) = simple_obj

        # Unpickle
        location_id = pickle.loads(location_id)
        tags = [pickle.loads(tag) for tag in tags] if tags else None
        description = pickle.loads(description)

        # Get the worker `location` on which lives the pointed-to Doc object
        location = worker.get_worker(id_or_worker=location_id)

        # Create a DocPointer object
        doc_pointer = DocPointer(
            location=location,
            id_at_location=id_at_location,
            owner=worker,
            id=id,
            garbage_collect_data=garbage_collect_data,
            tags=tags,
            description=description,
        )

        return doc_pointer