#  Copyright 2008-2015 Nokia Networks
#  Copyright 2016-     Robot Framework Foundation
#
#  Licensed under the Apache License, Version 2.0 (the "License");
#  you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.

import copy

from robot.utils import py3to2, SetterAwareType, with_metaclass


@py3to2
class ModelObject(with_metaclass(SetterAwareType, object)):
    repr_args = ()
    __slots__ = []

    def config(self, **attributes):
        """Configure model object with given attributes.

        ``obj.config(name='Example', doc='Something')`` is equivalent to setting
        ``obj.name = 'Example'`` and ``obj.doc = 'Something'``.

        New in Robot Framework 4.0.
        """
        for name in attributes:
            setattr(self, name, attributes[name])
        return self

    def copy(self, **attributes):
        """Return shallow copy of this object.

        :param attributes: Attributes to be set for the returned copy
            automatically. For example, ``test.copy(name='New name')``.

        See also :meth:`deepcopy`. The difference between these two is the same
        as with the standard ``copy.copy`` and ``copy.deepcopy`` functions
        that these methods also use internally.

        New in Robot Framework 3.0.1.
        """
        copied = copy.copy(self)
        for name in attributes:
            setattr(copied, name, attributes[name])
        return copied

    def deepcopy(self, **attributes):
        """Return deep copy of this object.

        :param attributes: Attributes to be set for the returned copy
            automatically. For example, ``test.deepcopy(name='New name')``.

        See also :meth:`copy`. The difference between these two is the same
        as with the standard ``copy.copy`` and ``copy.deepcopy`` functions
        that these methods also use internally.

        New in Robot Framework 3.0.1.
        """
        copied = copy.deepcopy(self)
        for name in attributes:
            setattr(copied, name, attributes[name])
        return copied

    def __repr__(self):
        args = ['%s=%r' % (n, getattr(self, n)) for n in self.repr_args]
        module = type(self).__module__.split('.')
        if len(module) > 1 and module[0] == 'robot':
            module = module[:2]
        return '%s.%s(%s)' % ('.'.join(module), type(self).__name__, ', '.join(args))

    def __setstate__(self, state):
        """Customize attribute updating when using the `copy` module.

        This may not be needed in the future if we fix the mess we have with
        different timeout types.
        """
        # We have __slots__ so state is always a two-tuple.
        # Refer to: https://www.python.org/dev/peps/pep-0307
        dictstate, slotstate = state
        if dictstate is not None:
            self.__dict__.update(dictstate)
        for name in slotstate:
            # If attribute is defined in __slots__ and overridden by @setter
            # (this is the case at least with 'timeout' of 'running.TestCase')
            # we must not set the "real" attribute value because that would run
            # the setter method and that would recreate the object when it
            # should not. With timeouts recreating object using the object
            # itself would also totally fail.
            setter_name = '_setter__' + name
            if setter_name not in slotstate:
                setattr(self, name, slotstate[name])

@@ -2779,1075 +2779,4 @@
 s))%0A
-%0A    def __setstate__(self, state):%0A        %22%22%22Customize attribute updating when using the %60copy%60 module.%0A%0A        This may not be needed in the future if we fix the mess we have with%0A        different timeout types.%0A        %22%22%22%0A        # We have __slots__ so state is always a two-tuple.%0A        # Refer to: https://www.python.org/dev/peps/pep-0307%0A        dictstate, slotstate = state%0A        if dictstate is not None:%0A            self.__dict__.update(dictstate)%0A        for name in slotstate:%0A            # If attribute is defined in __slots__ and overridden by @setter%0A            # (this is the case at least with 'timeout' of 'running.TestCase')%0A            # we must not set the %22real%22 attribute value because that would run%0A            # the setter method and that would recreate the object when it%0A            # should not. With timeouts recreating object using the object%0A            # itself would also totally fail.%0A            setter_name = '_setter__' + name%0A            if setter_name not in slotstate:%0A                setattr(self, name, slotstate%5Bname%5D)%0A

Remove nowadays unnecassary code related to copy and deepcopy.