def unicode_str(content, encoding=None, errors=None):
    """Try to decode ``content``` into unicode given an
    ``encoding``. By default it will try to decode using utf-8.

    If the input is already a unicode string, it will be returned
    unchanged.

    Args:
        ``content``: a basestring.
        ``encoding``: an encoding to use to decode ``content``.
        ``errors``: (optional) specifies the response when the input
           string can't be converted according to the encoding.
           Legal values for this argument:
               'strict': Return None. This is the default behavior.
               'replace': replace with U+FFFD, 'REPLACEMENT CHARACTER'
               'ignore': just leave the character out of the result

    Returns:
        Unicode representation of ``content``.
    """
    if not encoding or encoding == 'undefined':
        encoding = 'utf-8'
    errors = errors or 'strict'
    try:
        if not isinstance(content, unicode):
            content = unicode(content, encoding, errors=errors)
    except (UnicodeDecodeError, LookupError, __HOLE__):
        content = None
    return content
dataset/ETHPy150Open pinterest/kingpin/kingpin/manageddata/manageddata_utils.py/unicode_str