def serialize_instance(instance):
attr_count = <NUM_LIT:0><EOL>metaclass = xtuml.get_metaclass(instance)<EOL>s = '<STR_LIT>' % metaclass.kind<EOL>for name, ty in metaclass.attributes:<EOL><INDENT>value = getattr(instance, name)<EOL>s += '<STR_LIT>'<EOL>s += serialize_value(value, ty)<EOL>attr_count += <NUM_LIT:1><EOL>if attr_count < len(metaclass.attributes):<EOL><INDENT>s += '<STR_LIT>' % (name, ty)<EOL><DEDENT>else:<EOL><INDENT>s += '<STR_LIT>' % (name, ty)<EOL><DEDENT><DEDENT>s += '<STR_LIT>'<EOL>return s<EOL>
Serialize an *instance* from a metamodel.