Projekt

Obecné

Profil

Stáhnout (1.82 KB) Statistiky
| Větev: | Tag: | Revize:
1
import pprint
2

    
3
import six
4
import typing
5

    
6
from swagger_server import util
7

    
8
T = typing.TypeVar('T')
9

    
10

    
11
class Model(object):
12
    # swaggerTypes: The key is attribute name and the
13
    # value is attribute type.
14
    swagger_types = {}
15

    
16
    # attributeMap: The key is attribute name and the
17
    # value is json key in definition.
18
    attribute_map = {}
19

    
20
    @classmethod
21
    def from_dict(cls: typing.Type[T], dikt) -> T:
22
        """Returns the dict as a model"""
23
        return util.deserialize_model(dikt, cls)
24

    
25
    def to_dict(self):
26
        """Returns the model properties as a dict
27

    
28
        :rtype: dict
29
        """
30
        result = {}
31

    
32
        for attr, _ in six.iteritems(self.swagger_types):
33
            value = getattr(self, attr)
34
            if isinstance(value, list):
35
                result[attr] = list(map(
36
                    lambda x: x.to_dict() if hasattr(x, "to_dict") else x,
37
                    value
38
                ))
39
            elif hasattr(value, "to_dict"):
40
                result[attr] = value.to_dict()
41
            elif isinstance(value, dict):
42
                result[attr] = dict(map(
43
                    lambda item: (item[0], item[1].to_dict())
44
                    if hasattr(item[1], "to_dict") else item,
45
                    value.items()
46
                ))
47
            else:
48
                result[attr] = value
49

    
50
        return result
51

    
52
    def to_str(self):
53
        """Returns the string representation of the model
54

    
55
        :rtype: str
56
        """
57
        return pprint.pformat(self.to_dict())
58

    
59
    def __repr__(self):
60
        """For `print` and `pprint`"""
61
        return self.to_str()
62

    
63
    def __eq__(self, other):
64
        """Returns true if both objects are equal"""
65
        return self.__dict__ == other.__dict__
66

    
67
    def __ne__(self, other):
68
        """Returns true if both objects are not equal"""
69
        return not self == other
(2-2/15)