def to_dbtext(text):
  """Helper to turn a string into a db.Text instance.

  Args:
    text: a string.

  Returns:
    A db.Text instance.
  """
  if isinstance(text, unicode):
    # A TypeError is raised if text is unicode and an encoding is given.
    return db.Text(text)
  else:
    try:
      return db.Text(text, encoding='utf-8')
    except __HOLE__:
      return db.Text(text, encoding='latin-1')
dataset/ETHPy150Open rietveld-codereview/rietveld/codereview/utils.py/to_dbtext