source: src/mapservice/src-gen/openapi_server/models/base_model_.py@ be25db1

debian/bullseye
Last change on this file since be25db1 was 5e4cb73, checked in by Joachim Langenbach <joachim.langenbach@…>, 8 years ago

Refactored mapservice

  • mapservice is a connexion python webservice with openapi defined api
  • mapservice-webclient is a angular app, consuming the openapi webservice mapservice
  • Property mode set to 100644
File size: 1.8 KB
Line 
1import pprint
2
3import six
4import typing
5
6from openapi_server import util
7
8T = typing.TypeVar('T')
9
10
11class Model(object):
12 # openapiTypes: The key is attribute name and the
13 # value is attribute type.
14 openapi_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.openapi_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
Note: See TracBrowser for help on using the repository browser.