def _get(result, field, mandatory=False, default="", transform=lambda x: x):
  """Retrieve a given field if available, return default or exception otherwise. Result may be manipulated by transformation function"""
  if field in result:
    return transform(result[field])
  else:
    if mandatory:
      raise KeyError("Field '"+field+"' not found in dictionary")
    else:
      return default