Example #1
0
    def __copy__(self):
        """Copy method for ParameterNode, invoked by copy.copy(parameter_node).
        """
        rv = self.__reduce_ex__(4)
        self_copy = _reconstruct(self, None, *rv)

        self_copy.__deepcopy__ = partial(__deepcopy__, self_copy)
        self_copy.parent = None  # By default no parent for copied nodes

        self_copy.parameters = {}
        for parameter_name, parameter in self.parameters.items():
            parameter_copy = copy(parameter)
            self_copy.parameters[parameter_name] = parameter_copy
            parameter_copy.parent = self_copy

        # Attach parameter decorators, done in a second loop because the
        # decorators may call parameters, and so all parameters must exist
        for parameter_name, parameter_decorators in self._parameter_decorators.items():
            parameter = self_copy.parameters[parameter_name]
            self_copy._attach_parameter_decorators(parameter, parameter_decorators)

        self_copy.parameter_nodes = {}
        for node_name, parameter_node in self_copy.parameter_nodes.items():
            parameter_node_copy = copy(parameter_node)
            self_copy.parameter_nodes[node_name] = parameter_node_copy
            parameter_node_copy.parent = self_copy

        return self_copy
    def __deepcopy__(self, memo):
        """
        The RLock is unsafe to deepcopy as it is in use while copying.
        Mark the RLock as having been already copied.
        This workaround was developed by debugging through the deepcopy process
        and finding the correct method to invoke for this class.
        """

        # Mark the RLock as having been copied already
        memo[id(self.lock)] = None

        # Can no longer call deepcopy(self) or it will result in an infinite
        # loop. The following calls are made by deepcopy if no __deepcopy__
        # function is defined for this class. It would be great if there was
        # some kind of one-time bypass of this function for performing deep
        # copies.
        # TODO hack getattr to count recursive calls into __deepcopy__ and
        # return None after it has already been called
        rv = self.__reduce_ex__(2)
        selfcopy = copy._reconstruct(self, rv, 1, memo)

        # Add a new RLock into the copy
        selfcopy.lock = threading.RLock()

        return selfcopy
Example #3
0
 def __copy__(self):
     rv = self.__reduce_ex__(4)
     if isinstance(rv, str):
         return self
     obj = copy._reconstruct(self, None, *rv)
     obj.db = self.db
     return obj
Example #4
0
    def __copy__(self):
        """
        Override to include variables list on shallow copy.
        See copy.copy
        """
        cls = type(self)

        copier = copy._copy_dispatch.get(cls)
        if copier:
            newone = copier(self)
        else:    
            reductor = copy.dispatch_table.get(cls)
            if reductor:
                rv = reductor(self)
            else:
                reductor = getattr(self, "__reduce_ex__", None)
                if reductor:
                    rv = reductor(2)
                else:
                    reductor = getattr(self, "__reduce__", None)
                    if reductor:
                        rv = reductor()
                    else:
                        raise Exception("un(shallow)copyable object of type %s" % cls)
        
            newone = copy._reconstruct(self, rv, 0)

        newone.variables = self.variables[:]
        return newone
Example #5
0
 def __deepcopy__(self, memo):
     rv = super(Solution, self).__reduce_ex__(4)
     i = id(self.stopper)
     if i not in memo:
         memo[i] = threading.Event()
     y = _reconstruct(self, rv, 1, memo)
     y._update_methods()
     return y
Example #6
0
    def __copy__(self):
        """
        EXAMPLES::

            sage: d = DynkinDiagram(["A", 3])
            sage: type(copy(d))
            <class 'sage.combinat.root_system.dynkin_diagram.DynkinDiagram_class'>
        """
        import copy
        # we have to go back to the generic copy method because the DiGraph one returns a DiGraph, not a DynkinDiagram
        return copy._reconstruct(self,self.__reduce_ex__(2),0)
Example #7
0
 def __copy__(self):
     """
     EXAMPLES::
     
         sage: d = DynkinDiagram(["A", 3])
         sage: type(copy(d))
         <class 'sage.combinat.root_system.dynkin_diagram.DynkinDiagram_class'>
     """
     import copy 
     # we have to go back to the generic copy method because the DiGraph one returns a DiGraph, not a DynkinDiagram
     return copy._reconstruct(self,self.__reduce_ex__(2),0)
Example #8
0
 def update_event(self, inp=-1):
     self.set_output_val(0, copy._reconstruct(self.input(0), self.input(1), self.input(2), self.input(3), self.input(4), self.input(5), self.input(6), self.input(7)))