6 Copyright (C) 2009-2010 8 RT-Synthesis Research Group 9 Intelligent Systems Research Institute, 10 National Institute of Advanced Industrial Science and Technology (AIST), 13 Licensed under the Eclipse Public License -v 1.0 (EPL) 14 http://www.opensource.org/licenses/eclipse-1.0.txt 22 __version__ =
'$Revision: $' 30 from rtsprofile
import RTS_EXT_NS, RTS_EXT_NS_S
38 date = date.split(
'T')
39 t = time.strptime(date[0],
'%Y-%m-%d')
43 t = time.strptime(date[1],
'%H:%M:%S')
47 return {
'year': year,
'month': month,
'day': day,
'hour': hour,
48 'minute': min,
'second': sec}
51 for c
in node.childNodes:
54 if c.prefix == prefix:
57 if c.localName == local_name:
66 '''Add indentation to a string. 68 Replaces all new lines in the string with a new line followed by the 69 specified number of spaces, and adds the specified number of spaces to the 73 indent =
' '.ljust(num_spaces)
74 return indent + re.sub(
'\n',
'\n' + indent, string)
78 name = node.getAttributeNS(RTS_EXT_NS,
'name')
79 value = node.getAttributeNS(RTS_EXT_NS,
'value')
87 element.setAttributeNS(RTS_EXT_NS, RTS_EXT_NS_S +
'name', name)
89 element.setAttributeNS(RTS_EXT_NS, RTS_EXT_NS_S +
'value', value)
93 '''Validates that an attribute meets expectations. 95 This function will check if the given attribute value matches a necessary 96 type and/or is not None, an empty string, an empty list, etc. It will raise 97 suitable exceptions on validation failure. 99 @param attr The value to validate. 100 @param name The attribute name to use in exceptions. 101 @param expected_type The type the value must be. If None, no check is 102 performed. If a list, attr must match one type in the list. 103 @param required If the value must not be empty, e.g. not an empty string. 104 @raises InvalidTypeError 105 @raises RequiredAttributeError 109 if type(expected_type) == list:
115 if required
and not attr:
124 for et
in expected_types:
125 if type(et) == type
and type(value) == et:
127 elif type(et) == new.classobj
and \
128 value.__class__ == et:
def date_to_dict(date)
Public API functions.
def properties_to_xml(element, name, value=None)
def parse_properties_xml(node)
def validate_attribute(attr, name, expected_type=None, required=False)
def get_direct_child_elements_xml(node, prefix=None, local_name=None)
def indent_string(string, num_spaces=2)
def _check_type(value, expected_types)
Private functions.