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.data_type import DataType
16
18 """
19 Contains a hash of names to Property objects. An instance of this class is
20 returned by DeviceApi.properties.
21 """
22
23 - def contains(self, property_name, value_to_check):
24 """
25 Checks whether the properties set has the given pair of property and value.
26 @param property_name: is a String with the property name.
27 @param value_to_check: is a Value to check.
28 It returs a bool value.
29 """
30
31 if property_name is None or value_to_check is None:
32 return False
33
34 if property_name in self:
35
36 if self[property_name].value == value_to_check:
37 return True
38
39 if self[property_name].data_type_id == DataType.BOOLEAN:
40
41 if (value_to_check == 'true' or value_to_check == 1 or
42 value_to_check == '1' or value_to_check == True):
43 return bool(self[property_name]) == True
44
45 if (value_to_check == 'false' or value_to_check == 0 or
46 value_to_check == '0' or value_to_check == False):
47 return bool(self[property_name]) == False
48
49 if self[property_name].data_type_id == DataType.INTEGER:
50 try:
51 value_to_check_int = int(value_to_check)
52 return int(self[property_name]) == value_to_check_int
53 except:
54 return False
55
56 return False
57
58 - def get(self, property_name):
59 """
60 Gets the value of the given property identified by its name.
61 @param property_name: is a String with the property_name.
62 It returns Property value or None if the property does not exist.
63 """
64 if property_name in self:
65 return self[property_name]
66 return None
67