def encode(string, encodings=None):
    if not PY2 and isinstance(string, bytes):
        return string

    if PY2 and isinstance(string, str):
        return string

    if encodings is None:
        encodings = ['utf-8', 'latin1', 'ascii']

    for encoding in encodings:
        try:
            return string.encode(encoding)
        except (UnicodeEncodeError, __HOLE__):
            pass

    return string.encode(encodings[0], errors='ignore')
dataset/ETHPy150Open sdispater/orator/orator/utils/__init__.py/encode