コード例 #1
0
ファイル: datamodel.py プロジェクト: yfyf510/openmediavault
 def property_convert(self, name, value):
     """
     Convert the given value into the type which is declared in the
     property schema at the specified path. The original value is returned
     when the property type can not be processed, e.g. 'any', 'array',
     'object' or 'null'.
     :param name: The path of the property, e.g. "aaa.bbb.ccc".
     :param value: The value to convert.
     :returns: The converted value.
     """
     prop_schema = self.schema.get_by_path(name)
     if isinstance(prop_schema['type'], list):
         raise openmediavault.json.SchemaException(
             "The attribute 'type' must not be an array at '%s'." % name)
     if "boolean" == prop_schema['type']:
         result = openmediavault.bool(value)
     elif "integer" == prop_schema['type']:
         result = int(value)
     elif prop_schema['type'] in ["number", "double", "float"]:
         result = float(value)
     elif "string" == prop_schema['type']:
         result = str(value)
     else:
         result = value
     return result
コード例 #2
0
ファイル: datamodel.py プロジェクト: succesor/omv
 def property_convert(self, name, value):
     """
     Convert the given value into the type which is declared in the
     property schema at the specified path. The original value is returned
     when the property type can not be processed, e.g. 'any', 'array',
     'object' or 'null'.
     :param name: The path of the property, e.g. "aaa.bbb.ccc".
     :param value: The value to convert.
     :returns: The converted value.
     """
     prop_schema = self.schema.get_by_path(name)
     if isinstance(prop_schema['type'], list):
         raise openmediavault.json.SchemaException(
             "The attribute 'type' must not be an array at '%s'." % name)
     try:
         if "boolean" == prop_schema['type']:
             result = openmediavault.bool(value)
         elif "integer" == prop_schema['type']:
             result = int(value)
         elif prop_schema['type'] in ['number', 'double', 'float']:
             result = float(value)
         elif "string" == prop_schema['type']:
             result = str(value)
         else:
             result = value
     except ValueError as e:
         # Re-raise the exception, but with a more meaningful message.
         raise ValueError("Failed to convert property '{}': {}".format(
             name, str(e)))
     return result
コード例 #3
0
 def property_convert(self, name, value):
     """
     Convert the given value into the type which is declared in the
     property schema at the specified path. The original value is returned
     when the property type can not be processed, e.g. 'any', 'array',
     'object' or 'null'.
     :param name: The path of the property, e.g. "aaa.bbb.ccc".
     :param value: The value to convert.
     :returns: The converted value.
     """
     prop_schema = self.schema.get_by_path(name)
     if isinstance(prop_schema['type'], list):
         raise openmediavault.json.SchemaException(
             "The attribute 'type' must not be an array at '%s'." % name
         )
     if "boolean" == prop_schema['type']:
         result = openmediavault.bool(value)
     elif "integer" == prop_schema['type']:
         result = int(value)
     elif prop_schema['type'] in ["number", "double", "float"]:
         result = float(value)
     elif "string" == prop_schema['type']:
         result = str(value)
     else:
         result = value
     return result
コード例 #4
0
ファイル: settings.py プロジェクト: zjsxwc/openmediavault
 def get_bool(key, default=None):
     value = __class__.get(key, default)
     return openmediavault.bool(value)
コード例 #5
0
 def test_bool_no(self):
     value = openmediavault.bool("no")
     self.assertEqual(value, False)
コード例 #6
0
 def test_bool_yes(self):
     value = openmediavault.bool("yes")
     self.assertEqual(value, True)
コード例 #7
0
 def get_bool(key, default=None):
     value = __class__.get(key, default)
     return omv.bool(value)
コード例 #8
0
 def get_bool(key, default=None):
     value = Environment.get(key, default)
     return openmediavault.bool(value)
コード例 #9
0
	def test_bool_no(self):
		value = openmediavault.bool("no")
		self.assertEqual(value, False)
コード例 #10
0
	def test_bool_yes(self):
		value = openmediavault.bool("yes")
		self.assertEqual(value, True)