6 from utils.error_handling
import Warning
7 from utils.io
import ENCODING
10 """! @brief Check that attribute value is of specified type.
11 @param val The attribute value to check.
12 @param typ The allowed Python type(s): simple, or Python set or list.
13 @param msg The message to display if value is not of correct type.
16 if type(typ)
is set
or type(typ)
is list:
17 if type(val)
not in typ:
20 elif type(val)
is not typ:
24 """! @brief Check that attribute value is in specified range.
25 @param value The attribute value to check.
26 @param range A Python set giving the range of allowed values.
27 @param msg The message to display if value is out-of-range.
28 @param mapping A Python dictionary giving mapping between values (i.e. from MDF to LMF)
29 @return The value to set, or None if out-of-range.
32 if value
not in range:
34 if mapping
is not None:
36 converted_value = mapping[value]
41 return converted_value
49 """! @brief Verify that date format is composed as follows: YYYY-MM-DD (ISO 8601).
50 If not, display a Warning message.
51 @param date Date to check.
54 if not re.match(
"^\d{4}-[01]\d-[0-3]\d$", date):
55 print Warning(
"Date must be formatted as follows: YYYY-MM-DD (given date is %s)" % date.encode(ENCODING))
58 """! @brief Verify that time format is composed as follows: THH:MM:SS,MSMS (ISO 8601: 'T' for Time).
59 If not, display a Warning message.
60 @param time Time to check.
63 if not re.match(
"^T[0-2]\d:[0-5]\d:[0-5]\d(\,\d+|)$", time):
64 print Warning(
"Time must be formatted as follows: THH:MM:SS,MSMS (given time is %s)" % time.encode(ENCODING))
67 """! @brief Verify that duration format is composed as follows: PTxxHxxMxxS (ISO 8601: 'P' for Period).
68 If not, display a Warning message.
69 @param duration Duration to check.
72 if not re.match(
"^PT[0-2]\dH[0-5]\dM[0-5]\dS$", duration):
73 print Warning(
"Duration must be formatted as follows: PTxxHxxMxxS (given duration is %s)" % duration.encode(ENCODING))
def check_attr_type
Check that attribute value is of specified type.
def check_date_format
Verify that date format is composed as follows: YYYY-MM-DD (ISO 8601).
def check_attr_range
Check that attribute value is in specified range.
def check_time_format
Verify that time format is composed as follows: THH:MM:SS,MSMS (ISO 8601: 'T' for Time)...
def check_duration_format
Verify that duration format is composed as follows: PTxxHxxMxxS (ISO 8601: 'P' for Period)...