import six


def ported_string(raw_data, encoding='utf-8', errors='ignore'):
    """
    Give as input raw data and output a str in Python 3
    and unicode in Python 2.

    Args:
        raw_data: Python 2 str, Python 3 bytes or str to porting
        encoding: string giving the name of an encoding
        errors: his specifies the treatment of characters
            which are invalid in the input encoding

    Returns:
        str (Python 3) or unicode (Python 2)
    """

    if not raw_data:
        return six.text_type()

    if isinstance(raw_data, six.text_type):
        return raw_data

    if six.PY2:
        try:
            return six.text_type(raw_data, encoding, errors)
        except LookupError:
            return six.text_type(raw_data, "utf-8", errors)

    if six.PY3:
        try:
            return six.text_type(raw_data, encoding)
        except (LookupError, UnicodeDecodeError):
            return six.text_type(raw_data, "utf-8", errors)