Robot Framework Integrated Development Environment (RIDE)
modelobject.py
Go to the documentation of this file.
1 # Copyright 2008-2015 Nokia Networks
2 # Copyright 2016- Robot Framework Foundation
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 
16 import copy
17 
18 from robotide.lib.robot.utils import SetterAwareType, py2to3, with_metaclass
19 
20 
21 @py2to3
22 class ModelObject(with_metaclass(SetterAwareType, object)):
23  __slots__ = []
24 
25 
36  def copy(self, **attributes):
37  copied = copy.copy(self)
38  for name in attributes:
39  setattr(copied, name, attributes[name])
40  return copied
41 
42 
53  def deepcopy(self, **attributes):
54  copied = copy.deepcopy(self)
55  for name in attributes:
56  setattr(copied, name, attributes[name])
57  return copied
58 
59  def __unicode__(self):
60  return self.name
61 
62  def __repr__(self):
63  return repr(str(self))
64 
65 
70  def __setstate__(self, state):
71  # We have __slots__ so state is always a two-tuple.
72  # Refer to: https://www.python.org/dev/peps/pep-0307
73  dictstate, slotstate = state
74  if dictstate is not None:
75  self.__dict__.update(dictstate)
76  for name in slotstate:
77  # If attribute is defined in __slots__ and overridden by @setter
78  # (this is the case at least with 'timeout' of 'running.TestCase')
79  # we must not set the "real" attribute value because that would run
80  # the setter method and that would recreate the object when it
81  # should not. With timeouts recreating object using the object
82  # itself would also totally fail.
83  setter_name = '_setter__' + name
84  if setter_name not in slotstate:
85  setattr(self, name, slotstate[name])
def __setstate__(self, state)
Customize attribute updating when using the copy module.
Definition: modelobject.py:70
def deepcopy(self, **attributes)
Return deep copy of this object.
Definition: modelobject.py:53
def copy(self, **attributes)
Return shallow copy of this object.
Definition: modelobject.py:36
def with_metaclass(meta, *bases)
Create a base class with a metaclass.
Definition: compat.py:46