def WidenText(self, text, encoding):
    """ Widen a piece of arbitrary text """
    if type(text) != types.StringType:
      return text

    # Try the passed in preference
    if encoding:
      try:
        result = unicode(text, encoding)
        if not encoding in self._learned:
          self._learned.append(encoding)
        return result
      except UnicodeError:
        pass
      except LookupError:
        output.Warn('Unknown encoding: %s' % encoding)

    # Try the user preference
    if self._user:
      try:
        return unicode(text, self._user)
      except UnicodeError:
        pass
      except LookupError:
        temp = self._user
        self._user = None
        output.Warn(temp % 'Unknown default_encoding: %s')

    # Look through learned defaults, knock any failing ones out of the list
    while self._learned:
      try:
        return unicode(text, self._learned[0])
      except:
        del self._learned[0]

    # When all other defaults are exhausted, use UTF-8
    try:
      return unicode(text, ENC_UTF8)
    except UnicodeError:
      pass

    # Getting here means it wasn't UTF-8 and we had no working default.
    # We really don't have anything "right" we can do anymore.
    output.Warn('Unrecognized encoding in text: %s' % text)
    if not self._user:
      output.Warn('You may need to set a default_encoding in your '
                  'configuration file.')
    return text.decode(ENC_ASCII, 'ignore')
  #end def WidenText
#end class Encoder
dataset/ETHPy150Open benoitc/gunicorn/docs/sitemap_gen.py/Encoder.WidenText/swapped operands of `%`