<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _copy_attachment(self, name, data, mimetype, mfg_event):
 """Copies an attachment to mfg_event."""

    attachment = mfg_event.attachment.add()
    attachment.name = name
    if isinstance(data, unicode):
      data = data.encode('utf8')
    attachment.value_binary = data
    if mimetype in test_runs_converter.MIMETYPE_MAP:
      attachment.type = test_runs_converter.MIMETYPE_MAP[mimetype]
    elif mimetype == test_runs_pb2.MULTIDIM_JSON:
      attachment.type = mimetype
    else:
      attachment.type = test_runs_pb2.BINARY