def _message_to_entity(msg, modelclass):
ent = modelclass()<EOL>for prop_name, prop in modelclass._properties.iteritems():<EOL><INDENT>if prop._code_name == '<STR_LIT>':  <EOL><INDENT>continue  <EOL><DEDENT>value = getattr(msg, prop_name)<EOL>if value is not None and isinstance(prop, model.StructuredProperty):<EOL><INDENT>if prop._repeated:<EOL><INDENT>value = [_message_to_entity(v, prop._modelclass) for v in value]<EOL><DEDENT>else:<EOL><INDENT>value = _message_to_entity(value, prop._modelclass)<EOL><DEDENT><DEDENT>setattr(ent, prop_name, value)<EOL><DEDENT>return ent<EOL>
Recursive helper for _to_base_type() to convert a message to an entity.

    Args:
      msg: A Message instance.
      modelclass: A Model subclass.

    Returns:
      An instance of modelclass.