Files
deb-python-tosca-parser/heat-translator/utils.py
Sahdev Zala 7fa547a3c1 First code drop on data modeling.
This is the first code drop for the project. Covers basis project structure
and reading tosca profile into a memory model.
2014-02-24 16:58:25 -06:00

26 lines
684 B
Python

import numbers
def validate_integer(value):
if not isinstance(value, (int, long)):
raise TypeError('value is not an integer for %s' %value)
return validate_number(value)
def validate_number(value):
return str_to_num(value)
def validate_string(value):
if not isinstance(value, basestring):
raise ValueError(_('Value must be a string'))
return value
def validate_list(self, value):
pass
def str_to_num(value):
'''Convert a string representation of a number into a numeric type.'''
if isinstance(value, numbers.Number):
return value
try:
return int(value)
except ValueError:
return float(value)