1
2
3 """
4 @copyright:
5 Copyright (c) 2014 by mTLD Top Level Domain Limited. All rights reserved.\n
6 Portions copyright (c) 2008 by Argo Interactive Limited.\n
7 Portions copyright (c) 2008 by Nokia Inc.\n
8 Portions copyright (c) 2008 by Telecom Italia Mobile S.p.A.\n
9 Portions copyright (c) 2008 by Volantis Systems Limited.\n
10 Portions copyright (c) 2002-2008 by Andreas Staeding.\n
11 Portions copyright (c) 2008 by Zandan.\n
12 @author: dotMobi
13 """
14
15 from mobi.mtld.da.exception.incorrect_property_type_exception import IncorrectPropertyTypeException
16 from mobi.mtld.da.data_type import DataType
19 """
20 Contains a property value and data type id. The value can be fetched as a
21 generic Object or one of the convenience str(), int(), bool() methods can be
22 used to get the value in a specific type.
23 """
24
25 __value = ''
26 __data_type_id = 0
27 __data_type_name = 'Boolean'
28
77
78 @property
81
82 @property
85
87 """
88 Get data type name.
89 It returns a String with the data type name
90 """
91 return self.__data_type_name
92
94 """
95 Gets a set of possible values for this property. This is typically only
96 used when it is known that a given property name can have multiple
97 possible values. All items in the set will have the same data type.
98 It returns the array value of the property
99 """
100 if isinstance(self.__value, basestring) and self.__value.contains(","):
101 values = self.__value.split(",")
102 else:
103 values = self.__value
104
105 class iterator(object):
106 def __init__(self, obj):
107 self.obj = obj
108 self.index = -1
109 def __iter__(self):
110 return self
111 def next(self):
112 if self.index < len(values) - 1:
113 self.index += 1
114 return self.obj[self.index]
115 else:
116 raise StopIteration
117 return iterator(self.__value)
118
119
121 """
122 Get the value of the property as a boolean (Python 3.x)
123 """
124 return self.__nonzero__()
125
127
128 if(self.__data_type_id != DataType.BOOLEAN):
129 raise IncorrectPropertyTypeException('Property is not convertible to a ' +
130 'boolean')
131
132 return self.__value == 1 or self.__value == '1' or self.__value is True
133
144
146 """
147 Gets the value of the property as string. If a property has multiple possible
148 values then the values are concatenated with a comma.
149 """
150 if isinstance(self.__value, list):
151 for i in range(0, len(self.__value)):
152 if isinstance(self.__value[i], bytes):
153 self.__value[i] = self.__value[i].decode("utf-8")
154 return ",".join(self.__value)
155
156 if isinstance(self.__value, bytes):
157 try:
158 self.__value = self.__value.decode("utf-8")
159 except:
160 pass
161
162 return str(self.__value)
163
165 """
166 Compare two instances of this class.
167 If both have equal values and data type then returns true.
168 """
169 return (type(self) == type(other) and
170 self.data_typeName == other.data_type() and
171 self.__value == other.value)
172
174 """
175 Opposite to __eq__()
176 """
177 return (type(self) != type(other) or
178 self.data_typeName != other.data_type() or
179 self.__value != other.value)
180