def ParseEnum(field, value):
 enum_descriptor = field.enum_type
 try:
  number = int(value, 0)
 except ValueError:
  enum_value = enum_descriptor.values_by_name.get(value, None)
  if (enum_value is None):
   raise ValueError(('Enum type "%s" has no value named %s.' % (enum_descriptor.full_name, value)))
 else:
  enum_value = enum_descriptor.values_by_number.get(number, None)
  if (enum_value is None):
   raise ValueError(('Enum type "%s" has no value with number %d.' % (enum_descriptor.full_name, number)))
 return enum_value.number

def ParseEnum ( field , value ) : enum_descriptor = field . enum_type try : number = int ( value , 0 ) except ValueError : enum_value = enum_descriptor . values_by_name . get ( value , None ) if ( enum_value is None ) : raise ValueError ( ( 'Enum type "%s" has no value named %s.' % ( enum_descriptor . full_name , value ) ) ) else : enum_value = enum_descriptor . values_by_number . get ( number , None ) if ( enum_value is None ) : raise ValueError ( ( 'Enum type "%s" has no value with number %d.' % ( enum_descriptor . full_name , number ) ) ) return enum_value . number
parse an enum value .