def _GetFilterFromArg(filter_arg, messages):
  """Gets a Filter message object from a filter phrase."""
  if not filter_arg:
    return None
  flag_event_types_to_enum = {
      'upgradeevent':
          messages.Filter.EventTypeValueListEntryValuesEnum.UPGRADE_EVENT,
      'upgradeavailableevent':
          messages.Filter.EventTypeValueListEntryValuesEnum
          .UPGRADE_AVAILABLE_EVENT,
      'securitybulletinevent':
          messages.Filter.EventTypeValueListEntryValuesEnum
          .SECURITY_BULLETIN_EVENT
  }
  to_return = messages.Filter()
  for event_type in filter_arg.split('|'):
    event_type = event_type.lower()
    if flag_event_types_to_enum[event_type]:
      to_return.eventType.append(flag_event_types_to_enum[event_type])
  return to_return